xtc.parser
Class Generifier

java.lang.Object
  extended by xtc.tree.Visitor
      extended by xtc.parser.Generifier

public class Generifier
extends Visitor

Visitor to add generic nodes as semantic values.

For any production with pseudotype "generic" that does not contain any direct left-recursions (which is also called a generic node production), this visitor adds the appropriate generic node value elements, which create a generic node as the productions' semantic value. The children of such a generic node are the matched component values of the production, though voided elements, void nonterminals, and character terminals are not included. If an alternative assigns CodeGenerator.VALUE either through a binding or a semantic action, that alternative's semantic value is the specified semantic value and not a newly generated generic node. 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.

Note that this visitor does not process generic productions that contain direct left-recursions; they are processed by DirectLeftRecurser.

Version:
$Revision: 1.56 $
Author:
Robert Grimm

Field Summary
protected  Analyzer analyzer
          The analyzer utility.
protected  java.util.List<Binding> children
          The list of variables representing the children of the generic node to be created.
static java.lang.String MARKER
          The marker for synthetic variables.
protected  java.util.List<NodeMarker> markers
          The list of node markers.
protected  Runtime runtime
          The runtime.
 
Constructor Summary
Generifier(Runtime runtime, Analyzer analyzer)
          Create a new generifier.
 
Method Summary
protected  Binding bind(Element e)
          Create a binding for the specified element.
static boolean isGeneric(FullProduction p)
          Determine whether the specified production is a generic node or a generic recursion production.
static boolean isGenericNode(FullProduction p)
          Determine whether the specified production is a generic node production.
static boolean isGenericRecursion(FullProduction p)
          Determine whether the specified production is a generic recursion production.
static void markGenericNode(FullProduction p, boolean verbose)
          Mark the specified production as a generic node production.
static void markGenericRecursion(FullProduction p, boolean verbose)
          Mark the specified production as a generic recursion production.
 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)
          Visit 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.
 
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

MARKER

public static final java.lang.String MARKER
The marker for synthetic variables.

See Also:
Constant Field Values

runtime

protected final Runtime runtime
The runtime.


analyzer

protected final Analyzer analyzer
The analyzer utility.


children

protected java.util.List<Binding> children
The list of variables representing the children of the generic node to be created.


markers

protected java.util.List<NodeMarker> markers
The list of node markers.

Constructor Detail

Generifier

public Generifier(Runtime runtime,
                  Analyzer analyzer)
Create a new generifier.

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

bind

protected Binding bind(Element e)
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.
Returns:
The corresponding binding.

visit

public void visit(Module m)
Visit the specified grammar.


visit

public void visit(FullProduction p)
Visit the specified production.


visit

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


visit

public Element visit(Repetition r)
Visit the specified repetition.


visit

public Element visit(Option o)
Visit the specified option.


visit

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


visit

public Element visit(Binding b)
Visit the specified binding.


visit

public Element visit(StringMatch m)
Visit the specified string match.


visit

public Element visit(NonTerminal nt)
Visit the specified nonterminal.


visit

public Element visit(StringLiteral l)
Visit the specified string literal.


visit

public Element visit(ParseTreeNode n)
Visit the specified parse tree node.


visit

public Element visit(NullLiteral l)
Visit the specified null literal.


visit

public Element visit(NodeMarker m)
Visit the specified node marker.


visit

public Element visit(Element e)
Visit the specified element. This method provides the default implementation for predicates, voided elements, character terminals, (parser) actions, and value elements.


markGenericNode

public static void markGenericNode(FullProduction p,
                                   boolean verbose)
Mark the specified production as a generic node production.

Parameters:
p - The production.
verbose - The flag for whether to be verbose.

markGenericRecursion

public static void markGenericRecursion(FullProduction p,
                                        boolean verbose)
Mark the specified production as a generic recursion production.

Parameters:
p - The production.
verbose - The flag for whether to be verbose.

isGeneric

public static boolean isGeneric(FullProduction p)
Determine whether the specified production is a generic node or a generic recursion production.

Parameters:
p - The production.
Returns:
true if the specified production is a generic node or generic recursion production.

isGenericNode

public static boolean isGenericNode(FullProduction p)
Determine whether the specified production is a generic node production. A production is a generic node production if its semantic value is an automatically generated generic node with the component values as its children.

Parameters:
p - The production.
Returns:
true if the specified production is a generic node production.

isGenericRecursion

public static boolean isGenericRecursion(FullProduction p)
Determine whether the specified production is a generic recursion production. A production is a generic recursion production if its semantic value is an automatically generated generic node and the production, as specified, contains one or more direct left-recursions that can automatically be transformed into the corresponding right-recursions.

Parameters:
p - The production.
Returns:
true if the specified production is a generic recursion production.
See Also:
DirectLeftRecurser


Copyright © 2012. All Rights Reserved.