[11 - Antlr Parser] Fix Scanner tests
This commit is contained in:
1
.idea/modules.xml
generated
1
.idea/modules.xml
generated
@@ -3,6 +3,7 @@
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/CC-Praxis-Antlr Parser fuer X-Leer.iml" filepath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/CC-Praxis-Antlr Parser fuer X-Leer.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/ÜB-Praxis-JFlex Scanner für AS-Leer/ÜB-Praxis-JFlex Scanner für AS-Leer.iml" filepath="$PROJECT_DIR$/ÜB-Praxis-JFlex Scanner für AS-Leer/ÜB-Praxis-JFlex Scanner für AS-Leer.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
4
.idea/runConfigurations/Run_Antlr_builder.xml
generated
4
.idea/runConfigurations/Run_Antlr_builder.xml
generated
@@ -2,8 +2,8 @@
|
||||
<configuration default="false" name="Run Antlr Builder" type="Application" factoryName="Application">
|
||||
<option name="MAIN_CLASS_NAME" value="org.antlr.Tool" />
|
||||
<module name="CC-Praxis-Antlr Parser fuer X-Leer" />
|
||||
<option name="PROGRAM_PARAMETERS" value=""$ModuleSourcePath$/de/dhbw/compiler/antlrxparser/X.g"" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer" />
|
||||
<option name="PROGRAM_PARAMETERS" value="-o "$ModuleSourcePath$/de/dhbw/compiler/antlrxparser/" "$ModuleSourcePath$/de/dhbw/compiler/antlrxparser/X.g"" />
|
||||
<option name="WORKING_DIRECTORY" value="$ContentRoot$" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
</component>
|
||||
71
.idea/workspace.xml
generated
71
.idea/workspace.xml
generated
@@ -2,9 +2,21 @@
|
||||
<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" afterPath="$PROJECT_DIR$/CC-Praxis-Antlr Parser fuer X-Leer/X.tokens" 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/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/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.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" />
|
||||
@@ -25,11 +37,12 @@
|
||||
<property name="SHARE_PROJECT_CONFIGURATION_FILES" value="true" />
|
||||
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||
<property name="aspect.path.notification.shown" value="true" />
|
||||
<property name="project.structure.last.edited" value="Project" />
|
||||
<property name="last_opened_file_path" value="$PROJECT_DIR$/ÜB-Praxis-JFlex Scanner für AS-Leer" />
|
||||
<property name="project.structure.last.edited" value="Modules" />
|
||||
<property name="project.structure.proportion" value="0.15429688" />
|
||||
<property name="project.structure.side.proportion" value="0.2" />
|
||||
</component>
|
||||
<component name="RunManager" selected="JUnit.TestAntlrXScanner1.tokenASSIGN">
|
||||
<component name="RunManager" selected="JUnit.TestAntlrXParser1">
|
||||
<configuration name="TestAntlrXParser1" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<module name="CC-Praxis-Antlr Parser fuer X-Leer" />
|
||||
<useClassPathOnly />
|
||||
@@ -65,7 +78,7 @@
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="TestAntlrXScanner1" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<configuration name="TestAntlrXScanner1" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
|
||||
<module name="CC-Praxis-Antlr Parser fuer X-Leer" />
|
||||
<useClassPathOnly />
|
||||
<extension name="coverage">
|
||||
@@ -146,10 +159,9 @@
|
||||
</list>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenStringConst" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1.program00BeginEnd" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenStringConst" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1.program00BeginEnd" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenREAD" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
@@ -166,7 +178,8 @@
|
||||
<updated>1591172713288</updated>
|
||||
<workItem from="1591172719978" duration="202000" />
|
||||
<workItem from="1591172941402" duration="220000" />
|
||||
<workItem from="1591174233890" duration="8126000" />
|
||||
<workItem from="1591174233890" duration="9316000" />
|
||||
<workItem from="1591183629705" duration="2093000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@@ -182,42 +195,52 @@
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state x="570" y="121" key="#TestAntlrXScanner1.tokenASSIGN/0.0.1920.1040@0.0.1920.1040" timestamp="1591175187591" />
|
||||
<state x="245" y="129" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1591178569825">
|
||||
<state x="-37" y="200" width="1471" height="691" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1591184444701">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state x="184" y="112" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1440.900@0.0.1440.900" timestamp="1591172899381" />
|
||||
<state x="245" y="129" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1591178569825" />
|
||||
<state x="92" y="92" width="1736" height="856" key="#com.intellij.execution.junit2.states.ComparisonFailureState$DiffDialog" timestamp="1591178570191">
|
||||
<state x="-37" y="200" width="1471" height="691" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1591184444701" />
|
||||
<state x="92" y="92" width="1736" height="856" key="#com.intellij.execution.junit2.states.ComparisonFailureState$DiffDialog" timestamp="1591185724270">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state x="92" y="92" width="1736" height="856" key="#com.intellij.execution.junit2.states.ComparisonFailureState$DiffDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1591178570191" />
|
||||
<state width="914" height="268" key="GridCell.Tab.0.bottom" timestamp="1591182426442">
|
||||
<state x="92" y="92" width="1736" height="856" key="#com.intellij.execution.junit2.states.ComparisonFailureState$DiffDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1591185724270" />
|
||||
<state x="700" y="183" key="#com.intellij.ide.macro.MacrosDialog" timestamp="1591184444196">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state x="700" y="183" key="#com.intellij.ide.macro.MacrosDialog/0.0.1920.1040@0.0.1920.1040" timestamp="1591184444196" />
|
||||
<state x="700" y="233" key="FileChooserDialogImpl" timestamp="1591184758908">
|
||||
<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">
|
||||
<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="914" height="268" key="GridCell.Tab.0.bottom/0.0.1920.1040@0.0.1920.1040" timestamp="1591182426442" />
|
||||
<state width="914" height="268" key="GridCell.Tab.0.center" timestamp="1591182426442">
|
||||
<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">
|
||||
<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="914" height="268" key="GridCell.Tab.0.center/0.0.1920.1040@0.0.1920.1040" timestamp="1591182426442" />
|
||||
<state width="914" height="268" key="GridCell.Tab.0.left" timestamp="1591182426442">
|
||||
<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">
|
||||
<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="914" height="268" key="GridCell.Tab.0.left/0.0.1920.1040@0.0.1920.1040" timestamp="1591182426442" />
|
||||
<state width="914" height="268" key="GridCell.Tab.0.right" timestamp="1591182426442">
|
||||
<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">
|
||||
<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="914" height="268" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1591182426442" />
|
||||
<state x="335" y="156" width="915" height="587" key="NewModule_or_Project.wizard" timestamp="1591172753823">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
<state width="1877" height="270" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1591185718383" />
|
||||
<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>
|
||||
<state x="335" y="156" width="915" height="587" key="NewModule_or_Project.wizard/0.0.1440.900@0.0.1440.900" timestamp="1591172753823" />
|
||||
<state x="208" y="31" key="SettingsEditor" timestamp="1591172804318">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
<state x="447" y="180" key="NewModule_or_Project.wizard/0.0.1920.1040@0.0.1920.1040" timestamp="1591184776491" />
|
||||
<state x="277" y="36" key="SettingsEditor" timestamp="1591184318089">
|
||||
<screen x="0" y="0" width="1920" height="1040" />
|
||||
</state>
|
||||
<state x="208" y="31" key="SettingsEditor/0.0.1440.900@0.0.1440.900" timestamp="1591172804318" />
|
||||
<state x="277" y="36" key="SettingsEditor/0.0.1920.1040@0.0.1920.1040" timestamp="1591184318089" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,63 +0,0 @@
|
||||
T__23=23
|
||||
T__24=24
|
||||
T__25=25
|
||||
T__26=26
|
||||
T__27=27
|
||||
T__28=28
|
||||
T__29=29
|
||||
T__30=30
|
||||
T__31=31
|
||||
T__32=32
|
||||
T__33=33
|
||||
T__34=34
|
||||
T__35=35
|
||||
T__36=36
|
||||
T__37=37
|
||||
T__38=38
|
||||
T__39=39
|
||||
T__40=40
|
||||
T__41=41
|
||||
T__42=42
|
||||
BINOP=4
|
||||
DECL=5
|
||||
DECLIST=6
|
||||
ESCAPE=7
|
||||
EXPR=8
|
||||
FLOATCONST=9
|
||||
ID=10
|
||||
INTCONST=11
|
||||
MODIFIER=12
|
||||
PROGRAM=13
|
||||
STAT=14
|
||||
STATLIST=15
|
||||
STRINGCONST=16
|
||||
TYPE=17
|
||||
UDIVIDE=18
|
||||
UMINUS=19
|
||||
UMULTIPLY=20
|
||||
UPLUS=21
|
||||
WS=22
|
||||
'('=23
|
||||
')'=24
|
||||
'*'=20
|
||||
'+'=21
|
||||
'-'=19
|
||||
'.'=25
|
||||
'/'=18
|
||||
':'=26
|
||||
':='=27
|
||||
';'=28
|
||||
'begin'=29
|
||||
'else'=30
|
||||
'end'=31
|
||||
'float'=32
|
||||
'for'=33
|
||||
'if'=34
|
||||
'int'=35
|
||||
'print'=36
|
||||
'program'=37
|
||||
'read print'=38
|
||||
'read'=39
|
||||
'string'=40
|
||||
'then'=41
|
||||
'while'=42
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -25,10 +25,6 @@ tokens {
|
||||
FLOATCONST;
|
||||
WS;
|
||||
MODIFIER;
|
||||
UMINUS='-';
|
||||
UPLUS='+';
|
||||
UMULTIPLY='*';
|
||||
UDIVIDE='/';
|
||||
DECLIST;
|
||||
PROGRAM;
|
||||
DECL;
|
||||
@@ -36,6 +32,7 @@ tokens {
|
||||
STAT;
|
||||
STATLIST;
|
||||
EXPR;
|
||||
INVALID;
|
||||
}
|
||||
|
||||
@parser::header {package de.dhbw.compiler.antlrxparser;}
|
||||
@@ -48,16 +45,19 @@ ID: ('a'..'z' | 'A'..'Z')
|
||||
greedy = true; // Lese alle möglichen Zeichen ein -> Zahlen in ID -> bleibt weiterhin ID
|
||||
}: 'a'..'z' | 'A'..'Z' | '0'..'9')*;
|
||||
|
||||
INTCONST: ('0'..'9')+;
|
||||
FLOATCONST: INTCONST '.' INTCONST;
|
||||
INTCONST: '0' | ('1'..'9') ('0'..'9')*;
|
||||
FLOATCONST: INTCONST ('.' DIGIT*)? ('e'|'E')('+' |'-' )? INTCONST
|
||||
| INTCONST ('.' DIGIT*)?;
|
||||
|
||||
STRINGCONST: '"' (ESCAPE | ~('\\' | '"'))* '"';
|
||||
ESCAPE: '\\' ('\"' |'\'' | '\\');
|
||||
|
||||
BINOP: '+' | '-' | '*' | '/' | '<' | '>' | '=';
|
||||
|
||||
WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); };
|
||||
|
||||
INVALID: .;
|
||||
|
||||
fragment DIGIT: ('0'..'9');
|
||||
|
||||
|
||||
// -- Parser stuff
|
||||
program: 'program' ID ';' decllist statlist '.' EOF -> ^(PROGRAM ID decllist statlist);
|
||||
@@ -65,14 +65,12 @@ program: 'program' ID ';' decllist statlist '.' EOF -> ^(PROGRAM ID decllist
|
||||
// Declaration
|
||||
decllist: decl decllist -> ^(DECLIST decl decllist);
|
||||
decl: modifier ID ':' type ';' -> ^(DECL modifier ID type);
|
||||
modifier: mod='read' | mod='print' | mod='read print' -> ^(MODIFIER[mod]);
|
||||
type: t='int' | t='float' | t='string' -> ^(TYPE[t]);
|
||||
modifier: 'read' 'print'? | 'read' | 'print';
|
||||
type: 'int' | 'float' | 'string';
|
||||
|
||||
// Block
|
||||
statlist: 'begin' (stat ';')* 'end' -> ^(STATLIST stat*);
|
||||
stat: t=assignstat | t=condstat | t=whilestat | t=forstat -> ^(STAT[t])
|
||||
| statlist
|
||||
-> ^(STATLIST statlist);
|
||||
stat: assignstat | condstat | whilestat | forstat | statlist;
|
||||
assignstat: ID ':=' expr -> ^(':=' ID expr);
|
||||
condstat: 'if' cond 'then' stat condElseStat? -> ^('if' cond stat condElseStat? );
|
||||
condElseStat: 'else' stat -> ^('else' stat);
|
||||
@@ -80,18 +78,23 @@ whilestat: 'while' '(' cond ')' stat -> ^('while' cond stat);
|
||||
forstat: 'for' '(' assignstat ';' cond ';' assignstat ')' stat
|
||||
-> ^('for' assignstat cond assignstat stat);
|
||||
|
||||
expr: expr2 UPLUS expr -> ^(UPLUS expr2 expr)
|
||||
| expr2 UMINUS expr -> ^(UMINUS expr2 expr)
|
||||
expr: expr2 '+' expr -> ^('+' expr2 expr)
|
||||
| expr2 '-' expr -> ^('-' expr2 expr)
|
||||
| expr2 -> ^(expr2);
|
||||
expr2: expr3 UMULTIPLY expr2 -> ^(UMULTIPLY expr3 expr2)
|
||||
| expr3 UDIVIDE expr2 -> ^(UDIVIDE expr3 expr2)
|
||||
expr2: expr3 '*' expr2 -> ^('*' expr3 expr2)
|
||||
| expr3 '/' expr2 -> ^('/' expr3 expr2)
|
||||
| expr3 -> ^(expr3);
|
||||
expr3: number -> ^(number)
|
||||
| UMINUS number -> ^(UMINUS number)
|
||||
| t=STRINGCONST | t=ID -> ^($t)
|
||||
| '(' expr ')' -> ^(expr);
|
||||
expr3: number | '-' number | STRINGCONST | '('! expr^ ')';
|
||||
number: INTCONST | FLOATCONST;
|
||||
|
||||
cond: expr cond2 -> ^(expr cond2);
|
||||
cond2: BINOP expr -> ^(BINOP expr);
|
||||
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: '+';
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
T__20=20
|
||||
T__21=21
|
||||
T__22=22
|
||||
T__23=23
|
||||
T__24=24
|
||||
T__25=25
|
||||
T__26=26
|
||||
T__27=27
|
||||
T__28=28
|
||||
T__29=29
|
||||
T__30=30
|
||||
T__31=31
|
||||
T__32=32
|
||||
T__33=33
|
||||
T__34=34
|
||||
T__35=35
|
||||
T__36=36
|
||||
T__37=37
|
||||
T__38=38
|
||||
T__39=39
|
||||
T__40=40
|
||||
T__41=41
|
||||
T__42=42
|
||||
T__43=43
|
||||
T__44=44
|
||||
T__45=45
|
||||
DECL=4
|
||||
DECLIST=5
|
||||
DIGIT=6
|
||||
ESCAPE=7
|
||||
EXPR=8
|
||||
FLOATCONST=9
|
||||
ID=10
|
||||
INTCONST=11
|
||||
INVALID=12
|
||||
MODIFIER=13
|
||||
PROGRAM=14
|
||||
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
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -25,10 +25,6 @@ tokens {
|
||||
FLOATCONST;
|
||||
WS;
|
||||
MODIFIER;
|
||||
UMINUS='-';
|
||||
UPLUS='+';
|
||||
UMULTIPLY='*';
|
||||
UDIVIDE='/';
|
||||
DECLIST;
|
||||
PROGRAM;
|
||||
DECL;
|
||||
@@ -36,6 +32,7 @@ tokens {
|
||||
STAT;
|
||||
STATLIST;
|
||||
EXPR;
|
||||
INVALID;
|
||||
}
|
||||
|
||||
@parser::header {package de.dhbw.compiler.antlrxparser;}
|
||||
@@ -48,16 +45,19 @@ ID: ('a'..'z' | 'A'..'Z')
|
||||
greedy = true; // Lese alle möglichen Zeichen ein -> Zahlen in ID -> bleibt weiterhin ID
|
||||
}: 'a'..'z' | 'A'..'Z' | '0'..'9')*;
|
||||
|
||||
INTCONST: ('0'..'9')+;
|
||||
FLOATCONST: INTCONST '.' INTCONST;
|
||||
INTCONST: '0' | ('1'..'9') ('0'..'9')*;
|
||||
FLOATCONST: INTCONST ('.' DIGIT*)? ('e'|'E')('+' |'-' )? INTCONST
|
||||
| INTCONST ('.' DIGIT*)?;
|
||||
|
||||
STRINGCONST: '"' (ESCAPE | ~('\\' | '"'))* '"';
|
||||
ESCAPE: '\\' ('\"' |'\'' | '\\');
|
||||
|
||||
BINOP: '+' | '-' | '*' | '/' | '<' | '>' | '=';
|
||||
|
||||
WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); };
|
||||
|
||||
INVALID: .;
|
||||
|
||||
fragment DIGIT: ('0'..'9');
|
||||
|
||||
|
||||
// -- Parser stuff
|
||||
program: 'program' ID ';' decllist statlist '.' EOF -> ^(PROGRAM ID decllist statlist);
|
||||
@@ -65,14 +65,12 @@ program: 'program' ID ';' decllist statlist '.' EOF -> ^(PROGRAM ID decllist
|
||||
// Declaration
|
||||
decllist: decl decllist -> ^(DECLIST decl decllist);
|
||||
decl: modifier ID ':' type ';' -> ^(DECL modifier ID type);
|
||||
modifier: mod='read' | mod='print' | mod='read print' -> ^(MODIFIER[mod]);
|
||||
type: t='int' | t='float' | t='string' -> ^(TYPE[t]);
|
||||
modifier: 'read' 'print'? | 'read' | 'print';
|
||||
type: 'int' | 'float' | 'string';
|
||||
|
||||
// Block
|
||||
statlist: 'begin' (stat ';')* 'end' -> ^(STATLIST stat*);
|
||||
stat: t=assignstat | t=condstat | t=whilestat | t=forstat -> ^(STAT[t])
|
||||
| statlist
|
||||
-> ^(STATLIST statlist);
|
||||
stat: assignstat | condstat | whilestat | forstat | statlist;
|
||||
assignstat: ID ':=' expr -> ^(':=' ID expr);
|
||||
condstat: 'if' cond 'then' stat condElseStat? -> ^('if' cond stat condElseStat? );
|
||||
condElseStat: 'else' stat -> ^('else' stat);
|
||||
@@ -80,18 +78,23 @@ whilestat: 'while' '(' cond ')' stat -> ^('while' cond stat);
|
||||
forstat: 'for' '(' assignstat ';' cond ';' assignstat ')' stat
|
||||
-> ^('for' assignstat cond assignstat stat);
|
||||
|
||||
expr: expr2 UPLUS expr -> ^(UPLUS expr2 expr)
|
||||
| expr2 UMINUS expr -> ^(UMINUS expr2 expr)
|
||||
expr: expr2 '+' expr -> ^('+' expr2 expr)
|
||||
| expr2 '-' expr -> ^('-' expr2 expr)
|
||||
| expr2 -> ^(expr2);
|
||||
expr2: expr3 UMULTIPLY expr2 -> ^(UMULTIPLY expr3 expr2)
|
||||
| expr3 UDIVIDE expr2 -> ^(UDIVIDE expr3 expr2)
|
||||
expr2: expr3 '*' expr2 -> ^('*' expr3 expr2)
|
||||
| expr3 '/' expr2 -> ^('/' expr3 expr2)
|
||||
| expr3 -> ^(expr3);
|
||||
expr3: number -> ^(number)
|
||||
| UMINUS number -> ^(UMINUS number)
|
||||
| t=STRINGCONST | t=ID -> ^($t)
|
||||
| '(' expr ')' -> ^(expr);
|
||||
expr3: number | '-' number | STRINGCONST | '('! expr^ ')';
|
||||
number: INTCONST | FLOATCONST;
|
||||
|
||||
cond: expr cond2 -> ^(expr cond2);
|
||||
cond2: BINOP expr -> ^(BINOP expr);
|
||||
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: '+';
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
T__20=20
|
||||
T__21=21
|
||||
T__22=22
|
||||
T__23=23
|
||||
T__24=24
|
||||
T__25=25
|
||||
T__26=26
|
||||
T__27=27
|
||||
T__28=28
|
||||
T__29=29
|
||||
T__30=30
|
||||
T__31=31
|
||||
T__32=32
|
||||
T__33=33
|
||||
T__34=34
|
||||
T__35=35
|
||||
T__36=36
|
||||
T__37=37
|
||||
T__38=38
|
||||
T__39=39
|
||||
T__40=40
|
||||
T__41=41
|
||||
T__42=42
|
||||
T__43=43
|
||||
T__44=44
|
||||
T__45=45
|
||||
DECL=4
|
||||
DECLIST=5
|
||||
DIGIT=6
|
||||
ESCAPE=7
|
||||
EXPR=8
|
||||
FLOATCONST=9
|
||||
ID=10
|
||||
INTCONST=11
|
||||
INVALID=12
|
||||
MODIFIER=13
|
||||
PROGRAM=14
|
||||
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
|
||||
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.
Binary file not shown.
@@ -1,38 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="EclipseModuleManager">
|
||||
<libelement value="jar://$MODULE_DIR$/lib/jflex-1.6.1.jar!/" />
|
||||
<src_description expected_position="0">
|
||||
<src_folder value="file://$MODULE_DIR$/src" expected_position="0" />
|
||||
</src_description>
|
||||
</component>
|
||||
<component name="NewModuleRootManager">
|
||||
<output url="file://$MODULE_DIR$/bin" />
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="jdk" jdkName="JavaSE-1.7" jdkType="JavaSDK" />
|
||||
<orderEntry type="module-library">
|
||||
<library name="junit4">
|
||||
<CLASSES>
|
||||
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="module-library">
|
||||
<library name="jflex-1.6.1.jar">
|
||||
<CLASSES>
|
||||
<root url="jar://$MODULE_DIR$/lib/jflex-1.6.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC />
|
||||
<SOURCES />
|
||||
</library>
|
||||
</orderEntry>
|
||||
<orderEntry type="library" name="junit:junit:4.12" level="application" />
|
||||
<orderEntry type="library" name="lib" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
Reference in New Issue
Block a user