[11 - Antlr Builder] Add other changes
This commit is contained in:
69
.idea/workspace.xml
generated
69
.idea/workspace.xml
generated
@@ -1,7 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ChangeListManager">
|
||||
<<<<<<< Updated upstream
|
||||
<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" />
|
||||
<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" />
|
||||
</list>
|
||||
>>>>>>> Stashed changes
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
@@ -134,8 +149,8 @@
|
||||
</configuration>
|
||||
<list>
|
||||
<item itemvalue="Application.Run Antlr Builder" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenASSIGN" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenREAD" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1.program00BeginEnd" />
|
||||
@@ -143,9 +158,16 @@
|
||||
</list>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<<<<<<< Updated upstream
|
||||
<item itemvalue="JUnit.TestAntlrXParser1" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenStringConst" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1.program00BeginEnd" />
|
||||
=======
|
||||
<item itemvalue="JUnit.TestAntlrXParser1.program00BeginEnd" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenStringConst" />
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1" />
|
||||
<item itemvalue="JUnit.TestAntlrXParser1" />
|
||||
>>>>>>> Stashed changes
|
||||
<item itemvalue="JUnit.TestAntlrXScanner1.tokenREAD" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
@@ -162,8 +184,14 @@
|
||||
<updated>1591172713288</updated>
|
||||
<workItem from="1591172719978" duration="202000" />
|
||||
<workItem from="1591172941402" duration="220000" />
|
||||
<<<<<<< Updated upstream
|
||||
<workItem from="1591174233890" duration="9316000" />
|
||||
<workItem from="1591183629705" duration="4405000" />
|
||||
=======
|
||||
<workItem from="1591174233890" duration="8126000" />
|
||||
<workItem from="1591182692118" duration="1868000" />
|
||||
<workItem from="1591263665308" duration="16000" />
|
||||
>>>>>>> Stashed changes
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@@ -179,6 +207,7 @@
|
||||
<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" />
|
||||
<<<<<<< Updated upstream
|
||||
<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>
|
||||
@@ -218,6 +247,44 @@
|
||||
<state width="916" height="398" key="GridCell.Tab.0.right/0.0.1920.1040@0.0.1920.1040" timestamp="1591188037708" />
|
||||
<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 x="184" y="125" key="#com.intellij.execution.impl.EditConfigurationsDialog" timestamp="1591184492286">
|
||||
<screen x="0" y="23" width="1440" height="821" />
|
||||
</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="184" y="125" key="#com.intellij.execution.impl.EditConfigurationsDialog/0.23.1440.821@0.23.1440.821" timestamp="1591184492286" />
|
||||
<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="1398" height="211" key="GridCell.Tab.0.bottom" timestamp="1591184646781">
|
||||
<screen x="0" y="23" width="1440" height="821" />
|
||||
</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="1398" height="211" key="GridCell.Tab.0.bottom/0.23.1440.821@0.23.1440.821" timestamp="1591184646781" />
|
||||
<state width="1398" height="211" key="GridCell.Tab.0.center" timestamp="1591184646781">
|
||||
<screen x="0" y="23" width="1440" height="821" />
|
||||
</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="1398" height="211" key="GridCell.Tab.0.center/0.23.1440.821@0.23.1440.821" timestamp="1591184646781" />
|
||||
<state width="1398" height="211" key="GridCell.Tab.0.left" timestamp="1591184646780">
|
||||
<screen x="0" y="23" width="1440" height="821" />
|
||||
</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="1398" height="211" key="GridCell.Tab.0.left/0.23.1440.821@0.23.1440.821" timestamp="1591184646780" />
|
||||
<state width="1398" height="211" key="GridCell.Tab.0.right" timestamp="1591184646781">
|
||||
<screen x="0" y="23" width="1440" height="821" />
|
||||
</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 width="1398" height="211" key="GridCell.Tab.0.right/0.23.1440.821@0.23.1440.821" timestamp="1591184646781" />
|
||||
<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" />
|
||||
>>>>>>> Stashed changes
|
||||
</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="447" y="180" key="NewModule_or_Project.wizard/0.0.1920.1040@0.0.1920.1040" timestamp="1591184776491" />
|
||||
|
||||
68
CC-Praxis-Antlr Parser fuer X-Leer/X.tokens
Normal file
68
CC-Praxis-Antlr Parser fuer X-Leer/X.tokens
Normal file
@@ -0,0 +1,68 @@
|
||||
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
|
||||
DECL=4
|
||||
DECLIST=5
|
||||
ESCAPE=6
|
||||
EXPR=7
|
||||
FLOATCONST=8
|
||||
ID=9
|
||||
INTCONST=10
|
||||
MODIFIER=11
|
||||
PROGRAM=12
|
||||
STAT=13
|
||||
STATLIST=14
|
||||
STRINGCONST=15
|
||||
TYPE=16
|
||||
UDIVIDE=17
|
||||
UMINUS=18
|
||||
UMULTIPLY=19
|
||||
UPLUS=20
|
||||
WS=21
|
||||
'('=22
|
||||
')'=23
|
||||
'*'=19
|
||||
'+'=20
|
||||
'-'=18
|
||||
'.'=24
|
||||
'/'=17
|
||||
':'=25
|
||||
':='=26
|
||||
';'=27
|
||||
'<'=28
|
||||
'='=29
|
||||
'>'=30
|
||||
'begin'=31
|
||||
'else'=32
|
||||
'end'=33
|
||||
'float'=34
|
||||
'for'=35
|
||||
'if'=36
|
||||
'int'=37
|
||||
'print'=38
|
||||
'program'=39
|
||||
'read print'=40
|
||||
'read'=41
|
||||
'string'=42
|
||||
'then'=43
|
||||
'while'=44
|
||||
@@ -86,7 +86,6 @@ expr2: expr3 (op='*' | op='/') expr -> ^($op expr3 expr)
|
||||
expr3: op='-' num=number -> ^(UMINUS[op,"UMINUS"] $num)
|
||||
| number | STRINGCONST | '('! expr^ ')'!;
|
||||
|
||||
// Conditions and comparison
|
||||
compOp: '<' | '>' | '=';
|
||||
cond: expr cond2;
|
||||
cond2: compOp expr;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,68 +0,0 @@
|
||||
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
|
||||
COMMENT=4
|
||||
DECL=5
|
||||
DECLLIST=6
|
||||
DIGIT=7
|
||||
FLOATCONST=8
|
||||
ID=9
|
||||
INTCONST=10
|
||||
INVALID=11
|
||||
LETTER=12
|
||||
OTHER=13
|
||||
POSDIGIT=14
|
||||
STATLIST=15
|
||||
STRINGCONST=16
|
||||
UMINUS=17
|
||||
WS=18
|
||||
ZERO=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.
@@ -1,92 +0,0 @@
|
||||
/* **********************************************
|
||||
* Duale Hochschule Baden-Württemberg Karlsruhe
|
||||
* Prof. Dr. Jörn Eisenbiegler
|
||||
*
|
||||
* Vorlesung Übersetzerbau
|
||||
* Praxis ANTLR-Parser für X
|
||||
* - Grammatik für Scanner und Parser
|
||||
*
|
||||
* **********************************************
|
||||
*/
|
||||
|
||||
grammar X;
|
||||
|
||||
options {
|
||||
language = Java;
|
||||
output = AST;
|
||||
ASTLabelType = CommonTree;
|
||||
backtrack = true;
|
||||
}
|
||||
|
||||
// AST-Tokens
|
||||
tokens {
|
||||
ID;
|
||||
INTCONST;
|
||||
FLOATCONST;
|
||||
WS;
|
||||
MODIFIER;
|
||||
DECLLIST;
|
||||
UMINUS;
|
||||
PROGRAM;
|
||||
DECL;
|
||||
TYPE;
|
||||
STAT;
|
||||
STATLIST;
|
||||
EXPR;
|
||||
INVALID;
|
||||
}
|
||||
|
||||
@parser::header {package de.dhbw.compiler.antlrxparser;}
|
||||
@lexer::header {package de.dhbw.compiler.antlrxparser;}
|
||||
|
||||
// Anmerkung: Es müssen Lexer- UND Parser-Regeln stehen, da sonst das Generieren nicht funktionieren
|
||||
// Lexer stuff
|
||||
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' | ('1'..'9') ('0'..'9')*;
|
||||
FLOATCONST: INTCONST ('.' DIGIT*)? ('e'|'E')('+' |'-' )? INTCONST
|
||||
| INTCONST ('.' DIGIT*)?;
|
||||
|
||||
STRINGCONST: '"' (ESCAPE | ~('\\' | '"'))* '"';
|
||||
ESCAPE: '\\' ('\"' |'\'' | '\\');
|
||||
|
||||
WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); };
|
||||
|
||||
fragment DIGIT: ('0'..'9');
|
||||
|
||||
|
||||
// -- Parser stuff
|
||||
program: 'program'^ ID ';'! decllist statlist '.'! EOF!;
|
||||
|
||||
// Declaration
|
||||
decllist: decl* -> ^(DECLLIST decl*);
|
||||
decl: modifier? ID ':' type ';' -> ^(DECL modifier? ID type);
|
||||
modifier: 'read' 'print'? | 'read' | 'print';
|
||||
type: 'int' | 'float' | 'string';
|
||||
|
||||
// Block
|
||||
statlist: 'begin' (stat ';')* 'end' -> ^(STATLIST stat*);
|
||||
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);
|
||||
whilestat: 'while' '(' cond ')' stat -> ^('while' cond stat);
|
||||
forstat: 'for' '(' assignstat ';' cond ';' assignstat ')' stat
|
||||
-> ^('for' assignstat cond assignstat stat);
|
||||
|
||||
// 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;
|
||||
@@ -1,69 +0,0 @@
|
||||
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
|
||||
T__46=46
|
||||
DECL=4
|
||||
DECLLIST=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
|
||||
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,148 +0,0 @@
|
||||
/* **********************************************
|
||||
* Duale Hochschule Baden-Württemberg Karlsruhe
|
||||
* Prof. Dr. Jörn Eisenbiegler
|
||||
*
|
||||
* Vorlesung Übersetzerbau
|
||||
* Praxis X Abstiegsparser
|
||||
* - Scanner-Definition
|
||||
*
|
||||
* **********************************************
|
||||
*/
|
||||
|
||||
|
||||
package de.dhbw.compiler.xparser;
|
||||
|
||||
%%
|
||||
|
||||
%class JFlexXScanner
|
||||
%type Token
|
||||
%function nextToken
|
||||
|
||||
|
||||
%unicode
|
||||
%line
|
||||
%column
|
||||
|
||||
%public
|
||||
%final
|
||||
|
||||
%xstate INT, FRACTION, EXPVZ, EXP, STRING
|
||||
|
||||
%{
|
||||
private int intvalue=0;
|
||||
private String textvalue ="";
|
||||
private int fracvalue=0;
|
||||
private int fraclength=0;
|
||||
private int expvalue=0;
|
||||
private int expsign=1;
|
||||
private int startline =0;
|
||||
private int startcolumn =0;
|
||||
private String stringvalue="";
|
||||
%}
|
||||
|
||||
|
||||
|
||||
%%
|
||||
|
||||
read { return new Token(Token.READ, yytext(), yyline+1, yycolumn+1); }
|
||||
print { return new Token(Token.PRINT, yytext(), yyline+1, yycolumn+1); }
|
||||
int { return new Token(Token.INT, yytext(), yyline+1, yycolumn+1); }
|
||||
float { return new Token(Token.FLOAT, yytext(), yyline+1, yycolumn+1); }
|
||||
string { return new Token(Token.STRING, yytext(), yyline+1, yycolumn+1); }
|
||||
\+ { return new Token(Token.PLUS, yytext(), yyline+1, yycolumn+1); }
|
||||
\- { return new Token(Token.MINUS, yytext(), yyline+1, yycolumn+1); }
|
||||
\* { return new Token(Token.MULT, yytext(), yyline+1, yycolumn+1); }
|
||||
\/ { return new Token(Token.DIV, yytext(), yyline+1, yycolumn+1); }
|
||||
:= { return new Token(Token.ASSIGN, yytext(), yyline+1, yycolumn+1); }
|
||||
\( { return new Token(Token.LBR, yytext(), yyline+1, yycolumn+1); }
|
||||
\) { return new Token(Token.RBR, yytext(), yyline+1, yycolumn+1); }
|
||||
\< { return new Token(Token.LESS, yytext(), yyline+1, yycolumn+1); }
|
||||
> { return new Token(Token.MORE, yytext(), yyline+1, yycolumn+1); }
|
||||
= { return new Token(Token.EQUALS, yytext(), yyline+1, yycolumn+1); }
|
||||
if { return new Token(Token.IF, yytext(), yyline+1, yycolumn+1); }
|
||||
then { return new Token(Token.THEN, yytext(), yyline+1, yycolumn+1); }
|
||||
else { return new Token(Token.ELSE, yytext(), yyline+1, yycolumn+1); }
|
||||
while { return new Token(Token.WHILE, yytext(), yyline+1, yycolumn+1); }
|
||||
for { return new Token(Token.FOR, yytext(), yyline+1, yycolumn+1); }
|
||||
; { return new Token(Token.SEMICOLON, yytext(), yyline+1, yycolumn+1); }
|
||||
begin { return new Token(Token.BEGIN, yytext(), yyline+1, yycolumn+1); }
|
||||
end { return new Token(Token.END, yytext(), yyline+1, yycolumn+1); }
|
||||
program { return new Token(Token.PROGRAM, yytext(), yyline+1, yycolumn+1); }
|
||||
\. { return new Token(Token.DOT, yytext(), yyline+1, yycolumn+1); }
|
||||
: { return new Token(Token.COLON, yytext(), yyline+1, yycolumn+1); }
|
||||
|
||||
|
||||
[a-zA-Z][a-zA-Z0-9]* { return new Token(Token.ID, yytext(), yyline+1, yycolumn+1); }
|
||||
|
||||
0 { return new IntConstToken(Token.INTCONST, yytext(), yyline+1, yycolumn+1, 0); }
|
||||
0/\. { yybegin(INT); textvalue=yytext(); startline=yyline+1; startcolumn=yycolumn+1;
|
||||
intvalue=yytext().charAt(0)-'0'; fracvalue=0; fraclength=0; expvalue=0; }
|
||||
[1-9] { yybegin(INT); textvalue=yytext(); startline=yyline+1; startcolumn=yycolumn+1;
|
||||
intvalue=yytext().charAt(0)-'0'; fracvalue=0; fraclength=0; expvalue=0; }
|
||||
|
||||
\" { yybegin(STRING); textvalue="\""; stringvalue=""; startline=yyline+1; startcolumn=yycolumn+1; }
|
||||
|
||||
(\/\*)~(\*\/) { /* eat comments */ }
|
||||
[\ \t\b\f\r\n]+ { /* eat whitespace */ }
|
||||
<<EOF>> { return new Token(Token.EOF, yytext(), yyline+1, yycolumn+1); }
|
||||
[^] { return new Token(Token.INVALID, yytext(), yyline+1, yycolumn+1); }
|
||||
|
||||
<STRING> {
|
||||
[a-zA-Z \.:] { textvalue+=yytext(); stringvalue+=yytext(); }
|
||||
\\\" { textvalue+="\\\""; stringvalue+="\""; }
|
||||
\" { yybegin(YYINITIAL); return new StringConstToken(Token.STRINGCONST, textvalue+"\"", startline, startcolumn, stringvalue); }
|
||||
[^] { yybegin(YYINITIAL); return new Token(Token.INVALID, textvalue+yytext(), startline, startcolumn); }
|
||||
<<EOF>> { yybegin(YYINITIAL); return new Token(Token.INVALID, textvalue, startline, startcolumn); }
|
||||
}
|
||||
|
||||
<INT> {
|
||||
[0-9] { intvalue = 10*intvalue + yytext().charAt(0)-'0';
|
||||
textvalue+=yytext();}
|
||||
\. { yybegin(FRACTION);
|
||||
textvalue+=yytext();}
|
||||
[eE]/-?[0-9] { yybegin(EXPVZ); textvalue += yytext(); }
|
||||
[^] { yybegin(YYINITIAL);
|
||||
yypushback(1);
|
||||
return new IntConstToken(Token.INTCONST, textvalue, startline, startcolumn, intvalue); }
|
||||
<<EOF>> { yybegin(YYINITIAL);
|
||||
yypushback(1);
|
||||
return new IntConstToken(Token.INTCONST, textvalue, startline, startcolumn, intvalue);}
|
||||
}
|
||||
|
||||
<FRACTION> {
|
||||
[0-9] { fracvalue= 10*fracvalue+ yytext().charAt(0)-'0';
|
||||
fraclength++;
|
||||
textvalue+=yytext();}
|
||||
[eE]/-?[0-9] { yybegin(EXPVZ);
|
||||
textvalue+=yytext();}
|
||||
[^] { yybegin(YYINITIAL);
|
||||
yypushback(1);
|
||||
return new FloatConstToken(Token.FLOATCONST, textvalue, startline, startcolumn,intvalue+fracvalue/Math.pow(10,fraclength)); }
|
||||
<<EOF>> { yybegin(YYINITIAL);
|
||||
yypushback(1);
|
||||
return new FloatConstToken(Token.FLOATCONST, textvalue, startline, startcolumn,intvalue+fracvalue/Math.pow(10,fraclength)); }
|
||||
}
|
||||
|
||||
<EXPVZ> {
|
||||
-0|0 { yybegin(YYINITIAL);
|
||||
return new FloatConstToken(Token.FLOATCONST, textvalue+yytext(), startline, startcolumn,intvalue+fracvalue/Math.pow(10,fraclength)); }
|
||||
-[1-9] { yybegin(EXP); expvalue=yytext().charAt(1)-'0'; expsign=-1; textvalue+=yytext(); }
|
||||
[1-9] { yybegin(EXP); expvalue=yytext().charAt(0)-'0'; expsign=1; textvalue+=yytext(); }
|
||||
[^] { yybegin(YYINITIAL);
|
||||
yypushback(1);
|
||||
return new Token(Token.INVALID, textvalue, startline, startcolumn); }
|
||||
<<EOF>> { yybegin(YYINITIAL);
|
||||
yypushback(1);
|
||||
return new Token(Token.INVALID, textvalue, startline, startcolumn); }
|
||||
}
|
||||
|
||||
<EXP> {
|
||||
[0-9] { expvalue = 10* expvalue + yytext().charAt(0)-'0'; textvalue+=yytext(); }
|
||||
[^] { yybegin(YYINITIAL);
|
||||
yypushback(1);
|
||||
return new FloatConstToken(Token.FLOATCONST, textvalue, startline, startcolumn, (intvalue+fracvalue/Math.pow(10,fraclength))*Math.pow(10,expvalue*expsign)); }
|
||||
<<EOF>> { yybegin(YYINITIAL);
|
||||
yypushback(1);
|
||||
return new FloatConstToken(Token.FLOATCONST, textvalue, startline, startcolumn, (intvalue+fracvalue/Math.pow(10,fraclength))*Math.pow(10,expvalue*expsign)); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user