[11 - Antlr Parser] Fix TestAntlrXParser1 halfway
This commit is contained in:
52
.idea/workspace.xml
generated
52
.idea/workspace.xml
generated
@@ -2,21 +2,39 @@
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="a11aa5c4-505d-4bfb-9e81-72367c118bbe" name="Default Changelist" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/runConfigurations/Run_Antlr_builder.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/runConfigurations/Run_Antlr_builder.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/X.tokens" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/XLexer.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/XParser.java" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g" beforeDir="false" afterPath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.tokens" beforeDir="false" afterPath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.tokens" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/XLexer.java" beforeDir="false" afterPath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/XLexer.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/XParser.java" beforeDir="false" afterPath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/XParser.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/X.g" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/X.g" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XLexer$DFA4.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/X.tokens" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/X.tokens" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XLexer$DFA12.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XLexer$DFA12.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XLexer$DFA9.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XLexer$DFA9.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XLexer.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XLexer.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$program_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$program_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$assignstat_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$assignstat_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$compOp_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$compOp_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$cond2_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$cond2_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$condElseStat_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$condElseStat_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$cond_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$cond_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$condstat_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$condstat_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$decl_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$decl_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$decllist_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$decllist_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$div_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$div_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$expr2_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$expr2_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$expr3_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$expr3_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$expr_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$expr_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$forstat_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$forstat_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$minus_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$minus_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$modifier_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$modifier_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$multiply_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$multiply_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$number_return.class" beforeDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$plus_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$plus_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$stat_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$stat_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$statlist_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$statlist_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$type_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$type_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$whilestat_return.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser$whilestat_return.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/CC-Praxis-Antlr Parser fuer X-Leer/de/dhbw/compiler/antlrxparser/XParser.class" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/ÜB-Praxis-JFlex Scanner für AS-Leer/ÜB-Praxis-JFlex Scanner für AS-Leer.iml" beforeDir="false" afterPath="$PROJECT_DIR$/ÜB-Praxis-JFlex Scanner für AS-Leer/ÜB-Praxis-JFlex Scanner für AS-Leer.iml" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -179,7 +197,7 @@
|
||||
<workItem from="1591172719978" duration="202000" />
|
||||
<workItem from="1591172941402" duration="220000" />
|
||||
<workItem from="1591174233890" duration="9316000" />
|
||||
<workItem from="1591183629705" duration="2093000" />
|
||||
<workItem from="1591183629705" duration="4105000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@@ -212,26 +230,26 @@
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state x="700" y="233" key="FileChooserDialogImpl/0.0.1920.1040@0.0.1920.1040" timestamp="1591184758908" />
|
||||
<state width="1877" height="270" key="GridCell.Tab.0.bottom" timestamp="1591185718383">
|
||||
<state width="916" height="398" key="GridCell.Tab.0.bottom" timestamp="1591187736229">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1398" height="245" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1591173185826" />
|
||||
<state width="1877" height="270" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1591185718383" />
|
||||
<state width="1877" height="270" key="GridCell.Tab.0.center" timestamp="1591185718383">
|
||||
<state width="916" height="398" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1591187736229" />
|
||||
<state width="916" height="398" key="GridCell.Tab.0.center" timestamp="1591187736229">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1398" height="245" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1591173185825" />
|
||||
<state width="1877" height="270" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1591185718383" />
|
||||
<state width="1877" height="270" key="GridCell.Tab.0.left" timestamp="1591185718383">
|
||||
<state width="916" height="398" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1591187736229" />
|
||||
<state width="916" height="398" key="GridCell.Tab.0.left" timestamp="1591187736228">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1398" height="245" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1591173185825" />
|
||||
<state width="1877" height="270" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1591185718383" />
|
||||
<state width="1877" height="270" key="GridCell.Tab.0.right" timestamp="1591185718383">
|
||||
<state width="916" height="398" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1591187736228" />
|
||||
<state width="916" height="398" key="GridCell.Tab.0.right" timestamp="1591187736229">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state width="1398" height="245" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1591173185826" />
|
||||
<state width="1877" height="270" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1591185718383" />
|
||||
<state width="916" height="398" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1591187736229" />
|
||||
<state x="447" y="180" width="915" height="587" key="NewModule_or_Project.wizard" timestamp="1591184776491">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user