blob: 6db704526bd4a164e89f9e2428bf7c9acf1fc007 (
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
|
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) (LETTER | DIGIT)* ;
WHITESPACE : ( '\t' | ' ' | '\u000C' )+
{
$channel = HIDDEN;
} ;
fragment
DIGIT : '0' .. '9' ;
fragment
LETTER: 'a' .. 'z' ;
|