March 2001
Intermediate to advanced
400 pages
8h 35m
English
You can follow the rules of Section 3.6 “Translating a Grammar to Code,” and code subparsers as methods on a parser class. Figure 5.4 shows CoffeeParser.

Most of the methods of the CoffeeParser class return a parser that recognizes one aspect of the coffee grammar. For example, the price() method returns a parser for the rule
price = Num;
The code for CoffeeParser.price() plugs in the price assembler:
/* * Return a parser that will recognize the sequence: * * price = Num; * * Use a PriceAssembler to update ...
Read now
Unlock full access