[11 - Antlr Parser] Implement more stuff
This commit is contained in:
9
.idea/Java.iml
generated
Normal file
9
.idea/Java.iml
generated
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
147
.idea/workspace.xml
generated
147
.idea/workspace.xml
generated
@@ -1,7 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<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/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/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" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@@ -25,8 +29,43 @@
|
||||
<property name="project.structure.proportion" value="0.15429688" />
|
||||
<property name="project.structure.side.proportion" value="0.2" />
|
||||
</component>
|
||||
<component name="RunManager" selected="JUnit.TestAntlrXScanner1.tokenID">
|
||||
<configuration name="TestAntlrXScanner1.tokenID" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<component name="RunManager" selected="JUnit.TestAntlrXScanner1.tokenASSIGN">
|
||||
<configuration name="TestAntlrXParser1" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<module name="CC-Praxis-Antlr Parser fuer X-Leer" />
|
||||
<useClassPathOnly />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="de.dhbw.compiler.antlrxparser.test.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<option name="PACKAGE_NAME" value="de.dhbw.compiler.antlrxparser.test" />
|
||||
<option name="MAIN_CLASS_NAME" value="de.dhbw.compiler.antlrxparser.test.TestAntlrXParser1" />
|
||||
<option name="METHOD_NAME" value="" />
|
||||
<option name="TEST_OBJECT" value="class" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<method v="2">
|
||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Run Antlr Builder" run_configuration_type="Application" />
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="TestAntlrXParser1.program00BeginEnd" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<module name="CC-Praxis-Antlr Parser fuer X-Leer" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="de.dhbw.compiler.antlrxparser.test.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<option name="PACKAGE_NAME" value="de.dhbw.compiler.antlrxparser.test" />
|
||||
<option name="MAIN_CLASS_NAME" value="de.dhbw.compiler.antlrxparser.test.TestAntlrXParser1" />
|
||||
<option name="METHOD_NAME" value="program00BeginEnd" />
|
||||
<option name="TEST_OBJECT" value="method" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="TestAntlrXScanner1" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<module name="CC-Praxis-Antlr Parser fuer X-Leer" />
|
||||
<useClassPathOnly />
|
||||
<extension name="coverage">
|
||||
@@ -37,21 +76,81 @@
|
||||
</extension>
|
||||
<option name="PACKAGE_NAME" value="de.dhbw.compiler.antlrxparser.test" />
|
||||
<option name="MAIN_CLASS_NAME" value="de.dhbw.compiler.antlrxparser.test.TestAntlrXScanner1" />
|
||||
<option name="METHOD_NAME" value="tokenID" />
|
||||
<option name="METHOD_NAME" value="" />
|
||||
<option name="TEST_OBJECT" value="class" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<method v="2">
|
||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Run Antlr Builder" run_configuration_type="Application" />
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="TestAntlrXScanner1.tokenASSIGN" type="JUnit" factoryName="JUnit" nameIsGenerated="true">
|
||||
<module name="CC-Praxis-Antlr Parser fuer X-Leer" />
|
||||
<useClassPathOnly />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="de.dhbw.compiler.antlrxparser.test.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<option name="PACKAGE_NAME" value="de.dhbw.compiler.antlrxparser.test" />
|
||||
<option name="MAIN_CLASS_NAME" value="de.dhbw.compiler.antlrxparser.test.TestAntlrXScanner1" />
|
||||
<option name="METHOD_NAME" value="tokenASSIGN" />
|
||||
<option name="TEST_OBJECT" value="method" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<method v="2">
|
||||
<option name="RunConfigurationTask" enabled="true" />
|
||||
<option name="RunConfigurationTask" enabled="true" run_configuration_name="Run Antlr Builder" run_configuration_type="Application" />
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="TestAntlrXScanner1.tokenREAD" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<module name="CC-Praxis-Antlr Parser fuer X-Leer" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="de.dhbw.compiler.antlrxparser.test.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<option name="PACKAGE_NAME" value="de.dhbw.compiler.antlrxparser.test" />
|
||||
<option name="MAIN_CLASS_NAME" value="de.dhbw.compiler.antlrxparser.test.TestAntlrXScanner1" />
|
||||
<option name="METHOD_NAME" value="tokenREAD" />
|
||||
<option name="TEST_OBJECT" value="method" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<configuration name="TestAntlrXScanner1.tokenStringConst" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<module name="CC-Praxis-Antlr Parser fuer X-Leer" />
|
||||
<extension name="coverage">
|
||||
<pattern>
|
||||
<option name="PATTERN" value="de.dhbw.compiler.antlrxparser.test.*" />
|
||||
<option name="ENABLED" value="true" />
|
||||
</pattern>
|
||||
</extension>
|
||||
<option name="PACKAGE_NAME" value="de.dhbw.compiler.antlrxparser.test" />
|
||||
<option name="MAIN_CLASS_NAME" value="de.dhbw.compiler.antlrxparser.test.TestAntlrXScanner1" />
|
||||
<option name="METHOD_NAME" value="tokenStringConst" />
|
||||
<option name="TEST_OBJECT" value="method" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
<list>
|
||||
<item itemvalue="Application.Run Antlr Builder" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenID" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenASSIGN" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenREAD" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1.program00BeginEnd" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenStringConst" />
|
||||
</list>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenID" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenStringConst" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1.program00BeginEnd" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenREAD" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
@@ -67,6 +166,7 @@
|
||||
<updated>1591172713288</updated>
|
||||
<workItem from="1591172719978" duration="202000" />
|
||||
<workItem from="1591172941402" duration="220000" />
|
||||
<workItem from="1591174233890" duration="8126000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@@ -78,26 +178,39 @@
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
</state>
|
||||
<state x="208" y="31" key="#Project_Structure/0.0.1440.900@0.0.1440.900" timestamp="1591172830001" />
|
||||
<state x="184" y="112" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1591172899381">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
<state x="570" y="121" key="#TestAntlrXScanner1.tokenASSIGN" timestamp="1591175187591">
|
||||
<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">
|
||||
<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 width="1398" height="245" key="GridCell.Tab.0.bottom" timestamp="1591173185826">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
<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">
|
||||
<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">
|
||||
<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="1398" height="245" key="GridCell.Tab.0.center" timestamp="1591173185825">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
<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">
|
||||
<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="1398" height="245" key="GridCell.Tab.0.left" timestamp="1591173185825">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
<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">
|
||||
<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="1398" height="245" key="GridCell.Tab.0.right" timestamp="1591173185826">
|
||||
<screen x="0" y="0" width="1440" height="900" />
|
||||
<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">
|
||||
<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>
|
||||
|
||||
@@ -1,6 +1,63 @@
|
||||
T__8=8
|
||||
FLOATCONST=4
|
||||
ID=5
|
||||
INTCONST=6
|
||||
WS=7
|
||||
'TODO'=8
|
||||
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
|
||||
|
||||
1325
CC-Praxis-Antlr Parser fuer X-Leer/XLexer.java
Normal file
1325
CC-Praxis-Antlr Parser fuer X-Leer/XLexer.java
Normal file
File diff suppressed because it is too large
Load Diff
2820
CC-Praxis-Antlr Parser fuer X-Leer/XParser.java
Normal file
2820
CC-Praxis-Antlr Parser fuer X-Leer/XParser.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,18 @@ tokens {
|
||||
INTCONST;
|
||||
FLOATCONST;
|
||||
WS;
|
||||
MODIFIER;
|
||||
UMINUS='-';
|
||||
UPLUS='+';
|
||||
UMULTIPLY='*';
|
||||
UDIVIDE='/';
|
||||
DECLIST;
|
||||
PROGRAM;
|
||||
DECL;
|
||||
TYPE;
|
||||
STAT;
|
||||
STATLIST;
|
||||
EXPR;
|
||||
}
|
||||
|
||||
@parser::header {package de.dhbw.compiler.antlrxparser;}
|
||||
@@ -35,10 +47,51 @@ ID: ('a'..'z' | 'A'..'Z')
|
||||
(options {
|
||||
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;
|
||||
|
||||
STRINGCONST: '"' (ESCAPE | ~('\\' | '"'))* '"';
|
||||
ESCAPE: '\\' ('\"' |'\'' | '\\');
|
||||
|
||||
BINOP: '+' | '-' | '*' | '/' | '<' | '>' | '=';
|
||||
|
||||
WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); };
|
||||
|
||||
// Parser stuff
|
||||
program: 'TODO';
|
||||
|
||||
// -- Parser stuff
|
||||
program: 'program' ID ';' decllist statlist '.' EOF -> ^(PROGRAM ID decllist statlist);
|
||||
|
||||
// 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]);
|
||||
|
||||
// Block
|
||||
statlist: 'begin' (stat ';')* 'end' -> ^(STATLIST stat*);
|
||||
stat: t=assignstat | t=condstat | t=whilestat | t=forstat -> ^(STAT[t])
|
||||
| statlist
|
||||
-> ^(STATLIST statlist);
|
||||
assignstat: ID ':=' expr -> ^(':=' ID expr);
|
||||
condstat: 'if' cond 'then' stat condElseStat? -> ^('if' cond stat condElseStat? );
|
||||
condElseStat: 'else' stat -> ^('else' stat);
|
||||
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)
|
||||
| expr2 -> ^(expr2);
|
||||
expr2: expr3 UMULTIPLY expr2 -> ^(UMULTIPLY expr3 expr2)
|
||||
| expr3 UDIVIDE expr2 -> ^(UDIVIDE expr3 expr2)
|
||||
| expr3 -> ^(expr3);
|
||||
expr3: number -> ^(number)
|
||||
| UMINUS number -> ^(UMINUS number)
|
||||
| t=STRINGCONST | t=ID -> ^($t)
|
||||
| '(' expr ')' -> ^(expr);
|
||||
number: INTCONST | FLOATCONST;
|
||||
|
||||
cond: expr cond2 -> ^(expr cond2);
|
||||
cond2: BINOP expr -> ^(BINOP expr);
|
||||
|
||||
|
||||
@@ -24,6 +24,18 @@ tokens {
|
||||
INTCONST;
|
||||
FLOATCONST;
|
||||
WS;
|
||||
MODIFIER;
|
||||
UMINUS='-';
|
||||
UPLUS='+';
|
||||
UMULTIPLY='*';
|
||||
UDIVIDE='/';
|
||||
DECLIST;
|
||||
PROGRAM;
|
||||
DECL;
|
||||
TYPE;
|
||||
STAT;
|
||||
STATLIST;
|
||||
EXPR;
|
||||
}
|
||||
|
||||
@parser::header {package de.dhbw.compiler.antlrxparser;}
|
||||
@@ -35,10 +47,51 @@ ID: ('a'..'z' | 'A'..'Z')
|
||||
(options {
|
||||
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;
|
||||
|
||||
STRINGCONST: '"' (ESCAPE | ~('\\' | '"'))* '"';
|
||||
ESCAPE: '\\' ('\"' |'\'' | '\\');
|
||||
|
||||
BINOP: '+' | '-' | '*' | '/' | '<' | '>' | '=';
|
||||
|
||||
WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); };
|
||||
|
||||
// Parser stuff
|
||||
program: 'TODO';
|
||||
|
||||
// -- Parser stuff
|
||||
program: 'program' ID ';' decllist statlist '.' EOF -> ^(PROGRAM ID decllist statlist);
|
||||
|
||||
// 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]);
|
||||
|
||||
// Block
|
||||
statlist: 'begin' (stat ';')* 'end' -> ^(STATLIST stat*);
|
||||
stat: t=assignstat | t=condstat | t=whilestat | t=forstat -> ^(STAT[t])
|
||||
| statlist
|
||||
-> ^(STATLIST statlist);
|
||||
assignstat: ID ':=' expr -> ^(':=' ID expr);
|
||||
condstat: 'if' cond 'then' stat condElseStat? -> ^('if' cond stat condElseStat? );
|
||||
condElseStat: 'else' stat -> ^('else' stat);
|
||||
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)
|
||||
| expr2 -> ^(expr2);
|
||||
expr2: expr3 UMULTIPLY expr2 -> ^(UMULTIPLY expr3 expr2)
|
||||
| expr3 UDIVIDE expr2 -> ^(UDIVIDE expr3 expr2)
|
||||
| expr3 -> ^(expr3);
|
||||
expr3: number -> ^(number)
|
||||
| UMINUS number -> ^(UMINUS number)
|
||||
| t=STRINGCONST | t=ID -> ^($t)
|
||||
| '(' expr ')' -> ^(expr);
|
||||
number: INTCONST | FLOATCONST;
|
||||
|
||||
cond: expr cond2 -> ^(expr cond2);
|
||||
cond2: BINOP expr -> ^(BINOP expr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user