Clean up and fix Antlr Parser module

This commit is contained in:
2020-06-03 10:07:51 +02:00
parent ef7bb13422
commit 620b6e35bd
36 changed files with 297 additions and 975 deletions

View File

@@ -1,5 +1,6 @@
T__7=7
ID=4
INTCONST=5
WS=6
'TODO'=7
T__8=8
FLOATCONST=4
ID=5
INTCONST=6
WS=7
'TODO'=8

View File

@@ -22,6 +22,7 @@ options {
tokens {
ID;
INTCONST;
FLOATCONST;
WS;
}
@@ -35,6 +36,7 @@ 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;
WS: ('\t' | ' ' | '\r' | '\n' | '\f')+ { skip(); };

View File

@@ -1,4 +1,4 @@
// $ANTLR 3.5.2 /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g 2020-05-27 16:02:18
// $ANTLR 3.5.2 /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g 2020-06-03 10:07:23
package de.dhbw.compiler.antlrxparser;
import org.antlr.runtime.*;
@@ -9,10 +9,11 @@ import java.util.ArrayList;
@SuppressWarnings("all")
public class XLexer extends Lexer {
public static final int EOF=-1;
public static final int T__7=7;
public static final int ID=4;
public static final int INTCONST=5;
public static final int WS=6;
public static final int T__8=8;
public static final int FLOATCONST=4;
public static final int ID=5;
public static final int INTCONST=6;
public static final int WS=7;
// delegates
// delegators
@@ -29,10 +30,10 @@ public class XLexer extends Lexer {
}
@Override public String getGrammarFileName() { return "/Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g"; }
// $ANTLR start "T__7"
public final void mT__7() throws RecognitionException {
// $ANTLR start "T__8"
public final void mT__8() throws RecognitionException {
try {
int _type = T__7;
int _type = T__8;
int _channel = DEFAULT_TOKEN_CHANNEL;
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:9:6: ( 'TODO' )
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:9:8: 'TODO'
@@ -48,15 +49,15 @@ public class XLexer extends Lexer {
// do for sure before leaving
}
}
// $ANTLR end "T__7"
// $ANTLR end "T__8"
// $ANTLR start "ID"
public final void mID() throws RecognitionException {
try {
int _type = ID;
int _channel = DEFAULT_TOKEN_CHANNEL;
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:33:3: ( ( 'a' .. 'z' | 'A' .. 'Z' ) ( options {greedy=true; } : 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' )* )
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:33:13: ( 'a' .. 'z' | 'A' .. 'Z' ) ( options {greedy=true; } : 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' )*
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:34:3: ( ( 'a' .. 'z' | 'A' .. 'Z' ) ( options {greedy=true; } : 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' )* )
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:34:13: ( 'a' .. 'z' | 'A' .. 'Z' ) ( options {greedy=true; } : 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' )*
{
if ( (input.LA(1) >= 'A' && input.LA(1) <= 'Z')||(input.LA(1) >= 'a' && input.LA(1) <= 'z') ) {
input.consume();
@@ -66,7 +67,7 @@ public class XLexer extends Lexer {
recover(mse);
throw mse;
}
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:34:13: ( options {greedy=true; } : 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' )*
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:35:13: ( options {greedy=true; } : 'a' .. 'z' | 'A' .. 'Z' | '0' .. '9' )*
loop1:
while (true) {
int alt1=4;
@@ -148,19 +149,19 @@ public class XLexer extends Lexer {
}
switch (alt1) {
case 1 :
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:36:16: 'a' .. 'z'
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:37:16: 'a' .. 'z'
{
matchRange('a','z');
}
break;
case 2 :
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:36:27: 'A' .. 'Z'
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:37:27: 'A' .. 'Z'
{
matchRange('A','Z');
}
break;
case 3 :
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:36:38: '0' .. '9'
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:37:38: '0' .. '9'
{
matchRange('0','9');
}
@@ -187,10 +188,10 @@ public class XLexer extends Lexer {
try {
int _type = INTCONST;
int _channel = DEFAULT_TOKEN_CHANNEL;
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:37:9: ( ( '0' .. '9' )+ )
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:37:13: ( '0' .. '9' )+
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:38:9: ( ( '0' .. '9' )+ )
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:38:13: ( '0' .. '9' )+
{
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:37:13: ( '0' .. '9' )+
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:38:13: ( '0' .. '9' )+
int cnt2=0;
loop2:
while (true) {
@@ -234,15 +235,39 @@ public class XLexer extends Lexer {
}
// $ANTLR end "INTCONST"
// $ANTLR start "FLOATCONST"
public final void mFLOATCONST() throws RecognitionException {
try {
int _type = FLOATCONST;
int _channel = DEFAULT_TOKEN_CHANNEL;
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:39:11: ( INTCONST '.' INTCONST )
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:39:13: INTCONST '.' INTCONST
{
mINTCONST();
match('.');
mINTCONST();
}
state.type = _type;
state.channel = _channel;
}
finally {
// do for sure before leaving
}
}
// $ANTLR end "FLOATCONST"
// $ANTLR start "WS"
public final void mWS() throws RecognitionException {
try {
int _type = WS;
int _channel = DEFAULT_TOKEN_CHANNEL;
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:39:3: ( ( '\\t' | ' ' | '\\r' | '\\n' | '\\f' )+ )
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:39:13: ( '\\t' | ' ' | '\\r' | '\\n' | '\\f' )+
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:41:3: ( ( '\\t' | ' ' | '\\r' | '\\n' | '\\f' )+ )
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:41:13: ( '\\t' | ' ' | '\\r' | '\\n' | '\\f' )+
{
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:39:13: ( '\\t' | ' ' | '\\r' | '\\n' | '\\f' )+
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:41:13: ( '\\t' | ' ' | '\\r' | '\\n' | '\\f' )+
int cnt3=0;
loop3:
while (true) {
@@ -289,134 +314,14 @@ public class XLexer extends Lexer {
@Override
public void mTokens() throws RecognitionException {
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:1:8: ( T__7 | ID | INTCONST | WS )
int alt4=4;
switch ( input.LA(1) ) {
case 'T':
{
int LA4_1 = input.LA(2);
if ( (LA4_1=='O') ) {
int LA4_5 = input.LA(3);
if ( (LA4_5=='D') ) {
int LA4_6 = input.LA(4);
if ( (LA4_6=='O') ) {
int LA4_7 = input.LA(5);
if ( ((LA4_7 >= '0' && LA4_7 <= '9')||(LA4_7 >= 'A' && LA4_7 <= 'Z')||(LA4_7 >= 'a' && LA4_7 <= 'z')) ) {
alt4=2;
}
else {
alt4=1;
}
}
else {
alt4=2;
}
}
else {
alt4=2;
}
}
else {
alt4=2;
}
}
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
case 'G':
case 'H':
case 'I':
case 'J':
case 'K':
case 'L':
case 'M':
case 'N':
case 'O':
case 'P':
case 'Q':
case 'R':
case 'S':
case 'U':
case 'V':
case 'W':
case 'X':
case 'Y':
case 'Z':
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
case 'g':
case 'h':
case 'i':
case 'j':
case 'k':
case 'l':
case 'm':
case 'n':
case 'o':
case 'p':
case 'q':
case 'r':
case 's':
case 't':
case 'u':
case 'v':
case 'w':
case 'x':
case 'y':
case 'z':
{
alt4=2;
}
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{
alt4=3;
}
break;
case '\t':
case '\n':
case '\f':
case '\r':
case ' ':
{
alt4=4;
}
break;
default:
NoViableAltException nvae =
new NoViableAltException("", 4, 0, input);
throw nvae;
}
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:1:8: ( T__8 | ID | INTCONST | FLOATCONST | WS )
int alt4=5;
alt4 = dfa4.predict(input);
switch (alt4) {
case 1 :
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:1:10: T__7
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:1:10: T__8
{
mT__7();
mT__8();
}
break;
@@ -435,7 +340,14 @@ public class XLexer extends Lexer {
}
break;
case 4 :
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:1:27: WS
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:1:27: FLOATCONST
{
mFLOATCONST();
}
break;
case 5 :
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:1:38: WS
{
mWS();
@@ -446,5 +358,67 @@ public class XLexer extends Lexer {
}
protected DFA4 dfa4 = new DFA4(this);
static final String DFA4_eotS =
"\1\uffff\1\2\1\uffff\1\6\1\uffff\1\2\2\uffff\1\2\1\12\1\uffff";
static final String DFA4_eofS =
"\13\uffff";
static final String DFA4_minS =
"\1\11\1\117\1\uffff\1\56\1\uffff\1\104\2\uffff\1\117\1\60\1\uffff";
static final String DFA4_maxS =
"\1\172\1\117\1\uffff\1\71\1\uffff\1\104\2\uffff\1\117\1\172\1\uffff";
static final String DFA4_acceptS =
"\2\uffff\1\2\1\uffff\1\5\1\uffff\1\3\1\4\2\uffff\1\1";
static final String DFA4_specialS =
"\13\uffff}>";
static final String[] DFA4_transitionS = {
"\2\4\1\uffff\2\4\22\uffff\1\4\17\uffff\12\3\7\uffff\23\2\1\1\6\2\6\uffff"+
"\32\2",
"\1\5",
"",
"\1\7\1\uffff\12\3",
"",
"\1\10",
"",
"",
"\1\11",
"\12\2\7\uffff\32\2\6\uffff\32\2",
""
};
static final short[] DFA4_eot = DFA.unpackEncodedString(DFA4_eotS);
static final short[] DFA4_eof = DFA.unpackEncodedString(DFA4_eofS);
static final char[] DFA4_min = DFA.unpackEncodedStringToUnsignedChars(DFA4_minS);
static final char[] DFA4_max = DFA.unpackEncodedStringToUnsignedChars(DFA4_maxS);
static final short[] DFA4_accept = DFA.unpackEncodedString(DFA4_acceptS);
static final short[] DFA4_special = DFA.unpackEncodedString(DFA4_specialS);
static final short[][] DFA4_transition;
static {
int numStates = DFA4_transitionS.length;
DFA4_transition = new short[numStates][];
for (int i=0; i<numStates; i++) {
DFA4_transition[i] = DFA.unpackEncodedString(DFA4_transitionS[i]);
}
}
protected class DFA4 extends DFA {
public DFA4(BaseRecognizer recognizer) {
this.recognizer = recognizer;
this.decisionNumber = 4;
this.eot = DFA4_eot;
this.eof = DFA4_eof;
this.min = DFA4_min;
this.max = DFA4_max;
this.accept = DFA4_accept;
this.special = DFA4_special;
this.transition = DFA4_transition;
}
@Override
public String getDescription() {
return "1:1: Tokens : ( T__8 | ID | INTCONST | FLOATCONST | WS );";
}
}
}

View File

@@ -1,4 +1,4 @@
// $ANTLR 3.5.2 /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g 2020-05-27 16:02:17
// $ANTLR 3.5.2 /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g 2020-06-03 10:07:22
package de.dhbw.compiler.antlrxparser;
import org.antlr.runtime.*;
@@ -14,13 +14,15 @@ import org.antlr.runtime.tree.*;
@SuppressWarnings("all")
public class XParser extends Parser {
public static final String[] tokenNames = new String[] {
"<invalid>", "<EOR>", "<DOWN>", "<UP>", "ID", "INTCONST", "WS", "'TODO'"
"<invalid>", "<EOR>", "<DOWN>", "<UP>", "FLOATCONST", "ID", "INTCONST",
"WS", "'TODO'"
};
public static final int EOF=-1;
public static final int T__7=7;
public static final int ID=4;
public static final int INTCONST=5;
public static final int WS=6;
public static final int T__8=8;
public static final int FLOATCONST=4;
public static final int ID=5;
public static final int INTCONST=6;
public static final int WS=7;
// delegates
public Parser[] getDelegates() {
@@ -57,7 +59,7 @@ public class XParser extends Parser {
// $ANTLR start "program"
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:42:1: program : 'TODO' ;
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:44:1: program : 'TODO' ;
public final XParser.program_return program() throws RecognitionException {
XParser.program_return retval = new XParser.program_return();
retval.start = input.LT(1);
@@ -69,13 +71,13 @@ public class XParser extends Parser {
CommonTree string_literal1_tree=null;
try {
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:42:8: ( 'TODO' )
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:42:13: 'TODO'
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:44:8: ( 'TODO' )
// /Users/kreis/git/gitea.humenius.me/dhbw-compilerbau/CC-Praxis-Antlr Parser fuer X-Leer/src/de/dhbw/compiler/antlrxparser/X.g:44:13: 'TODO'
{
root_0 = (CommonTree)adaptor.nil();
string_literal1=(Token)match(input,7,FOLLOW_7_in_program256); if (state.failed) return retval;
string_literal1=(Token)match(input,8,FOLLOW_8_in_program272); if (state.failed) return retval;
if ( state.backtracking==0 ) {
string_literal1_tree = (CommonTree)adaptor.create(string_literal1);
adaptor.addChild(root_0, string_literal1_tree);
@@ -106,5 +108,5 @@ public class XParser extends Parser {
public static final BitSet FOLLOW_7_in_program256 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_8_in_program272 = new BitSet(new long[]{0x0000000000000002L});
}