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); }
public AstTokenStream(Lexer lexer) { if (lexer == null) throw new ArgumentNullException(nameof(lexer)); Lexer = lexer; Advance(); }
public ParserContext(AutomatonSourceParser parser, Grammar grammar, Lexer lexer) { Parser = parser; Grammar = grammar; Lexer = lexer; ParserStack = new Stack<ParserNode>(); SyntaxErrors = new List<SyntaxError>(); }
public ParseResult Parse(Lexer lexer, GrammarDefinition rootDefinition) { return Parse(lexer, Automaton.InitialStates[rootDefinition]); }
public override ParseResult Parse(Lexer lexer) { return Parse(lexer, Automaton.DefaultInitialState); }
public abstract ParseResult Parse(Lexer lexer);