Next: , Previous: , Up: Java Parsers   [Contents][Index]


10.2.6 Special Features for Use in Java Actions

The following special constructs can be uses in Java actions. Other analogous C action features are currently unavailable for Java.

Use ‘%define throws’ to specify any uncaught exceptions from parser actions, and initial actions specified by %initial-action.

Variable: $n

The semantic value for the nth component of the current rule. This may not be assigned to. See Java Semantic Values.

Variable: $<typealt>n

Like $n but specifies a alternative type typealt. See Java Semantic Values.

Variable: $$

The semantic value for the grouping made by the current rule. As a value, this is in the base type (Object or as specified by ‘%define api.value.type’) as in not cast to the declared subtype because casts are not allowed on the left-hand side of Java assignments. Use an explicit Java cast if the correct subtype is needed. See Java Semantic Values.

Variable: $<typealt>$

Same as $$ since Java always allow assigning to the base type. Perhaps we should use this and $<>$ for the value and $$ for setting the value but there is currently no easy way to distinguish these constructs. See Java Semantic Values.

Variable: @n

The location information of the nth component of the current rule. This may not be assigned to. See Java Location Values.

Variable: @$

The location information of the grouping made by the current rule. See Java Location Values.

Statement: return YYABORT ;

Return immediately from the parser, indicating failure. See Java Parser Interface.

Statement: return YYACCEPT ;

Return immediately from the parser, indicating success. See Java Parser Interface.

Statement: return YYERROR ;

Start error recovery (without printing an error message). See Error Recovery.

Function: boolean recovering ()

Return whether error recovery is being done. In this state, the parser reads token until it reaches a known state, and then restarts normal operation. See Error Recovery.

Function: void yyerror (String msg)
Function: void yyerror (Position loc, String msg)
Function: void yyerror (Location loc, String msg)

Print an error message using the yyerror method of the scanner instance in use. The Location and Position parameters are available only if location tracking is active.


Next: , Previous: , Up: Java Parsers   [Contents][Index]