summaryrefslogtreecommitdiff
path: root/impl/EquationSystem.g
diff options
context:
space:
mode:
Diffstat (limited to 'impl/EquationSystem.g')
-rw-r--r--impl/EquationSystem.g19
1 files changed, 13 insertions, 6 deletions
diff --git a/impl/EquationSystem.g b/impl/EquationSystem.g
index 6db7045..3a6598a 100644
--- a/impl/EquationSystem.g
+++ b/impl/EquationSystem.g
@@ -3,27 +3,34 @@ grammar EquationSystem;
options {
language=C;
output=AST;
+ backtrack=true;
}
tokens {
- SYSTEM = 'system' ;
PLUS = '+' ;
SUB = '-' ;
MULT = '*' ;
+ COMMA = ';' ;
+ GUARD = 'guard' ;
+ GREATER_EQUAL = '>=' ;
+ QUESTION_MARK = '?' ;
MAXIMUM = 'max' ;
MINIMUM = 'min' ;
NEWLINE = '\n' ;
}
-equation_system : equation ( NEWLINE! + equation )* (NEWLINE!) *;
-equation : VARIABLE '='! maxExpr;
+equation_system : equation ( NEWLINE! + equation )* (NEWLINE!)* ;
+equation : VARIABLE '='! maxExpr ;
-maxExpr : MAXIMUM^ '('! minExpr ( ','! minExpr )* ')'! | minExpr;
+maxExpr : MAXIMUM^ '('! minExpr ( ','! minExpr )* ')'! | minExpr ;
minExpr : MINIMUM^ '('! maxExpr ( ','! maxExpr )* ')'! | expr ;
-expr : term ( (PLUS | MULT | SUB)^ term )* ;
+expr : '(' expr GREATER_EQUAL expr QUESTION_MARK expr ')' -> ^(GUARD expr expr expr)
+ | term ( (PLUS | MULT | SUB | COMMA)^ expr )* ;
-term : NUMBER | VARIABLE ;
+term : NUMBER
+ | VARIABLE
+ | '('! expr ')'! ;
NUMBER : (DIGIT)+ ;