Expressions

This commit is contained in:
Andrey Breslav
2010-11-15 17:28:56 +03:00
parent 050f7c661b
commit 58eacb1e00
+35 -4
View File
@@ -1,18 +1,35 @@
expression
: "(" expression ")" // see tupleLiteral
: "new" constructorInvocation
: literalConstant
: functionLiteral
: tupleLiteral
: listLiteral
: mapLiteral
: "null"
: binOpExpression
: unOpExpression
: name functionParameters? // ambiguity here
: name functionParameters? // TODO: ambiguity here
: FieldName
: if
// list comprehension
// TODO: list comprehension
: jump
;
binaryOperation
: "+" : "-" : "*" : "/"
: "|" : "||" : "&" : "&&" : "^" // Maybe we can drop "^"
: "<" : ">" : ">=" : "<="
: "==" : "==="
: "in"
: "is" : "isnot"
;
unaryOperation
: "-" : "+"
: "!"
;
jump
: "throw" expression
: "return" expression
@@ -21,8 +38,9 @@ jump
// yield ?
;
tupleLiteral
: "(" expression{","} ")"
tupleLiteral // No, (a) is not a tuple
: "(" ")"
: "(" expression ("," expression)+ ")"
;
functionLiteral
@@ -34,3 +52,16 @@ functionLiteral
constructorInvocation
: userType "(" expression{","} ")"
;
listLiteral
: "[" expression{","} "]"
;
mapLiteral
: "[" mapEntryLiteral ("," mapEntryLiteral)* "]"
: "[" ":" "]"
;
mapEntryLiteral
: expression ":" expression
;