| www.delorie.com/gnu/docs/bison/bison_19.html | search |
![]() Buy the book! | |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
rpcalc Here are the grammar rules for the reverse polish notation calculator.
input: /* empty */
| input line
;
line: '\n'
| exp '\n' { printf ("\t%.10g\n", $1); }
;
exp: NUM { $$ = $1; }
| exp exp '+' { $$ = $1 + $2; }
| exp exp '-' { $$ = $1 - $2; }
| exp exp '*' { $$ = $1 * $2; }
| exp exp '/' { $$ = $1 / $2; }
/* Exponentiation */
| exp exp '^' { $$ = pow ($1, $2); }
/* Unary minus */
| exp 'n' { $$ = -$1; }
;
%%
|
The groupings of the rpcalc "language" defined here are the expression
(given the name exp), the line of input (line), and the
complete input transcript (input). Each of these nonterminal
symbols has several alternate rules, joined by the `|' punctuator
which is read as "or". The following sections explain what these rules
mean.
The semantics of the language is determined by the actions taken when a grouping is recognized. The actions are the C code that appears inside braces. See section 3.5.3 Actions.
You must specify these actions in C, but Bison provides the means for
passing semantic values between the rules. In each action, the
pseudo-variable $$ stands for the semantic value for the grouping
that the rule is going to construct. Assigning a value to $$ is the
main job of most actions. The semantic values of the components of the
rule are referred to as $1, $2, and so on.
2.1.2.1 Explanation of input2.1.2.2 Explanation of line2.1.2.3 Explanation of expr
| webmaster donations bookstore | delorie software privacy |
| Copyright © 2003 by The Free Software Foundation | Updated Jun 2003 |