public async Task <ParseResult> Parse(LexResult lex) { return(await Task <ParseResult> .Run(() => { ParseContext context = new ParseContext(prefixRules, infixRules, lex); // start parsing! while (context.TokenStream.Count > 0) { try { context.Nodes.Add(context.ParseStatement()); } catch (CompileException e) { context.Errors.Add(e.Error); } } return new ParseResult(context.Nodes.ToArray(), context.Errors.ToArray()); })); }
public ParseContext(Dictionary <TokenType, IPrefixRule> prefixRules, Dictionary <TokenType, IInfixRule> infixRules, LexResult lex) { this.prefixRules = prefixRules; this.infixRules = infixRules; TokenStream = new List <Token>(lex.Tokens); Nodes = new List <ASTNode>(); Errors = new List <CompileError>(); eof = TokenStream[TokenStream.Count - 1]; }