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
: unOpExpression
: name functionParameters? // TODO: ambiguity here
: infixFunctionCall
: arrayAccess
: match
: FieldName
: if
// TODO: list comprehension
: jump
;
binaryOperation
: "+" : "-" : "*" : "/"
: "|" : "||" : "&" : "&&" : "^" // Maybe we can drop "^"
: "<" : ">" : ">=" : "<="
binaryOperation // Decreasing precedence
: "*" : "/" // No %
: "+" : "-"
// No << >> >>>
: "<" : ">" : ">=" : "<=" : "is" : "isnot" : "in" // TODO: Check the precedence for in carefully
: "==" : "==="
: "in"
: "is" : "isnot"
// No | & ^ ~
: "&&"
: "||"
;
unaryOperation
assignments
: "="
: "+=" : "-=" : "*=" : "/=" // TODO: |=, %= and <<= make more sense than |, % or << alone, and so for others
;
prefixUnaryOperation
: "-" : "+"
: "!"
: "++" : "--"
: "!" // No ~
;
postfixUnaryOperation
: "++" : "--"
;
jump