public Start Parse() { Push(0, null); IList ign = null; while(true) { while(Index(lexer.Peek()) == -1) { if(ign == null) { ign = new TypedList(NodeCast.Instance); } ign.Add(lexer.Next()); } if(ign != null) { ignoredTokens.SetIn(lexer.Peek(), ign); ign = null; } last_pos = lexer.Peek().Pos; last_line = lexer.Peek().Line; last_token = lexer.Peek(); int index = Index(lexer.Peek()); action[0] = actionTable[State()][0][1]; action[1] = actionTable[State()][0][2]; int low = 1; int high = actionTable[State()].Length - 1; while(low <= high) { int middle = (low + high) / 2; if(index < actionTable[State()][middle][0]) { high = middle - 1; } else if(index > actionTable[State()][middle][0]) { low = middle + 1; } else { action[0] = actionTable[State()][middle][1]; action[1] = actionTable[State()][middle][2]; break; } } switch(action[0]) { case SHIFT: { ArrayList list = new ArrayList(); list.Add(lexer.Next()); Push(action[1], list); last_shift = action[1]; } break; case REDUCE: switch(action[1]) { case 0: { ArrayList list = New0(); Push(GoTo(0), list); } break; case 1: { ArrayList list = New1(); Push(GoTo(1), list); } break; case 2: { ArrayList list = New2(); Push(GoTo(1), list); } break; case 3: { ArrayList list = New3(); Push(GoTo(2), list); } break; case 4: { ArrayList list = New4(); Push(GoTo(2), list); } break; case 5: { ArrayList list = New5(); Push(GoTo(2), list); } break; case 6: { ArrayList list = New6(); Push(GoTo(2), list); } break; case 7: { ArrayList list = New7(); Push(GoTo(2), list); } break; case 8: { ArrayList list = New8(); Push(GoTo(2), list); } break; case 9: { ArrayList list = New9(); Push(GoTo(3), list); } break; case 10: { ArrayList list = New10(); Push(GoTo(3), list); } break; } break; case ACCEPT: { EOF node2 = (EOF) lexer.Next(); PDocument node1 = (PDocument) ((ArrayList)Pop())[0]; Start node = new Start(node1, node2); return node; } case ERROR: throw new ParserException(last_token, "[" + last_line + "," + last_pos + "] " + errorMessages[errors[action[1]]]); } } }
public ParserException(Token token, String message) : base(message) { this.token = token; }
static Sexp terminal(SexpType type, Token t) { return new Sexp(type, t.Text, null, t.Line, t.Pos); }