Binary operations, control structures

This commit is contained in:
Andrey Breslav
2010-11-16 12:27:06 +03:00
parent 58eacb1e00
commit 807062a1f8
2 changed files with 46 additions and 8 deletions
+23
View File
@@ -0,0 +1,23 @@
if
: "if" "(" expression ")" expression ("else" expression)?
;
match
: expression "match" "{" matchEntry+ "}"
;
matchEntry
: "case" pattern "=>" expression // TODO: Consider other options than "=>"
;
for
: "for" "(" valOrVar? (SimpleName | parameter) "in" expression ")" expression
;
while
: "while" "(" expression ")" expression
;
doWhile
: "do" expression "while" "(" expression ")"
;
+23 -8
View File
@@ -10,24 +10,39 @@ expression
: binOpExpression : binOpExpression
: unOpExpression : unOpExpression
: name functionParameters? // TODO: ambiguity here : name functionParameters? // TODO: ambiguity here
: infixFunctionCall
: arrayAccess
: match
: FieldName : FieldName
: if : if
// TODO: list comprehension // TODO: list comprehension
: jump : jump
; ;
binaryOperation binaryOperation // Decreasing precedence
: "+" : "-" : "*" : "/" : "*" : "/" // No %
: "|" : "||" : "&" : "&&" : "^" // Maybe we can drop "^" : "+" : "-"
: "<" : ">" : ">=" : "<=" // No << >> >>>
: "<" : ">" : ">=" : "<=" : "is" : "isnot" : "in" // TODO: Check the precedence for in carefully
: "==" : "===" : "==" : "==="
: "in" // No | & ^ ~
: "is" : "isnot" : "&&"
: "||"
; ;
unaryOperation assignments
: "="
: "+=" : "-=" : "*=" : "/=" // TODO: |=, %= and <<= make more sense than |, % or << alone, and so for others
;
prefixUnaryOperation
: "-" : "+" : "-" : "+"
: "!" : "++" : "--"
: "!" // No ~
;
postfixUnaryOperation
: "++" : "--"
; ;
jump jump