public class DirectLeftRecurser extends Visitor
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.| Modifier and Type | Field and Description |
|---|---|
protected Analyzer |
analyzer
The analyzer utility.
|
protected AST |
ast
The type operations.
|
protected java.util.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
constant attribute. |
protected boolean |
hasParseTree
The flag for whether the grammar has the
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 java.util.List<NodeMarker> |
markers
The list of node markers.
|
protected FullProduction |
pTail
The new tail production.
|
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.
|
static int |
STATE_BASE
The flag for processing the base case.
|
static int |
STATE_RECURSION
The flag for processing the recursive case.
|
protected java.lang.String |
varAction
The name of the action's argument.
|
| Constructor and Description |
|---|
DirectLeftRecurser(Runtime runtime,
Analyzer analyzer,
AST ast)
Create a new direct left-recurser.
|
| Modifier and Type | Method and Description |
|---|---|
protected Binding |
bind(Element e)
Create a binding for the specified element.
|
static boolean |
isBase(Sequence s,
FullProduction p)
Determine whether the specified sequence represents a base case
for a direct left-recursion.
|
static boolean |
isRecursive(Sequence s,
FullProduction p)
Determine whether the specified sequence is directly
left-recursive.
|
static boolean |
isTransformable(FullProduction p)
Determine whether the specified production contains a direct
left-recursion that is transformable into the corresponding
right-recursion by this visitor.
|
Element |
visit(Binding b)
Visit the specified binding.
|
Element |
visit(Element e)
Visit the specified element.
|
void |
visit(FullProduction p)
Visit the specified production.
|
void |
visit(Module m)
Process the specified grammar.
|
Element |
visit(NodeMarker m)
Visit the specified node marker.
|
Element |
visit(NonTerminal nt)
Visit the specified nonterminal.
|
Element |
visit(NullLiteral l)
Visit the specified null literal.
|
Element |
visit(Option o)
Visit the specified option.
|
Element |
visit(OrderedChoice c)
Visit the specified ordered choice.
|
Element |
visit(ParseTreeNode n)
Visit the specified parse tree node.
|
Element |
visit(Repetition r)
Visit the specified repetition.
|
Element |
visit(Sequence s)
Visit the specified sequence.
|
Element |
visit(StringLiteral l)
Visit the specified string literal.
|
Element |
visit(StringMatch m)
Visit the specified string match.
|
dispatch, equals, hashCode, iterate, map, mapInPlace, unableToVisit, visitpublic static final int STATE_RECURSION
public static final int STATE_BASE
protected final Runtime runtime
protected final Analyzer analyzer
protected final AST ast
protected boolean isVoid
protected boolean isTextOnly
protected boolean isToken
protected boolean isGeneric
protected boolean hasConstant
constant attribute.protected boolean hasParseTree
parseTree attribute.protected int state
protected boolean isTopLevel
protected boolean seenChoice
protected java.util.List<Binding> children
protected java.util.List<NodeMarker> markers
protected FullProduction pTail
protected Binding seed
protected java.lang.String varAction
protected Binding bind(Element e)
e - The element to bind.public void visit(Module m)
public void visit(FullProduction p)
public Element visit(OrderedChoice c)
public Element visit(Repetition r)
public Element visit(StringMatch m)
public Element visit(NonTerminal nt)
public Element visit(StringLiteral l)
public Element visit(ParseTreeNode n)
public Element visit(NullLiteral l)
public Element visit(NodeMarker m)
public Element visit(Element e)
public static boolean isTransformable(FullProduction p)
p - The production.true if the production is transformable
by this visitor.public static boolean isRecursive(Sequence s, FullProduction p)
transformable.s - The sequence.p - The production.true if the specified sequence is directly
left-recursive.public static boolean isBase(Sequence s, FullProduction p)
transformable.s - The sequence.p - The production.true if the specified sequence is a base
case for the direct left-recursion.Copyright © 2014. All Rights Reserved.