O'Reilly logo

Building Parsers with Java™ by Steven John Metsker

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

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 ...

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