General Information
Tutorials
Reference Manuals
Libraries
Translation Tasks
Tools
Administration
|
Syntactic AnalysisCarrying Out Actions During ParsingIn some cases the translation problem being solved requires that arbitrary actions be carried out as the parser is recognizing the phrase structure of the input, rather than waiting for the complete phrase structure to be available. Most of those cases can be classified either as interactive applications or as complex structuring problems in which contextual information is needed to determine the phrase structure. An arbitrary action is specified by a fragment of C code. None of the data accessed by this code is provided by Eli; it is the responsibility of the writer of the arbitrary actions to manage any data they manipulate. The simplest approach is to implement all actions as invocations of operators exported by a library or user-defined abstract data type. If these invocations have arguments, they are either constant values characteristic of the particular invocation or references to an entity exported by some (possibly different) abstract data type. An action is a sequence consisting of an ampersand (&) followed by a literal. The content of the literal is the C code fragment to be executed. Actions can be placed anywhere in a production, and will be executed when all of the symbols to the left of the action's position have been recognized. Thus an action placed at the end of the production would be executed when all of the symbols in the sequence have been recognized. Here is a fragment of a grammar describing a desk calculator; actions are used to compute subexpression values as the expression is parsed:
expression: term / expression '+' term &'ExprPlus();' / expression '-' term &'ExprMinus();' . term: primary / term '*' primary &'ExprTimes();' / term '/' primary &'ExprDiv();' . The C code fragments invoke operations of a module that maintains a stack of integer values.
If an action is placed anywhere other than the end of the production,
it may lead to conflicts.
Suppose that an action is placed between the first and second symbols of
the sequence in a production
|