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