blob: 3a6598a7a4a528b5d82d8342b46416c48f7ea2c2 (
about) (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
grammar EquationSystem;
options {
language=C;
output=AST;
backtrack=true;
}
tokens {
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 ;
maxExpr : MAXIMUM^ '('! minExpr ( ','! minExpr )* ')'! | minExpr ;
minExpr : MINIMUM^ '('! maxExpr ( ','! maxExpr )* ')'! | expr ;
expr : '(' expr GREATER_EQUAL expr QUESTION_MARK expr ')' -> ^(GUARD expr expr expr)
| term ( (PLUS | MULT | SUB | COMMA)^ expr )* ;
term : NUMBER
| VARIABLE
| '('! expr ')'! ;
NUMBER : (DIGIT)+ ;
VARIABLE: (LETTER) (LETTER | DIGIT)* ;
WHITESPACE : ( '\t' | ' ' | '\u000C' )+
{
$channel = HIDDEN;
} ;
fragment
DIGIT : '0' .. '9' ;
fragment
LETTER: 'a' .. 'z' ;
|