protected override ParserAction Action(ParseState state, Token token, out Production production, out ParseState nextState) { var lr0 = base.Action(state, token, out production, out nextState); if (token != null && lr0 == ParserAction.Reduce && !Grammar.GetFollowSet(production.Head).Contains(token.Terminal)) return ParserAction.Error; return lr0; }
protected override ParserAction Action(ParseState state, Token token, out Production production, out ParseState nextState) { bool shift = false; bool reduce = false; if (token == null && state.AcceptingState) { production = default(Production); nextState = null; return ParserAction.Accept; } if (token != null) { nextState = automaton[state, token.Terminal]; if (nextState != null) { production = default(Production); shift = true; } } else nextState = null; if (state.Count() == 1 && state.First().Position == state.First().Production.Body.Length) { nextState = null; production = state.First().Production; reduce = true; } else production = default(Production); if (shift && reduce) throw new ParseException(String.Format("Shift/Reduce conflict between shift {0} and reduce {1}", nextState, production)); else if (shift) return ParserAction.Shift; else if (reduce) return ParserAction.Reduce; else if (token == null) throw new ParseException("Unexpected EOF"); throw new ParseException(String.Format("Unexpected {0} at line {1} column {2}", token.Value, token.Line, token.Column)); }
protected abstract ParserAction Action(ParseState state, Token token, out Production production, out ParseState nextState);
public ParseTreeNode(ParseTreeNode parent, Token token) { this.Parent = parent; this.token = token; }
public ParseTreeNode(Token token) { this.token = token; }
private void AssertToken(Token token, string name, int line, int column) { Assert.AreEqual(name, token.Terminal.Name); Assert.AreEqual(line, token.Line); Assert.AreEqual(column, token.Column); }