blob: 6b721bb8b93f3daefc2b2bb16cd20c7b810fb319 (
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
47
48
|
grammar EquationSystem;
options {
language=C;
output=AST;
backtrack=true;
}
tokens {
PLUS = '+' ;
SUB = '-' ;
MULT = '*' ;
COMMA = ';' ;
RANGE = 'range' ;
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 | COMMA)^ expr )* ;
term : '[' NUMBER ',' NUMBER ']' -> ^( RANGE NUMBER NUMBER )
| VARIABLE
| '('! expr ')'!
| SUB^ term ;
NUMBER : (SUB) (DIGIT)+ | (DIGIT)+ ;
VARIABLE: (LETTER) (LETTER | DIGIT)* ;
WHITESPACE : ( '\t' | ' ' | '\u000C' )+
{
$channel = HIDDEN;
} ;
fragment
DIGIT : '0' .. '9' ;
fragment
LETTER: 'a' .. 'z' ;
|