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

14.2. A Logikus Grammar

The building blocks of Logikus programs are structures and variables. A typical structure has a string as its functor and has terms enclosed in parentheses. For now, let's sketch a grammar that will recognize a structure such as

starred(jamesCagney, "Mister Roberts", Year) 

The following grammar gives a first draft for recognizing Logikus structures and variables:

structure    = functor ('(' commaList(term) ')' | Empty); 
functor      = LowercaseWord | QuotedString;
term         = structure | variable;
variable     = UppercaseWord;
commaList(p) = p (',' p)*;

Note that the functor of a structure cannot be an uppercase word. Logikus shares this feature with Prolog; users need not and cannot declare variables. A string that begins with an ...

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