In some cases the translation problem being solved requires that arbitrary
be carried out as the parser is recognizing the phrase structure of
the input, rather than waiting for the complete phrase structure to be
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
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
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
expression '+' term &'ExprPlus();' /
expression '-' term &'ExprMinus();' .
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
Suppose further that there is another production,
Q, whose sequence
begins with the same two symbols but does not contain the same action.
If one of the states of the parser could be recognizing either
Q, and has recognized the first symbol, it would not be able to
decide whether or not to execute the action.