javacc-7.0.1.test.tmp.GUIParsing.ParserVersion.CalcInputParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javacc Show documentation
Show all versions of javacc Show documentation
JavaCC is a parser/scanner generator for Java.
/* CalcInputParser.java */
/* Generated By:JavaCC: Do not edit this line. CalcInputParser.java */
public class CalcInputParser implements CalcInputParserConstants {
static final public void Input() throws ParseException {double larg = 0.0;
double rarg;
label_1:
while (true) {
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case EQ:
case ADD:
case SUB:
case MUL:
case DIV:
case DIGIT:
case DOT:{
;
break;
}
default:
jj_la1[0] = jj_gen;
break label_1;
}
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case DIGIT:
case DOT:{
larg = Number();
CalcGUI.print(larg);
break;
}
default:
jj_la1[1] = jj_gen;
;
}
label_2:
while (true) {
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case ADD:
case SUB:
case MUL:
case DIV:{
;
break;
}
default:
jj_la1[2] = jj_gen;
break label_2;
}
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case ADD:{
jj_consume_token(ADD);
rarg = Number();
larg = larg + rarg;
CalcGUI.print(larg);
break;
}
case SUB:{
jj_consume_token(SUB);
rarg = Number();
larg = larg - rarg;
CalcGUI.print(larg);
break;
}
case MUL:{
jj_consume_token(MUL);
rarg = Number();
larg = larg * rarg;
CalcGUI.print(larg);
break;
}
case DIV:{
jj_consume_token(DIV);
rarg = Number();
larg = (rarg==0) ? Float.POSITIVE_INFINITY : (larg / rarg);
CalcGUI.print(larg);
break;
}
default:
jj_la1[3] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
jj_consume_token(EQ);
}
}
static final public double Number() throws ParseException {Token t;
String image = "";
double value = 0.0;
double decimalPlace = 1.0;
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case DIGIT:{
label_3:
while (true) {
t = jj_consume_token(DIGIT);
image += t.image;
value = value*10 + Integer.parseInt(t.image);
CalcGUI.print(image);
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case DIGIT:{
;
break;
}
default:
jj_la1[4] = jj_gen;
break label_3;
}
}
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case DOT:{
jj_consume_token(DOT);
image += ".";
CalcGUI.print(image);
label_4:
while (true) {
t = jj_consume_token(DIGIT);
image += t.image;
decimalPlace *= 0.1;
value = value + Integer.parseInt(t.image)*decimalPlace;
CalcGUI.print(image);
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case DIGIT:{
;
break;
}
default:
jj_la1[5] = jj_gen;
break label_4;
}
}
break;
}
default:
jj_la1[6] = jj_gen;
;
}
{if ("" != null) return value;}
break;
}
case DOT:{
jj_consume_token(DOT);
image = "0.";
CalcGUI.print(image);
label_5:
while (true) {
t = jj_consume_token(DIGIT);
image += t.image;
decimalPlace *= 0.1;
value = value + Integer.parseInt(t.image)*decimalPlace;
CalcGUI.print(image);
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case DIGIT:{
;
break;
}
default:
jj_la1[7] = jj_gen;
break label_5;
}
}
{if ("" != null) return value;}
break;
}
default:
jj_la1[8] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
static private boolean jj_initialized_once = false;
/** User defined Token Manager. */
static public TokenManager token_source;
/** Current token. */
static public Token token;
/** Next token. */
static public Token jj_nt;
static private int jj_ntk;
static private int jj_gen;
static final private int[] jj_la1 = new int[9];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
}
private static void jj_la1_init_0() {
jj_la1_0 = new int[] {0xfe,0xc0,0x3c,0x3c,0x40,0x40,0x80,0x40,0xc0,};
}
/** Constructor with user supplied Token Manager. */
public CalcInputParser(TokenManager tm) {
if (jj_initialized_once) {
System.out.println("ERROR: Second call to constructor of static parser. ");
System.out.println(" You must either use ReInit() or set the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
}
jj_initialized_once = true;
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 9; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
public void ReInit(TokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 9; i++) jj_la1[i] = -1;
}
static private Token jj_consume_token(int kind) throws ParseException {
Token oldToken;
if ((oldToken = token).next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
if (token.kind == kind) {
jj_gen++;
return token;
}
token = oldToken;
jj_kind = kind;
throw generateParseException();
}
/** Get the next Token. */
static final public Token getNextToken() {
if (token.next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
jj_gen++;
return token;
}
/** Get the specific Token. */
static final public Token getToken(int index) {
Token t = token;
for (int i = 0; i < index; i++) {
if (t.next != null) t = t.next;
else t = t.next = token_source.getNextToken();
}
return t;
}
static private int jj_ntk_f() {
if ((jj_nt=token.next) == null)
return (jj_ntk = (token.next=token_source.getNextToken()).kind);
else
return (jj_ntk = jj_nt.kind);
}
static private java.util.List jj_expentries = new java.util.ArrayList();
static private int[] jj_expentry;
static private int jj_kind = -1;
/** Generate ParseException. */
static public ParseException generateParseException() {
jj_expentries.clear();
boolean[] la1tokens = new boolean[8];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 9; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<