[11 - Antlr Parser] Fix TestAntlrXParser1 halfway

This commit is contained in:
2020-06-03 14:39:54 +02:00
parent 2e62631386
commit 8a640d5174
34 changed files with 1337 additions and 1735 deletions

52
.idea/workspace.xml generated
View File

@@ -2,21 +2,39 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="a11aa5c4-505d-4bfb-9e81-72367c118bbe" name="Default Changelist" comment=""> <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$/.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.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/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$/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/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/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$/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> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -179,7 +197,7 @@
<workItem from="1591172719978" duration="202000" /> <workItem from="1591172719978" duration="202000" />
<workItem from="1591172941402" duration="220000" /> <workItem from="1591172941402" duration="220000" />
<workItem from="1591174233890" duration="9316000" /> <workItem from="1591174233890" duration="9316000" />
<workItem from="1591183629705" duration="2093000" /> <workItem from="1591183629705" duration="4105000" />
</task> </task>
<servers /> <servers />
</component> </component>
@@ -212,26 +230,26 @@
<screen x="0" y="0" width="1920" height="1040" /> <screen x="0" y="0" width="1920" height="1040" />
</state> </state>
<state x="700" y="233" key="FileChooserDialogImpl/0.0.1920.1040@0.0.1920.1040" timestamp="1591184758908" /> <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" /> <screen x="0" y="0" width="1920" height="1040" />
</state> </state>
<state width="1398" height="245" key="GridCell.Tab.0.bottom/0.0.1440.900@0.0.1440.900" timestamp="1591173185826" /> <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="916" height="398" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1591187736229" />
<state width="1877" height="270" key="GridCell.Tab.0.center" timestamp="1591185718383"> <state width="916" height="398" key="GridCell.Tab.0.center" timestamp="1591187736229">
<screen x="0" y="0" width="1920" height="1040" /> <screen x="0" y="0" width="1920" height="1040" />
</state> </state>
<state width="1398" height="245" key="GridCell.Tab.0.center/0.0.1440.900@0.0.1440.900" timestamp="1591173185825" /> <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="916" height="398" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1591187736229" />
<state width="1877" height="270" key="GridCell.Tab.0.left" timestamp="1591185718383"> <state width="916" height="398" key="GridCell.Tab.0.left" timestamp="1591187736228">
<screen x="0" y="0" width="1920" height="1040" /> <screen x="0" y="0" width="1920" height="1040" />
</state> </state>
<state width="1398" height="245" key="GridCell.Tab.0.left/0.0.1440.900@0.0.1440.900" timestamp="1591173185825" /> <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="916" height="398" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1591187736228" />
<state width="1877" height="270" key="GridCell.Tab.0.right" timestamp="1591185718383"> <state width="916" height="398" key="GridCell.Tab.0.right" timestamp="1591187736229">
<screen x="0" y="0" width="1920" height="1040" /> <screen x="0" y="0" width="1920" height="1040" />
</state> </state>
<state width="1398" height="245" key="GridCell.Tab.0.right/0.0.1440.900@0.0.1440.900" timestamp="1591173185826" /> <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"> <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" /> <screen x="0" y="0" width="1920" height="1040" />
</state> </state>

View File

@@ -25,7 +25,8 @@ tokens {
FLOATCONST; FLOATCONST;
WS; WS;
MODIFIER; MODIFIER;
DECLIST; DECLLIST;
UMINUS;
PROGRAM; PROGRAM;
DECL; DECL;
TYPE; TYPE;
@@ -54,17 +55,15 @@ ESCAPE: '\\' ('\"' |'\'' | '\\');
WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); }; WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); };
INVALID: .;
fragment DIGIT: ('0'..'9'); fragment DIGIT: ('0'..'9');
// -- Parser stuff // -- Parser stuff
program: 'program' ID ';' decllist statlist '.' EOF -> ^(PROGRAM ID decllist statlist); program: 'program'^ ID ';'! decllist statlist '.'! EOF!;
// Declaration // Declaration
decllist: decl decllist -> ^(DECLIST decl decllist); decllist: decl* -> ^(DECLLIST decl*);
decl: modifier ID ':' type ';' -> ^(DECL modifier ID type); decl: modifier? ID ':' type ';' -> ^(DECL modifier? ID type);
modifier: 'read' 'print'? | 'read' | 'print'; modifier: 'read' 'print'? | 'read' | 'print';
type: 'int' | 'float' | 'string'; type: 'int' | 'float' | 'string';
@@ -78,23 +77,16 @@ whilestat: 'while' '(' cond ')' stat -> ^('while' cond stat);
forstat: 'for' '(' assignstat ';' cond ';' assignstat ')' stat forstat: 'for' '(' assignstat ';' cond ';' assignstat ')' stat
-> ^('for' assignstat cond assignstat stat); -> ^('for' assignstat cond assignstat stat);
expr: expr2 '+' expr -> ^('+' expr2 expr) // Expressions
| expr2 '-' expr -> ^('-' expr2 expr)
| expr2 -> ^(expr2);
expr2: expr3 '*' expr2 -> ^('*' expr3 expr2)
| expr3 '/' expr2 -> ^('/' expr3 expr2)
| expr3 -> ^(expr3);
expr3: number | '-' number | STRINGCONST | '('! expr^ ')';
number: INTCONST | FLOATCONST; 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: '<' | '>' | '='; compOp: '<' | '>' | '=';
cond: expr cond2; cond: expr cond2;
cond2: compOp expr; cond2: compOp expr;
// -- Dummy rules
// Das sollte dafür sorgen, dass implizite Tokens auch ihre Tokens bekommen
// TODO: Remove this
minus: '-';
div: '/';
multiply: '*';
plus: '+';

View File

@@ -1,4 +1,3 @@
T__20=20
T__21=21 T__21=21
T__22=22 T__22=22
T__23=23 T__23=23
@@ -24,8 +23,9 @@ T__42=42
T__43=43 T__43=43
T__44=44 T__44=44
T__45=45 T__45=45
T__46=46
DECL=4 DECL=4
DECLIST=5 DECLLIST=5
DIGIT=6 DIGIT=6
ESCAPE=7 ESCAPE=7
EXPR=8 EXPR=8
@@ -39,30 +39,31 @@ STAT=15
STATLIST=16 STATLIST=16
STRINGCONST=17 STRINGCONST=17
TYPE=18 TYPE=18
WS=19 UMINUS=19
'('=20 WS=20
')'=21 '('=21
'*'=22 ')'=22
'+'=23 '*'=23
'-'=24 '+'=24
'.'=25 '-'=25
'/'=26 '.'=26
':'=27 '/'=27
':='=28 ':'=28
';'=29 ':='=29
'<'=30 ';'=30
'='=31 '<'=31
'>'=32 '='=32
'begin'=33 '>'=33
'else'=34 'begin'=34
'end'=35 'else'=35
'float'=36 'end'=36
'for'=37 'float'=37
'if'=38 'for'=38
'int'=39 'if'=39
'print'=40 'int'=40
'program'=41 'print'=41
'read'=42 'program'=42
'string'=43 'read'=43
'then'=44 'string'=44
'while'=45 'then'=45
'while'=46

View File

@@ -25,7 +25,8 @@ tokens {
FLOATCONST; FLOATCONST;
WS; WS;
MODIFIER; MODIFIER;
DECLIST; DECLLIST;
UMINUS;
PROGRAM; PROGRAM;
DECL; DECL;
TYPE; TYPE;
@@ -54,17 +55,15 @@ ESCAPE: '\\' ('\"' |'\'' | '\\');
WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); }; WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); };
INVALID: .;
fragment DIGIT: ('0'..'9'); fragment DIGIT: ('0'..'9');
// -- Parser stuff // -- Parser stuff
program: 'program' ID ';' decllist statlist '.' EOF -> ^(PROGRAM ID decllist statlist); program: 'program'^ ID ';'! decllist statlist '.'! EOF!;
// Declaration // Declaration
decllist: decl decllist -> ^(DECLIST decl decllist); decllist: decl* -> ^(DECLLIST decl*);
decl: modifier ID ':' type ';' -> ^(DECL modifier ID type); decl: modifier? ID ':' type ';' -> ^(DECL modifier? ID type);
modifier: 'read' 'print'? | 'read' | 'print'; modifier: 'read' 'print'? | 'read' | 'print';
type: 'int' | 'float' | 'string'; type: 'int' | 'float' | 'string';
@@ -78,23 +77,16 @@ whilestat: 'while' '(' cond ')' stat -> ^('while' cond stat);
forstat: 'for' '(' assignstat ';' cond ';' assignstat ')' stat forstat: 'for' '(' assignstat ';' cond ';' assignstat ')' stat
-> ^('for' assignstat cond assignstat stat); -> ^('for' assignstat cond assignstat stat);
expr: expr2 '+' expr -> ^('+' expr2 expr) // Expressions
| expr2 '-' expr -> ^('-' expr2 expr)
| expr2 -> ^(expr2);
expr2: expr3 '*' expr2 -> ^('*' expr3 expr2)
| expr3 '/' expr2 -> ^('/' expr3 expr2)
| expr3 -> ^(expr3);
expr3: number | '-' number | STRINGCONST | '('! expr^ ')';
number: INTCONST | FLOATCONST; 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: '<' | '>' | '='; compOp: '<' | '>' | '=';
cond: expr cond2; cond: expr cond2;
cond2: compOp expr; cond2: compOp expr;
// -- Dummy rules
// Das sollte dafür sorgen, dass implizite Tokens auch ihre Tokens bekommen
// TODO: Remove this
minus: '-';
div: '/';
multiply: '*';
plus: '+';

View File

@@ -1,4 +1,3 @@
T__20=20
T__21=21 T__21=21
T__22=22 T__22=22
T__23=23 T__23=23
@@ -24,8 +23,9 @@ T__42=42
T__43=43 T__43=43
T__44=44 T__44=44
T__45=45 T__45=45
T__46=46
DECL=4 DECL=4
DECLIST=5 DECLLIST=5
DIGIT=6 DIGIT=6
ESCAPE=7 ESCAPE=7
EXPR=8 EXPR=8
@@ -39,30 +39,31 @@ STAT=15
STATLIST=16 STATLIST=16
STRINGCONST=17 STRINGCONST=17
TYPE=18 TYPE=18
WS=19 UMINUS=19
'('=20 WS=20
')'=21 '('=21
'*'=22 ')'=22
'+'=23 '*'=23
'-'=24 '+'=24
'.'=25 '-'=25
'/'=26 '.'=26
':'=27 '/'=27
':='=28 ':'=28
';'=29 ':='=29
'<'=30 ';'=30
'='=31 '<'=31
'>'=32 '='=32
'begin'=33 '>'=33
'else'=34 'begin'=34
'end'=35 'else'=35
'float'=36 'end'=36
'for'=37 'float'=37
'if'=38 'for'=38
'int'=39 'if'=39
'print'=40 'int'=40
'program'=41 'print'=41
'read'=42 'program'=42
'string'=43 'read'=43
'then'=44 'string'=44
'while'=45 'then'=45
'while'=46