[11 - Antlr Parser] Fix TestAntlrXParser1 halfway
This commit is contained in:
@@ -25,7 +25,8 @@ tokens {
|
||||
FLOATCONST;
|
||||
WS;
|
||||
MODIFIER;
|
||||
DECLIST;
|
||||
DECLLIST;
|
||||
UMINUS;
|
||||
PROGRAM;
|
||||
DECL;
|
||||
TYPE;
|
||||
@@ -54,17 +55,15 @@ ESCAPE: '\\' ('\"' |'\'' | '\\');
|
||||
|
||||
WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); };
|
||||
|
||||
INVALID: .;
|
||||
|
||||
fragment DIGIT: ('0'..'9');
|
||||
|
||||
|
||||
// -- Parser stuff
|
||||
program: 'program' ID ';' decllist statlist '.' EOF -> ^(PROGRAM ID decllist statlist);
|
||||
program: 'program'^ ID ';'! decllist statlist '.'! EOF!;
|
||||
|
||||
// Declaration
|
||||
decllist: decl decllist -> ^(DECLIST decl decllist);
|
||||
decl: modifier ID ':' type ';' -> ^(DECL modifier ID type);
|
||||
decllist: decl* -> ^(DECLLIST decl*);
|
||||
decl: modifier? ID ':' type ';' -> ^(DECL modifier? ID type);
|
||||
modifier: 'read' 'print'? | 'read' | 'print';
|
||||
type: 'int' | 'float' | 'string';
|
||||
|
||||
@@ -78,23 +77,16 @@ whilestat: 'while' '(' cond ')' stat -> ^('while' cond stat);
|
||||
forstat: 'for' '(' assignstat ';' cond ';' assignstat ')' stat
|
||||
-> ^('for' assignstat cond assignstat stat);
|
||||
|
||||
expr: expr2 '+' expr -> ^('+' expr2 expr)
|
||||
| expr2 '-' expr -> ^('-' expr2 expr)
|
||||
| expr2 -> ^(expr2);
|
||||
expr2: expr3 '*' expr2 -> ^('*' expr3 expr2)
|
||||
| expr3 '/' expr2 -> ^('/' expr3 expr2)
|
||||
| expr3 -> ^(expr3);
|
||||
expr3: number | '-' number | STRINGCONST | '('! expr^ ')';
|
||||
// Expressions
|
||||
number: INTCONST | FLOATCONST;
|
||||
expr: expr2 (op='+' | op='-') expr -> ^($op expr2 expr)
|
||||
| expr2;
|
||||
expr2: expr3 (op='*' | op='/') expr -> ^($op expr3 expr)
|
||||
| expr3;
|
||||
expr3: op='-' num=number -> ^(UMINUS[op,"UMINUS"] $num)
|
||||
| number | STRINGCONST | '('! expr^ ')'!;
|
||||
|
||||
// Conditions and comparison
|
||||
compOp: '<' | '>' | '=';
|
||||
cond: expr cond2;
|
||||
cond2: compOp expr;
|
||||
|
||||
// -- Dummy rules
|
||||
// Das sollte dafür sorgen, dass implizite Tokens auch ihre Tokens bekommen
|
||||
// TODO: Remove this
|
||||
minus: '-';
|
||||
div: '/';
|
||||
multiply: '*';
|
||||
plus: '+';
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
T__20=20
|
||||
T__21=21
|
||||
T__22=22
|
||||
T__23=23
|
||||
@@ -24,8 +23,9 @@ T__42=42
|
||||
T__43=43
|
||||
T__44=44
|
||||
T__45=45
|
||||
T__46=46
|
||||
DECL=4
|
||||
DECLIST=5
|
||||
DECLLIST=5
|
||||
DIGIT=6
|
||||
ESCAPE=7
|
||||
EXPR=8
|
||||
@@ -39,30 +39,31 @@ STAT=15
|
||||
STATLIST=16
|
||||
STRINGCONST=17
|
||||
TYPE=18
|
||||
WS=19
|
||||
'('=20
|
||||
')'=21
|
||||
'*'=22
|
||||
'+'=23
|
||||
'-'=24
|
||||
'.'=25
|
||||
'/'=26
|
||||
':'=27
|
||||
':='=28
|
||||
';'=29
|
||||
'<'=30
|
||||
'='=31
|
||||
'>'=32
|
||||
'begin'=33
|
||||
'else'=34
|
||||
'end'=35
|
||||
'float'=36
|
||||
'for'=37
|
||||
'if'=38
|
||||
'int'=39
|
||||
'print'=40
|
||||
'program'=41
|
||||
'read'=42
|
||||
'string'=43
|
||||
'then'=44
|
||||
'while'=45
|
||||
UMINUS=19
|
||||
WS=20
|
||||
'('=21
|
||||
')'=22
|
||||
'*'=23
|
||||
'+'=24
|
||||
'-'=25
|
||||
'.'=26
|
||||
'/'=27
|
||||
':'=28
|
||||
':='=29
|
||||
';'=30
|
||||
'<'=31
|
||||
'='=32
|
||||
'>'=33
|
||||
'begin'=34
|
||||
'else'=35
|
||||
'end'=36
|
||||
'float'=37
|
||||
'for'=38
|
||||
'if'=39
|
||||
'int'=40
|
||||
'print'=41
|
||||
'program'=42
|
||||
'read'=43
|
||||
'string'=44
|
||||
'then'=45
|
||||
'while'=46
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user