| 1 |
Here are the grammar rules for the reverse polish notation calculator. |
| 2 |
verbinsert(//RULES rpn/parser/grammar) |
| 3 |
The rules of the tt(rpn) `language' defined here are the expression |
| 4 |
(using the name tt(exp)), the line of input (tt(line)), and the complete input |
| 5 |
transcript (tt(input)). Each of these nonterminal symbols has several |
| 6 |
alternate rules, joined by the `tt(|)' separator, separating the various |
| 7 |
production rules. The various rules are explained next. |
| 8 |
|
| 9 |
The semantics of the language are determined by the actions taken once |
| 10 |
nonterminals have been recognized. The actions consist of bf(C++) code that |
| 11 |
appears inside braces. See section ref(ACTIONS). |
| 12 |
|
| 13 |
Actions are specified using bf(C++), but b() provides the means for passing |
| 14 |
semantic values between rules. Refer to section ref(ACTIONS) below for an |
| 15 |
extensive coverage of the various possibilities. As a short introduction, the |
| 16 |
pseudo-variable tt($$) can be used in rules to represent the semantic value |
| 17 |
for the nonterminal that the production rule is defining. Assigning a value to |
| 18 |
tt($$) is the main task of many actions. The semantic values of the elements |
| 19 |
of production rules are referred to as tt($1) (the first element of a |
| 20 |
production rule), tt($2) (the second element), and so on. |