From 807062a1f8914c24d84884b9753064e4baf1c92a Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 16 Nov 2010 12:27:06 +0300 Subject: [PATCH] Binary operations, control structures --- grammar/src/control.grm | 23 +++++++++++++++++++++++ grammar/src/expressions.grm | 31 +++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 grammar/src/control.grm diff --git a/grammar/src/control.grm b/grammar/src/control.grm new file mode 100644 index 00000000000..b4123115631 --- /dev/null +++ b/grammar/src/control.grm @@ -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 ")" + ; diff --git a/grammar/src/expressions.grm b/grammar/src/expressions.grm index 6b9c12ed45e..06bb08788e5 100644 --- a/grammar/src/expressions.grm +++ b/grammar/src/expressions.grm @@ -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