|
|
An action may refer to values returned by actions to the left of the current rule. The mechanism is simply the same as with ordinary actions, $ followed by a digit.
sent : adj noun verb adj noun { look at the sentence ... } ; adj : THE { $$ = THE; } | YOUNG { $$ = YOUNG; } ... ; noun : DOG { $$ = DOG; } | CRONE { if( $0 == YOUNG ) { (void) printf( "what?\n" ); } $$ = CRONE; } ; ...
In this case, the digit may be 0 or negative. In the action following the word CRONE, a check is made that the preceding token shifted was not YOUNG. Obviously, this is only possible when a great deal is known about what might precede the symbol noun in the input. Nevertheless, at times this mechanism prevents a great deal of trouble especially when a few combinations are to be excluded from an otherwise regular structure.