summaryrefslogtreecommitdiff
path: root/impl/EquationSystem.g
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-05-25 13:24:37 +1000
committerCarlo Zancanaro <carlo@pc-4w14-0.cs.usyd.edu.au>2012-05-25 13:24:37 +1000
commit61f90f14af8796bbed074538882e76f1e1bf3333 (patch)
tree5d1dc744b47817a39b905418b1fc76bb828cea4a /impl/EquationSystem.g
parentee8547cf3c89c51ff10603814e6f745466bc4c79 (diff)
Try to make some more modular Fixpoint algorithms.
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)+ ;