xtc.parser
Class Simplifier

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

public class Simplifier
extends GrammarVisitor

Visitor to simplify a grammar. This visitor folds nested choices and sequences into the embedding choice or sequence, eliminates choices and sequences with only one alternative or element (with the exception of the top-level choice of a production), and reduces repetitions and options to their simplest form. It also reduces trivial character classes and string literals to character literals. Note that the resulting grammar may violate the requirements of code generation.

Version:
$Revision: 1.54 $
Author:
Robert Grimm

Field Summary
 
Fields inherited from class xtc.parser.GrammarVisitor
analyzer, isBound, isLastElement, isPredicate, isRepeatedOnce, isTopLevel, isVoided, needsSequence, runtime, transformInPlace
 
Constructor Summary
Simplifier(Runtime runtime, Analyzer analyzer)
          Create a new simplifier.
 
Method Summary
 Element visit(Binding b)
          Visit the specified binding.
 Element visit(CharClass c)
          Visit the specified character class.
 Element visit(Option o)
          Visit the specified option.
 Element visit(OrderedChoice c)
          Visit the specified ordered choice.
 Element visit(Repetition r)
          Visit the specified repetition.
 Element visit(Sequence s)
          Visit the specified sequence.
 Element visit(StringMatch m)
          Visit the specified string match.
 Element visit(VoidedElement v)
          Visit the specified voided element.
 
Methods inherited from class xtc.parser.GrammarVisitor
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
 

Constructor Detail

Simplifier

public Simplifier(Runtime runtime,
                  Analyzer analyzer)
Create a new simplifier.

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

visit

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

Overrides:
visit in class GrammarVisitor

visit

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

Overrides:
visit in class GrammarVisitor

visit

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

Overrides:
visit in class GrammarVisitor

visit

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

Overrides:
visit in class GrammarVisitor

visit

public Element visit(VoidedElement v)
Visit the specified voided element.

Overrides:
visit in class GrammarVisitor

visit

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

Overrides:
visit in class GrammarVisitor

visit

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

Overrides:
visit in class GrammarVisitor

visit

public Element visit(CharClass c)
Visit the specified character class.



Copyright © 2012. All Rights Reserved.