xtc.parser
Class ChoiceExpander

java.lang.Object
  extended by xtc.tree.Visitor
      extended by xtc.parser.GrammarVisitor
          extended by xtc.parser.ChoiceExpander

public class ChoiceExpander
extends GrammarVisitor

Visitor to expand choices by inlining productions. This visitor inlines transient productions if they are essentially the only element appearing in ordered choices' alternatives.

Note that this visitor requires that text-only productions have been marked as such, that all value elements have been added to the grammar (notably, for generic productions), and that the grammar's productions have been reference counted. Also note that this visitor may result in new opportunities for the elimination of dead productions.

This visitor assumes that the entire grammar is contained in a single module.

Version:
$Revision: 1.36 $
Author:
Robert Grimm

Nested Class Summary
static class ChoiceExpander.Mode
          The processing mode.
 
Field Summary
protected  boolean hasState
          The flag for whether the grammar has the state attribute.
protected  ChoiceExpander.Mode mode
          The current processing mode.
 
Fields inherited from class xtc.parser.GrammarVisitor
analyzer, isBound, isLastElement, isPredicate, isRepeatedOnce, isTopLevel, isVoided, needsSequence, runtime, transformInPlace
 
Constructor Summary
ChoiceExpander(Runtime runtime, Analyzer analyzer)
          Create a new choice expander.
 
Method Summary
protected  NonTerminal candidate(Sequence alternative, boolean top)
          Determine whether the specified alternative is a candidate for replacement.
protected  void inlined(Production p)
          Record that the specified production has been inlined and, if necessary, print a message to the console.
 java.lang.Object visit(Module m)
          Visit the specified grammar.
 Element visit(OrderedChoice c)
          Visit the specified ordered choice.
 Element visit(Sequence s)
          Visit the specified sequence.
 Element visit(ValueElement v)
          Visit the specified value element.
 
Methods inherited from class xtc.parser.GrammarVisitor
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
 
Methods inherited from class xtc.tree.Visitor
dispatch, equals, hashCode, iterate, map, mapInPlace, unableToVisit, visit
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hasState

protected boolean hasState
The flag for whether the grammar has the state attribute.


mode

protected ChoiceExpander.Mode mode
The current processing mode.

Constructor Detail

ChoiceExpander

public ChoiceExpander(Runtime runtime,
                      Analyzer analyzer)
Create a new choice expander.

Parameters:
runtime - The runtime.
analyzer - The analyzer utility.
Method Detail

candidate

protected NonTerminal candidate(Sequence alternative,
                                boolean top)
Determine whether the specified alternative is a candidate for replacement. If the alternative is a candidate, this method returns the nonterminal for inlining. Otherwise, it returns null.

Parameters:
alternative - The alternative.
top - The flag for whether the alternative appears in a top-level choice.
Returns:
The candidate nonterminal.

inlined

protected void inlined(Production p)
Record that the specified production has been inlined and, if necessary, print a message to the console.

Parameters:
p - The production.

visit

public java.lang.Object visit(Module m)
Visit the specified grammar.

Overrides:
visit in class GrammarVisitor

visit

public Element visit(OrderedChoice c)
Visit the specified ordered choice.

Overrides:
visit in class GrammarVisitor

visit

public Element visit(Sequence s)
Visit the specified sequence.

Overrides:
visit in class GrammarVisitor

visit

public Element visit(ValueElement v)
Visit the specified value element.



Copyright © 2012. All Rights Reserved.