Next: , Previous: , Up: Bovine parser development   [Contents]

2 Bovine Grammar Rules

The rules are what allow the compiler to create tags from a language file. Once the setup is done in the prologue, you can start writing rules. See (grammar-fw)Grammar Framework Manual.

result : components1 optional-semantic-action1)
       | components2 optional-semantic-action2

result is a nonterminal, that is a symbol synthesized in your grammar. components is a list of elements that are to be matched if result is to be made. optional-semantic-action is an optional sequence of simplified Emacs Lisp expressions for concocting the parse tree.

In bison, each time an element of components is found, it is shifted onto the parser stack. (The stack of matched elements.) When all components’ elements have been matched, it is reduced to result. See Algorithm in The GNU Bison Manual.

A particular result written into your grammar becomes the parser’s goal. It is designated by a %start statement (see Starting Rules). The value returned by the associated optional-semantic-action is the parser’s result. It should be a tree of Semantic tags, see (semantic-appdev)Semantic Application Development.

components is made up of symbols. A symbol such as FOO means that a syntactic token of class FOO must be matched.