Contents    Page-10    Prev    Next    Page+10    Index   

Grammar Rules

A grammar rule has the form:


(nonterm -> (right-hand side items) semantics)
nonterm is a nonterminal symbol that is the left-hand side of the production; the rule says that the left-hand side nonterminal can be composed of the sequence of items on the right-hand side.

The allowable items on the right-hand side are:
word exactly the specified word
(nonterminal) like a subroutine call to a sub-grammar.
(category) a word in the category, e.g. (month)
(number) any number
(symbol) any symbol
? preceding item is optional
(separate ? from a word by a space)

The semantics is clojure code to be executed when the grammar rule is satisfied. The right-hand side items are available as variables $1, $2, $3, etc., similar to what is done in Yacc. For example, consider the rule:


 (loc -> (in (city))   (restrict 'city $2))
In this case, $2 refers to whatever matches the (city) part of the grammar rule.