/* Generated By:JavaCC: Do not edit this line. TheParser.java */ package gen; import edu.neu.ccs.demeterf.lib.*; import edu.neu.ccs.demeterf.*; import edu.neu.ccs.demeterf.Fields; import edu.neu.ccs.demeterf.lib.ident; import edu.neu.ccs.demeterf.lib.verbatim; public class TheParser implements TheParserConstants { public static String unescape(String str){ String retval = ""; int index = 0; char ch, ch1; int ordinal = 0; while (index < str.length()) { if(str.charAt(index) != '\\') { retval += str.charAt(index++); continue; } ch = str.charAt(++index); if(ch == 'b') { retval += '\b'; index++; continue; } if(ch == 't') { retval += '\t'; index++; continue; } if(ch == 'n') { retval += '\n'; index++; continue; } if(ch == 'f') { retval += '\f'; index++; continue; } if(ch == 'r') { retval += '\r'; index++; continue; } if(ch == '"') { retval += '\"'; index++; continue; } if(ch == '\'') { retval += '\''; index++; continue; } if(ch == '\\') { retval += '\\'; index++; continue; } if(ch >= '0' && ch <= '7'){ ordinal = ((int)ch) - ((int)'0'); index++; ch1 = str.charAt(index); if(ch1 >= '0' && ch1 <= '7'){ ordinal = ordinal*8 + ((int)ch1) - ((int)'0'); index++; ch1 = str.charAt(index); if(ch <= '3' && ch1 >= '0' && ch1 <= '7'){ ordinal = ordinal*8 + ((int)ch1) - ((int)'0'); index++; } } retval += (char)ordinal; continue; } if(ch == 'u'){ ordinal = 0; for(int i = 0; i < 4; i++){ index++; ch = str.charAt(index); ordinal = ordinal*16+hexval(ch); } index++; retval += (char)ordinal; continue; } } return retval; } static int hexval(char c){ int r = "0123456789ABCDEF".indexOf(Character.toUpperCase(c)); if(r >= 0)return r; throw new RuntimeException(" ** Bad Escaped Character"); } final public byte parse_byte() throws ParseException { int i; i = parse_int(); {if (true) return (byte)i;} throw new Error("Missing return statement in function"); } final public Byte parse_Byte() throws ParseException { byte b; b = parse_byte(); {if (true) return b;} throw new Error("Missing return statement in function"); } final public short parse_short() throws ParseException { int i; i = parse_int(); {if (true) return (short)i;} throw new Error("Missing return statement in function"); } final public Short parse_Short() throws ParseException { short s; s = parse_short(); {if (true) return s;} throw new Error("Missing return statement in function"); } final public int parse_int() throws ParseException { Token t; t = jj_consume_token(INT); if(t.image.length() > 1 && Character.toLowerCase(t.image.charAt(1)) == 'x') {if (true) return Integer.parseInt(t.image.substring(2), 16);} {if (true) return Integer.parseInt(t.image);} throw new Error("Missing return statement in function"); } final public Integer parse_Integer() throws ParseException { int i; i = parse_int(); {if (true) return i;} throw new Error("Missing return statement in function"); } final public long parse_long() throws ParseException { Token t; t = jj_consume_token(INT); if(t.image.length() > 1 && Character.toLowerCase(t.image.charAt(1)) == 'x') {if (true) return Long.parseLong(t.image.substring(2), 16);} {if (true) return Long.parseLong(t.image);} throw new Error("Missing return statement in function"); } final public Long parse_Long() throws ParseException { long l; l = parse_long(); {if (true) return l;} throw new Error("Missing return statement in function"); } final public double parse_double() throws ParseException { Token t; t = jj_consume_token(DOUBLE); {if (true) return Double.parseDouble(t.image);} throw new Error("Missing return statement in function"); } final public Double parse_Double() throws ParseException { double d; d = parse_double(); {if (true) return d;} throw new Error("Missing return statement in function"); } final public float parse_float() throws ParseException { Token t; t = jj_consume_token(DOUBLE); {if (true) return Float.parseFloat(t.image);} throw new Error("Missing return statement in function"); } final public Float parse_Float() throws ParseException { float f; f = parse_float(); {if (true) return f;} throw new Error("Missing return statement in function"); } final public String parse_String() throws ParseException { Token t; t = jj_consume_token(STRING); {if (true) return unescape(t.image.substring(1,t.image.length()-1));} throw new Error("Missing return statement in function"); } final public boolean parse_boolean() throws ParseException { Token t; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case TRUE: t = jj_consume_token(TRUE); {if (true) return true;} break; case FALSE: t = jj_consume_token(FALSE); {if (true) return false;} break; default: jj_la1[0] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } final public Boolean parse_Boolean() throws ParseException { boolean b; b = parse_boolean(); {if (true) return b;} throw new Error("Missing return statement in function"); } final public char parse_char() throws ParseException { Token t; t = jj_consume_token(CHAR); {if (true) return unescape(t.image.substring(1,t.image.length()-1)).charAt(0);} throw new Error("Missing return statement in function"); } final public Character parse_Character() throws ParseException { char c; c = parse_char(); {if (true) return c;} throw new Error("Missing return statement in function"); } final public ident parse_ident() throws ParseException { Token t; t = jj_consume_token(IDENT); {if (true) return new ident(t.image);} throw new Error("Missing return statement in function"); } final public verbatim parse_verbatim() throws ParseException { Token t; t = jj_consume_token(TEXT); {if (true) return new verbatim(t.image.substring(2,t.image.length()-2));} throw new Error("Missing return statement in function"); } final public DT parse_DT() throws ParseException { DT sup = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 1: sup = parse_Simple(); {if (true) return sup;} break; case 2: sup = parse_Compound(); {if (true) return sup;} break; default: jj_la1[1] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } final public Simple parse_Simple() throws ParseException { HSR highest_safe_rung; jj_consume_token(1); highest_safe_rung = parse_HSR(); {if (true) return new Simple(highest_safe_rung);} throw new Error("Missing return statement in function"); } final public HSR parse_HSR() throws ParseException { int i; i = parse_int(); {if (true) return new HSR(i);} throw new Error("Missing return statement in function"); } final public Compound parse_Compound() throws ParseException { Rung question; DT yes; DT no; jj_consume_token(2); question = parse_Rung(); jj_consume_token(3); yes = parse_DT(); jj_consume_token(4); no = parse_DT(); jj_consume_token(5); {if (true) return new Compound(question,yes,no);} throw new Error("Missing return statement in function"); } final public Rung parse_Rung() throws ParseException { int i; i = parse_int(); {if (true) return new Rung(i);} throw new Error("Missing return statement in function"); } /** Generated Token Manager. */ public TheParserTokenManager token_source; SimpleCharStream jj_input_stream; /** Current token. */ public Token token; /** Next token. */ public Token jj_nt; private int jj_ntk; private int jj_gen; final private int[] jj_la1 = new int[2]; static private int[] jj_la1_0; static { jj_la1_init_0(); } private static void jj_la1_init_0() { jj_la1_0 = new int[] {0x30000,0x6,}; } /** Constructor with InputStream. */ public TheParser(java.io.InputStream stream) { this(stream, null); } /** Constructor with InputStream and supplied encoding */ public TheParser(java.io.InputStream stream, String encoding) { try { jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } token_source = new TheParserTokenManager(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 2; i++) jj_la1[i] = -1; } /** Reinitialise. */ public void ReInit(java.io.InputStream stream) { ReInit(stream, null); } /** Reinitialise. */ public void ReInit(java.io.InputStream stream, String encoding) { try { jj_input_stream.ReInit(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); } token_source.ReInit(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 2; i++) jj_la1[i] = -1; } /** Constructor. */ public TheParser(java.io.Reader stream) { jj_input_stream = new SimpleCharStream(stream, 1, 1); token_source = new TheParserTokenManager(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 2; i++) jj_la1[i] = -1; } /** Reinitialise. */ public void ReInit(java.io.Reader stream) { jj_input_stream.ReInit(stream, 1, 1); token_source.ReInit(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 2; i++) jj_la1[i] = -1; } /** Constructor with generated Token Manager. */ public TheParser(TheParserTokenManager tm) { token_source = tm; token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 2; i++) jj_la1[i] = -1; } /** Reinitialise. */ public void ReInit(TheParserTokenManager tm) { token_source = tm; token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 2; i++) jj_la1[i] = -1; } 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. */ 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. */ 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; } private int jj_ntk() { if ((jj_nt=token.next) == null) return (jj_ntk = (token.next=token_source.getNextToken()).kind); else return (jj_ntk = jj_nt.kind); } private java.util.List jj_expentries = new java.util.ArrayList(); private int[] jj_expentry; private int jj_kind = -1; /** Generate ParseException. */ public ParseException generateParseException() { jj_expentries.clear(); boolean[] la1tokens = new boolean[22]; if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; } for (int i = 0; i < 2; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1<