diff options
Diffstat (limited to 'impl/EquationSystem.g')
-rw-r--r-- | impl/EquationSystem.g | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/impl/EquationSystem.g b/impl/EquationSystem.g new file mode 100644 index 0000000..d7e55a7 --- /dev/null +++ b/impl/EquationSystem.g @@ -0,0 +1,39 @@ +grammar EquationSystem; + +options { + language=C; + output=AST; +} + +tokens { + SYSTEM = 'system' ; + PLUS = '+' ; + SUB = '-' ; + MULT = '*' ; + MAXIMUM = 'max' ; + MINIMUM = 'min' ; + NEWLINE = '\n' ; +} + +equation_system : equation ( NEWLINE! + equation )* (NEWLINE!) *; +equation : VARIABLE '='! maxExpr; + +maxExpr : MAXIMUM^ '('! minExpr ( ','! minExpr )* ')'! | minExpr; +minExpr : MINIMUM^ '('! maxExpr ( ','! maxExpr )* ')'! | expr ; + +expr : term ( (PLUS | MULT | SUB)^ term )* ; + +term : NUMBER | VARIABLE ; + + +NUMBER : (DIGIT)+ ; +VARIABLE: (LETTER)+ ; +WHITESPACE : ( '\t' | ' ' | '\u000C' )+ + { + $channel = HIDDEN; + } ; + +fragment +DIGIT : '0' .. '9' ; +fragment +LETTER: 'a' .. 'z' ; |