Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
 protected abstract ParserAction Action(ParseState state, Token token, out Production production, out ParseState nextState);
Exemplo n.º 4
0
 public ParseTreeNode(ParseTreeNode parent, Token token)
 {
     this.Parent = parent;
     this.token = token;
 }
Exemplo n.º 5
0
 public ParseTreeNode(Token token)
 {
     this.token = token;
 }
Exemplo n.º 6
0
 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);
 }