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

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.