8.5. A Regular Expression Parser

The class RegularParser holds a collection of methods that return the subparsers for a regular expression grammar. Figure 8.4 shows this class.

Figure 8.4. The RegularParser class. This class holds a collection of methods that compose into a parser for regular expressions.

To use this class, you can apply RegularParser.start() to match a character assembly. As with the ArithmeticParser class, the RegularParser class provides a value() method, which simplifies using the class. The following example uses the RegularParser class's value() method to match a variety of regular expressions:

 package sjm.examples.regular; ...

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.