1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
Now consider the definition of line:
verb(
line:
'\n'
|
exp '\n'
{
cout << "\t" << $1 << endl;
}
;
)
The first alternative is a token which is a newline character; this means
that tt(rpn) accepts a blank line (and ignores it, since there is no
action). The second alternative is an expression followed by a newline. This
is the alternative that makes tt(rpn) useful. The semantic value of the
tt(exp) grouping is the value of tt($1) because the tt(exp) in question is the
first symbol in the rule's alternative. The action prints this value, which is
the result of the computation the user asked for.
This action is unusual because it does not assign a value to tt($$). As a
consequence, the semantic value associated with the line is uninitialized (its
value will be unpredictable). This would be a bug if that value were ever
used, but we don't use it: once tt(rpn) has printed the value of the user's
input line, that value is no longer needed.
|