xtc.parser
Class Transformer

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

public class Transformer
extends Visitor

Visitor to transform productions. This visitor lifts repetitions, options, and nested choices into their own productions, desugars reptitions and options, and adds the appropriate semantic values to expressions that require them. It also ensures that repeated, optional, and predicated elements are sequences, thus fulfilling the requirements for code generation. Before applying this visitor on a grammar, the grammar must have been simplified, all text-only productions should be marked as such by applying the TextTester visitor, and all token-level productions should be marked as such by applying the Tokenizer visitor. Note that Generifier adds the appropriate semantic values for generic productions. Further note that repetitions in transient productions are not desugared (nor lifted) if the corresponding command line option ("-Orepeated-Ooptional") is set. Finally, note that this visitor assumes that the entire grammar is contained in a single module.

This visitor may report errors to the user.

Version:
$Revision: 1.128 $
Author:
Robert Grimm

Nested Class Summary
 class Transformer.Deducer
          Visitor to add semantic values.
 class Transformer.Desugarer
          Visitor to desugar repetitions and options.
 class Transformer.Lifter
          Visitor to lift nested choices, repetitions, and options.
 class Transformer.Typer
          Visitor to deduce a production's type.
 
Field Summary
protected  Analyzer analyzer
          The analyzer.
protected  AST ast
          The type operations.
static java.lang.String ELEMENT_MARKER
          The variable marker for bindings in repeated or optional elements.
protected  boolean hasParseTree
          The flag for whether the current module has the parseTree attribute.
protected  FullProduction production
          The current (full) production.
protected  Runtime runtime
          The runtime.
 
Constructor Summary
Transformer(Runtime runtime, Analyzer analyzer, AST ast)
          Create a new transformer.
 
Method Summary
 boolean changesState()
          Determine whether the current production changes the global parser state.
protected  Production current()
          Get the current production.
protected  boolean isGeneric()
          Determine whether the current production is generic.
protected  boolean isLeftRecursive()
          Determine whether the current production is a directly left-recursive production.
protected  boolean isList()
          Determine whether the current production has a list value.
protected  boolean isMemoized()
          Determine whether the current production is memoized.
protected  boolean isTextOnly()
          Determine whether the current production is text-only.
protected  boolean isToken()
          Determine whether the current production is token-level.
protected  boolean isVoid()
          Determine whether the current production is void.
protected  void process(FullProduction p)
          Process the specified production.
protected  boolean retainOptions()
          Determine whether the current production may contain options.
protected  boolean retainRepetitions()
          Determine whether the current production may contain repetitions.
 void visit(FullProduction p)
          Visit the specified production.
 void visit(Module m)
          Visit the specified grammar.
 
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

ELEMENT_MARKER

public static final java.lang.String ELEMENT_MARKER
The variable marker for bindings in repeated or optional elements.

See Also:
Constant Field Values

runtime

protected final Runtime runtime
The runtime.


analyzer

protected final Analyzer analyzer
The analyzer.


ast

protected final AST ast
The type operations.


hasParseTree

protected boolean hasParseTree
The flag for whether the current module has the parseTree attribute.


production

protected FullProduction production
The current (full) production.

Constructor Detail

Transformer

public Transformer(Runtime runtime,
                   Analyzer analyzer,
                   AST ast)
Create a new transformer.

Parameters:
runtime - The runtime.
analyzer - The analyzer utility.
ast - The type operations.
Method Detail

process

protected void process(FullProduction p)
Process the specified production. This method may be called recursively while processing another production.

Parameters:
p - The production to process.

isMemoized

protected boolean isMemoized()
Determine whether the current production is memoized.

Returns:
true if the current production is memoized.

changesState

public boolean changesState()
Determine whether the current production changes the global parser state.

Returns:
true if the current production is resetting or stateful.

isVoid

protected boolean isVoid()
Determine whether the current production is void.

Returns:
true if the current production is void.

isTextOnly

protected boolean isTextOnly()
Determine whether the current production is text-only.

Returns:
true if the current production is text-only.

isToken

protected boolean isToken()
Determine whether the current production is token-level.

Returns:
true if the current production is token-level.

isGeneric

protected boolean isGeneric()
Determine whether the current production is generic.

Returns:
true if the current production is generic.

isList

protected boolean isList()
Determine whether the current production has a list value.

Returns:
true if the current production has a list value.

isLeftRecursive

protected boolean isLeftRecursive()
Determine whether the current production is a directly left-recursive production.

Returns:
true if the current production is directly left-recursive.

current

protected Production current()
Get the current production.

Returns:
The current production.

retainRepetitions

protected boolean retainRepetitions()
Determine whether the current production may contain repetitions.

Returns:
true if the production may contain repetitions.

retainOptions

protected boolean retainOptions()
Determine whether the current production may contain options.

Returns:
true if the production may contain options.

visit

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


visit

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



Copyright © 2012. All Rights Reserved.