4.3. Special Tokenizers and Targets

If your parser needs a special tokenizer or target, you can create a new subclass of ParserTester and override the assembly() and freshTarget() methods. For example, the SlingParser class in Chapter 16, “Parsing an Imperative Language,” uses a special tokenizer that recognizes reserved words. This parser class also requires an assembly to have as its target a SlingTarget object. To provide for these special target and tokenization needs, the class SlingTester in sjm.examples.sling overrides the freshTarget() and assembly() methods of its superclasses. Here is SlingTester.java:

 package sjm.examples.sling; import sjm.parse.*; import sjm.parse.tokens.*; import sjm.examples.sling.*; /** * This class tests that ...

Get Building Parsers with Java™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.