bovine: Bovine Grammar Rules
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. (grammar-fw)Grammar Rules.
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.
(bison)Algorithm.
A particular RESULT written into your grammar becomes the parser’s
goal. It is designated by a ‘%start’ statement (Starting
Rules). The value returned by the associated OPTIONAL-SEMANTIC-ACTION
is the parser’s result. It should be a tree of Semantic “tags”,
(semantic-appdev)Semantic Tags.
COMPONENTS is made up of symbols. A symbol such as ‘FOO’ means that
a syntactic token of class ‘FOO’ must be matched.
Menu