/* Generated By:JavaCC: Do not edit this line. Parser.java */ import java.io.*; import edu.neu.ccs.demeterf.*; import edu.neu.ccs.demeterf.util.Util; import edu.neu.ccs.demeterf.control.*; import edu.neu.ccs.demeter.*; public class Parser implements ParserConstants { // oit is uugly. Why isn't there a Character.valueOf(String)? static char unescapifyChar(String s) { char c = s.charAt(0); if (c == '\\') { switch (s.charAt(1)) { case 'n': c = '\n'; break; case 't': c = '\t'; break; case 'b': c = '\b'; break; case 'r': c = '\r'; break; case 'f': c = '\f'; break; case '\\': c = '\\'; break; case '\'': c = '\''; break; case '\"': c = '\"'; break; default: c = (char) Integer.parseInt(s.substring(1, s.length()), 8); break; } } return c; } // Even uglier... static String unescapify(String s) { char str[] = new char[s.length()]; int i = 0, o = 0; while (i < s.length()) { char c = s.charAt(i++); if (c == '\\') { int j = i + 1; while (j < s.length() && Character.digit(s.charAt(j), 8) != -1) { j++; } c = unescapifyChar(s.substring(i-1, j)); i = j; } str[o++] = c; } return String.valueOf(str, 0, o); } final public Main _Main() throws ParseException { Main it = null; Exp _e; it=new Main(); _e = _Exp(); it.set_e(_e); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Exp _Exp() throws ParseException { Exp it = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 5: case IDENTIFIER: it = _Var(); break; case DECIMAL_LITERAL: case HEX_LITERAL: case OCTAL_LITERAL: case FLOATING_POINT_LITERAL: it = _Num(); break; case 9: it = _If(); break; case 4: it = _Lambda(); break; case 2: it = _Call(); break; case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: it = _Op(); break; case 7: case 8: it = _Bool(); break; case 1: it = _LetRec(); break; default: jj_la1[0] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return it;} throw new Error("Missing return statement in function"); } final public void common_Exp(Exp it) throws ParseException { } final public LetRec _LetRec() throws ParseException { LetRec it = null; Arg _bind; Exp _e; Exp _body; it=new LetRec(); jj_consume_token(1); jj_consume_token(2); _bind = _Arg(); it.set_bind(_bind); _e = _Exp(); it.set_e(_e); jj_consume_token(3); _body = _Exp(); it.set_body(_body); jj_consume_token(3); common_Exp(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Lambda _Lambda() throws ParseException { Lambda it = null; Arg _formal; Exp _body; it=new Lambda(); jj_consume_token(4); jj_consume_token(2); _formal = _Arg(); it.set_formal(_formal); jj_consume_token(3); _body = _Exp(); it.set_body(_body); jj_consume_token(3); common_Exp(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Var _Var() throws ParseException { Var it = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IDENTIFIER: it = _Sym(); break; case 5: it = _Addr(); break; default: jj_la1[1] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return it;} throw new Error("Missing return statement in function"); } final public void common_Var(Var it) throws ParseException { common_Exp(it); } final public Sym _Sym() throws ParseException { Sym it = null; Ident _name; it=new Sym(); _name = _Ident(); it.set_name(_name); common_Var(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Addr _Addr() throws ParseException { Addr it = null; Integer _offset; it=new Addr(); jj_consume_token(5); _offset = _Integer(); it.set_offset(_offset); jj_consume_token(6); common_Var(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Arg _Arg() throws ParseException { Arg it = null; Type _type; Sym _sym; it=new Arg(); _type = _Type(); it.set_type(_type); _sym = _Sym(); it.set_sym(_sym); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Num _Num() throws ParseException { Num it = null; Integer _value; it=new Num(); _value = _Integer(); it.set_value(_value); common_Exp(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Bool _Bool() throws ParseException { Bool it = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 7: it = _True(); break; case 8: it = _False(); break; default: jj_la1[2] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return it;} throw new Error("Missing return statement in function"); } final public void common_Bool(Bool it) throws ParseException { common_Exp(it); } final public True _True() throws ParseException { True it = null; it=new True(); jj_consume_token(7); common_Bool(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public False _False() throws ParseException { False it = null; it=new False(); jj_consume_token(8); common_Bool(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public If _If() throws ParseException { If it = null; Exp _cond; Exp _then; Exp _otherwise; it=new If(); jj_consume_token(9); _cond = _Exp(); it.set_cond(_cond); _then = _Exp(); it.set_then(_then); _otherwise = _Exp(); it.set_otherwise(_otherwise); jj_consume_token(3); common_Exp(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Call _Call() throws ParseException { Call it = null; Exp _proc; ExpList _args; it=new Call(); jj_consume_token(2); _proc = _Exp(); it.set_proc(_proc); _args = _ExpList(); it.set_args(_args); jj_consume_token(3); common_Exp(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Op _Op() throws ParseException { Op it = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 10: it = _Plus(); break; case 11: it = _Minus(); break; case 13: it = _Mult(); break; case 12: it = _Div(); break; case 14: it = _Less(); break; case 15: it = _Greater(); break; case 16: it = _Or(); break; case 17: it = _And(); break; case 18: it = _Eq(); break; case 19: it = _Print(); break; default: jj_la1[3] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return it;} throw new Error("Missing return statement in function"); } final public void common_Op(Op it) throws ParseException { common_Exp(it); } final public Plus _Plus() throws ParseException { Plus it = null; it=new Plus(); jj_consume_token(10); common_Op(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Minus _Minus() throws ParseException { Minus it = null; it=new Minus(); jj_consume_token(11); common_Op(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Div _Div() throws ParseException { Div it = null; it=new Div(); jj_consume_token(12); common_Op(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Mult _Mult() throws ParseException { Mult it = null; it=new Mult(); jj_consume_token(13); common_Op(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Less _Less() throws ParseException { Less it = null; it=new Less(); jj_consume_token(14); common_Op(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Greater _Greater() throws ParseException { Greater it = null; it=new Greater(); jj_consume_token(15); common_Op(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Or _Or() throws ParseException { Or it = null; it=new Or(); jj_consume_token(16); common_Op(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public And _And() throws ParseException { And it = null; it=new And(); jj_consume_token(17); common_Op(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Eq _Eq() throws ParseException { Eq it = null; it=new Eq(); jj_consume_token(18); common_Op(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Print _Print() throws ParseException { Print it = null; Type _type; it=new Print(); jj_consume_token(19); _type = _Type(); it.set_type(_type); jj_consume_token(15); common_Op(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public Type _Type() throws ParseException { Type it = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 20: it = _BoolT(); break; case 21: it = _NumT(); break; case 2: it = _FuncT(); break; default: jj_la1[4] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return it;} throw new Error("Missing return statement in function"); } final public void common_Type(Type it) throws ParseException { } final public BoolT _BoolT() throws ParseException { BoolT it = null; it=new BoolT(); jj_consume_token(20); common_Type(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public NumT _NumT() throws ParseException { NumT it = null; it=new NumT(); jj_consume_token(21); common_Type(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public FuncT _FuncT() throws ParseException { FuncT it = null; TypeList _args; Type _ret; it=new FuncT(); jj_consume_token(2); _args = _TypeList(); it.set_args(_args); jj_consume_token(22); _ret = _Type(); it.set_ret(_ret); jj_consume_token(3); common_Type(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public SymList _SymList() throws ParseException { SymList it = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case IDENTIFIER: it = _SymCons(); break; default: jj_la1[5] = jj_gen; it = _SymEmpty(); } {if (true) return it;} throw new Error("Missing return statement in function"); } final public void common_SymList(SymList it) throws ParseException { } final public SymCons _SymCons() throws ParseException { SymCons it = null; Sym _first; SymList _rest; it=new SymCons(); _first = _Sym(); it.set_first(_first); _rest = _SymList(); it.set_rest(_rest); common_SymList(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public SymEmpty _SymEmpty() throws ParseException { SymEmpty it = null; it=new SymEmpty(); common_SymList(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public ArgList _ArgList() throws ParseException { ArgList it = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 2: it = _ArgCons(); break; default: jj_la1[6] = jj_gen; it = _ArgEmpty(); } {if (true) return it;} throw new Error("Missing return statement in function"); } final public void common_ArgList(ArgList it) throws ParseException { } final public ArgCons _ArgCons() throws ParseException { ArgCons it = null; Arg _first; ArgList _rest; it=new ArgCons(); jj_consume_token(2); _first = _Arg(); it.set_first(_first); jj_consume_token(3); _rest = _ArgList(); it.set_rest(_rest); common_ArgList(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public ArgEmpty _ArgEmpty() throws ParseException { ArgEmpty it = null; it=new ArgEmpty(); common_ArgList(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public ExpList _ExpList() throws ParseException { ExpList it = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 1: case 2: case 4: case 5: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case DECIMAL_LITERAL: case HEX_LITERAL: case OCTAL_LITERAL: case FLOATING_POINT_LITERAL: case IDENTIFIER: it = _ExpCons(); break; default: jj_la1[7] = jj_gen; it = _ExpEmpty(); } {if (true) return it;} throw new Error("Missing return statement in function"); } final public void common_ExpList(ExpList it) throws ParseException { } final public ExpCons _ExpCons() throws ParseException { ExpCons it = null; Exp _first; ExpList _rest; it=new ExpCons(); _first = _Exp(); it.set_first(_first); _rest = _ExpList(); it.set_rest(_rest); common_ExpList(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public ExpEmpty _ExpEmpty() throws ParseException { ExpEmpty it = null; it=new ExpEmpty(); common_ExpList(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public TypeList _TypeList() throws ParseException { TypeList it = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case 2: case 20: case 21: it = _TypeCons(); break; default: jj_la1[8] = jj_gen; it = _TypeEmpty(); } {if (true) return it;} throw new Error("Missing return statement in function"); } final public void common_TypeList(TypeList it) throws ParseException { } final public TypeCons _TypeCons() throws ParseException { TypeCons it = null; Type _first; TypeList _rest; it=new TypeCons(); _first = _Type(); it.set_first(_first); _rest = _TypeList(); it.set_rest(_rest); common_TypeList(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public TypeEmpty _TypeEmpty() throws ParseException { TypeEmpty it = null; it=new TypeEmpty(); common_TypeList(it); {if (true) return it;} throw new Error("Missing return statement in function"); } final public boolean _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[9] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } final public char _char() throws ParseException { Token t; t = jj_consume_token(CHARACTER_LITERAL); String s = t.image; {if (true) return unescapifyChar(s.substring(1, s.length()-1));} throw new Error("Missing return statement in function"); } final public byte _byte() throws ParseException { int i; i = _int(); {if (true) return (byte) i;} throw new Error("Missing return statement in function"); } final public short _short() throws ParseException { int i; i = _int(); {if (true) return (short) i;} throw new Error("Missing return statement in function"); } final public int _int() throws ParseException { Number num; num = _Number(); {if (true) return num.intValue();} throw new Error("Missing return statement in function"); } final public long _long() throws ParseException { Number num; num = _Number(); {if (true) return num.longValue();} throw new Error("Missing return statement in function"); } final public float _float() throws ParseException { Number num; num = _Number(); {if (true) return num.floatValue();} throw new Error("Missing return statement in function"); } final public double _double() throws ParseException { Number num; num = _Number(); {if (true) return num.doubleValue();} throw new Error("Missing return statement in function"); } final public Boolean _Boolean() throws ParseException { Token t; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case TRUE: t = jj_consume_token(TRUE); {if (true) return Boolean.TRUE;} break; case FALSE: t = jj_consume_token(FALSE); {if (true) return Boolean.FALSE;} break; default: jj_la1[10] = jj_gen; jj_consume_token(-1); throw new ParseException(); } throw new Error("Missing return statement in function"); } final public Character _Character() throws ParseException { char c; c = _char(); {if (true) return new Character(c);} throw new Error("Missing return statement in function"); } final public Integer _Integer() throws ParseException { int i; i = _int(); {if (true) return new Integer(i);} throw new Error("Missing return statement in function"); } final public Long _Long() throws ParseException { long l; l = _long(); {if (true) return new Long(l);} throw new Error("Missing return statement in function"); } final public Float _Float() throws ParseException { float f; f = _float(); {if (true) return new Float(f);} throw new Error("Missing return statement in function"); } final public Double _Double() throws ParseException { double d; d = _double(); {if (true) return new Double(d);} throw new Error("Missing return statement in function"); } final public Number _Number() throws ParseException { Token t; String s = null; int radix = 0; Number num = null; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case DECIMAL_LITERAL: case HEX_LITERAL: case OCTAL_LITERAL: switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case DECIMAL_LITERAL: t = jj_consume_token(DECIMAL_LITERAL); s = t.image; radix = 10; break; case HEX_LITERAL: t = jj_consume_token(HEX_LITERAL); // Strip off the "0x". s = t.image.substring(2, t.image.length()); radix = 16; break; case OCTAL_LITERAL: t = jj_consume_token(OCTAL_LITERAL); s = t.image; radix = 8; break; default: jj_la1[11] = jj_gen; jj_consume_token(-1); throw new ParseException(); } switch (s.charAt(s.length()-1)) { case 'l': case 'L': s = s.substring(0, s.length()-1); num = new Long(new java.math.BigInteger(s, radix).longValue()); break; default: num = new Integer(new java.math.BigInteger(s, radix).intValue()); break; } break; case FLOATING_POINT_LITERAL: t = jj_consume_token(FLOATING_POINT_LITERAL); s = t.image; switch (s.charAt(s.length()-1)) { case 'd': case 'D': num = Double.valueOf(s.substring(0, s.length()-1)); break; case 'f': case 'F': num = Float.valueOf(s.substring(0, s.length()-1)); break; default: num = Float.valueOf(s); break; } break; default: jj_la1[12] = jj_gen; jj_consume_token(-1); throw new ParseException(); } {if (true) return num;} throw new Error("Missing return statement in function"); } final public String _String() throws ParseException { Token t; t = jj_consume_token(STRING_LITERAL); String s = t.image; {if (true) return unescapify(s.substring(1, s.length()-1));} throw new Error("Missing return statement in function"); } final public StringBuffer _StringBuffer() throws ParseException { String s; s = _String(); {if (true) return new StringBuffer(s);} throw new Error("Missing return statement in function"); } final public Ident _Ident() throws ParseException { Token t; t = jj_consume_token(IDENTIFIER); {if (true) return new Ident(t.image);} throw new Error("Missing return statement in function"); } final public Text _Text() throws ParseException { Token t; t = jj_consume_token(TEXT_LITERAL); String s = t.image; {if (true) return new Text(s.substring(2, s.length()-2));} throw new Error("Missing return statement in function"); } final public Line _Line() throws ParseException { Token t; token_source.SwitchTo(1); t = jj_consume_token(LINE); {if (true) return new Line(t.image);} throw new Error("Missing return statement in function"); } final public Word _Word() throws ParseException { Token t; token_source.SwitchTo(2); t = jj_consume_token(WORD); {if (true) return new Word(t.image);} throw new Error("Missing return statement in function"); } public ParserTokenManager token_source; ASCII_UCodeESC_CharStream jj_input_stream; public Token token, jj_nt; private int jj_ntk; private int jj_gen; final private int[] jj_la1 = new int[13]; final private int[] jj_la1_0 = {0xe00fffb6,0x20,0x180,0xffc00,0x300004,0x0,0x4,0xe00fffb6,0x300004,0x0,0x0,0xe0000000,0xe0000000,}; final private int[] jj_la1_1 = {0x81,0x80,0x0,0x0,0x0,0x80,0x0,0x81,0x0,0x60,0x60,0x0,0x1,}; public Parser(java.io.InputStream stream) { jj_input_stream = new ASCII_UCodeESC_CharStream(stream, 1, 1); token_source = new ParserTokenManager(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 13; i++) jj_la1[i] = -1; } public void ReInit(java.io.InputStream 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 < 13; i++) jj_la1[i] = -1; } public Parser(java.io.Reader stream) { jj_input_stream = new ASCII_UCodeESC_CharStream(stream, 1, 1); token_source = new ParserTokenManager(jj_input_stream); token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 13; i++) jj_la1[i] = -1; } 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 < 13; i++) jj_la1[i] = -1; } public Parser(ParserTokenManager tm) { token_source = tm; token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 13; i++) jj_la1[i] = -1; } public void ReInit(ParserTokenManager tm) { token_source = tm; token = new Token(); jj_ntk = -1; jj_gen = 0; for (int i = 0; i < 13; i++) jj_la1[i] = -1; } final 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(); } 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; } 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; } final 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.Vector jj_expentries = new java.util.Vector(); private int[] jj_expentry; private int jj_kind = -1; final public ParseException generateParseException() { jj_expentries.removeAllElements(); boolean[] la1tokens = new boolean[48]; for (int i = 0; i < 48; i++) { la1tokens[i] = false; } if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; } for (int i = 0; i < 13; i++) { if (jj_la1[i] == jj_gen) { for (int j = 0; j < 32; j++) { if ((jj_la1_0[i] & (1<