O'Reilly logo

.NET Design Patterns by Shine Xavier, Praseed Pai

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The parser module

By using recursive descent parsing, we will arrange the tokens to see whether expressions are valid, and generate the AST out of the input stream with the help of the lexical analyzer.

A recursive descent parser is a top-down parser built from a set of mutually-recursive procedures, where each such procedure usually implements one of the production rules of the grammar. Thus, the structure of the resulting program closely mirrors the grammar that it recognizes:

    public class RDParser : Lexer 
    { 
      TOKEN Current_Token; 
      public RDParser(String str): base(str){} 
 
      public Exp CallExpr() 
      { 
        Current_Token = GetToken(); 
        return Expr(); 
      } 

The constructor of the RDParser class takes the expression string as a parameter, and passes it to the Lexer ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required