public static Lexem Consume <TToken>(this TokenWalker walker)
            where TToken : IToken
        {
            var lexem = walker.Pop();

            return(lexem.Token switch
            {
                TToken _ => lexem,
                _ => HandleMissingLexem <TToken>(lexem, walker),
            });
Ejemplo n.º 2
0
        public static Parser Create()
        {
            // Create the object tree without DI Framework
            var expressionParser = new ExpressionParser();
            var factorParser     = new FactorParser(expressionParser);
            var termParser       = new TermParser(factorParser);

            expressionParser.TermParser = termParser;
            var lexerRules = new LexerRules();

            ILinePositionCalculator NewLinePositionCalculator(List <Lexem> lexems) => new LinePositionCalculator(lexems);
            ILexerReader NewLexerReader(string expression) => new LexerReader(expression);

            var tokenizer = new Tokenizer(lexerRules, NewLexerReader, NewLinePositionCalculator);

            IToken NewEpsilonToken() => new EpsilonToken();

            var tokenWalker = new TokenWalker(tokenizer, NewEpsilonToken, NewLinePositionCalculator);

            return(new Parser(tokenWalker, expressionParser));
        }
Ejemplo n.º 3
0
 public IParseNode Parse(TokenWalker walker)
 {
     return(_expressionParser.Parse(walker));
 }
Ejemplo n.º 4
0
 public Parser(TokenWalker tokenWalker, ExpressionParser expressionParser)
 {
     _tokenWalker      = tokenWalker;
     _expressionParser = expressionParser;
 }