| java.lang.Object xtc.tree.Visitor xtc.parser.DirectLeftRecurser
DirectLeftRecurser | public class DirectLeftRecurser extends Visitor (Code) | | Visitor to transform direct left-recursions into equivalent
right-recursions. As a practical matter, this visitor transforms
only void, text-only, token-level, and generic productions. For
generic productions, it builds on
xtc.util.Action actions to ensure that the resulting right-recursive productions preserve
the structure of the original productions' semantic values. In
particular, left-associative data structures remain
left-associative, even after transformation. This visitor requires
that all nested choices that do not appear as the last element in a
sequence have been lifted. It also assumes that the entire grammar
is contained in a single module.
This visitor may report errors to the user.
author: Robert Grimm version: $Revision: 1.77 $ |
Field Summary | |
final public static int | STATE_BASE The flag for processing the base case. | final public static int | STATE_RECURSION The flag for processing the recursive case. | final protected Analyzer | analyzer The analyzer utility. | final protected AST | ast The type operations. | protected List<Binding> | children The list of variables representing the children of the generic
node to be created. | protected boolean | hasConstant The flag for whether the grammar has the
Constants.ATT_CONSTANTconstant attribute. | protected boolean | hasParseTree The flag for whether the grammar has the
Constants.ATT_PARSE_TREE parseTree attribute. | protected boolean | isGeneric The flag for whether we are transforming a generic production. | protected boolean | isTextOnly The flag for whether we are transforming a text-only production. | protected boolean | isToken The flag for whether we are transforming a token-level production. | protected boolean | isTopLevel Flag for whether the current element is the top-level element of
a production. | protected boolean | isVoid The flag for whether we are transforming a void production. | protected List<NodeMarker> | markers The list of node markers. | protected FullProduction | pTail The new tail production. | final protected Runtime | runtime The runtime. | protected Binding | seed The binding for the seed value. | protected boolean | seenChoice Flag for whether we have processed an ordered choice. | protected int | state The current state. | protected String | varAction The name of the action's argument. |
STATE_BASE | final public static int STATE_BASE(Code) | | The flag for processing the base case.
|
STATE_RECURSION | final public static int STATE_RECURSION(Code) | | The flag for processing the recursive case.
|
ast | final protected AST ast(Code) | | The type operations.
|
children | protected List<Binding> children(Code) | | The list of variables representing the children of the generic
node to be created.
|
isGeneric | protected boolean isGeneric(Code) | | The flag for whether we are transforming a generic production.
|
isTextOnly | protected boolean isTextOnly(Code) | | The flag for whether we are transforming a text-only production.
|
isToken | protected boolean isToken(Code) | | The flag for whether we are transforming a token-level production.
|
isTopLevel | protected boolean isTopLevel(Code) | | Flag for whether the current element is the top-level element of
a production.
|
isVoid | protected boolean isVoid(Code) | | The flag for whether we are transforming a void production.
|
seenChoice | protected boolean seenChoice(Code) | | Flag for whether we have processed an ordered choice.
|
state | protected int state(Code) | | The current state.
|
varAction | protected String varAction(Code) | | The name of the action's argument.
|
DirectLeftRecurser | public DirectLeftRecurser(Runtime runtime, Analyzer analyzer, AST ast)(Code) | | Create a new direct left-recurser.
Parameters: runtime - The runtime. Parameters: analyzer - The analyzer utility. Parameters: ast - The type operations. |
bind | protected Binding bind(Element e)(Code) | | Create a binding for the specified element. This method also
adds the name of the bound variable to the end of the list of
children.
Parameters: e - The element to bind. The corresponding binding. |
isBase | public static boolean isBase(Sequence s, FullProduction p)(Code) | | Determine whether the specified sequence represents a base case
for a direct left-recursion. The specified sequence must be a
top-level alternative for the specified production, which, in
turn, must be
DirectLeftRecurser.isTransformable transformable .
Parameters: s - The sequence. Parameters: p - The production. true if the specified sequence is a basecase for the direct left-recursion. |
isRecursive | public static boolean isRecursive(Sequence s, FullProduction p)(Code) | | Determine whether the specified sequence is directly
left-recursive. The specified sequence must be a top-level
alternative of the specified production, which, in turn, must be
DirectLeftRecurser.isTransformable transformable .
Parameters: s - The sequence. Parameters: p - The production. true if the specified sequence is directlyleft-recursive. |
isTransformable | public static boolean isTransformable(FullProduction p)(Code) | | Determine whether the specified production contains a direct
left-recursion that is transformable into the corresponding
right-recursion by this visitor. Note that, for a production to
be transformable, all direct left-recursions must precede the
corresponding base cases. Further nore that this method assumes
that the specified production's element is an ordered choice of
sequences.
Parameters: p - The production. true if the production is transformableby this visitor. |
visit | public void visit(Module m)(Code) | | Process the specified grammar.
|
visit | public Element visit(Element e)(Code) | | Visit the specified element. This method provides the default
implementation for repetitions, options, predicates, voided
elements, character terminals, (parser) actions, and value
elements.
|
|
|