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

11.2. New Terminals

Terminals use some judgment about whether the next element in an assembly qualifies as the type of element sought. You can refine this judgment by introducing new subclasses of Terminal. For example, consider a language that differentiates between known values and unknown values by using lowercase and uppercase letters. In this language, a structure might appear that looks like this:

member(X, [republican, democrat]) 

This structure might imply that the unknown X can take on either of the known values in the list. A partial grammar for this language might look something like this:

//... 
term     = variable | known;
variable = UppercaseWord;
known    = LowercaseWord;

Here is a sample program that depends on UppercaseWord and

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