Exemplo n.º 1
0
        public ParseResult Parse(Lexer lexer, ParserState initialState)
        {
            var context = new ParserContext(this, Automaton.Grammar, lexer);
            context.CurrentState = initialState;
            context.ParserStack.Push(new ParserNode(context, new GrammarDefinition("init"))
            {
                State = initialState
            });

            ReadNextToken(context);
            context.CurrentNode = new ParserNode(context, Automaton.Grammar.ToElement(lexer.Current.GetTokenCode()), lexer.Current);

            while (lexer.Current != null && context.Root == null && context.CurrentState != null)
            {
                // If no input and no default action (e.g. a grammar reduction),
                // that means we have to read the next token.
                if (context.CurrentNode == null && context.CurrentState.DefaultAction == null)
                    ReadNextToken(context);

                var action = GetNextAction(context);
                action.Execute(context);
            }

            lexer.SpecialBag.InsertNodesIntoAstNode(context.Root.Result);

            return ParseResult.FromContext(context);
        }
Exemplo n.º 2
0
 public AstTokenStream(Lexer lexer)
 {
     if (lexer == null)
         throw new ArgumentNullException(nameof(lexer));
     Lexer = lexer;
     Advance();
 }
Exemplo n.º 3
0
 public ParserContext(AutomatonSourceParser parser, Grammar grammar, Lexer lexer)
 {
     Parser = parser;
     Grammar = grammar;
     Lexer = lexer;
     ParserStack = new Stack<ParserNode>();
     SyntaxErrors = new List<SyntaxError>();
 }
Exemplo n.º 4
0
 public ParseResult Parse(Lexer lexer, GrammarDefinition rootDefinition)
 {
     return Parse(lexer, Automaton.InitialStates[rootDefinition]);
 }
Exemplo n.º 5
0
 public override ParseResult Parse(Lexer lexer)
 {
     return Parse(lexer, Automaton.DefaultInitialState);
 }
Exemplo n.º 6
0
 public abstract ParseResult Parse(Lexer lexer);