xtc.parser
Class CostEstimator

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

public class CostEstimator
extends Visitor

Visitor to provide a conservative estimate for the cost of parsing a production. One unit of cost is approximately equivalent to the effort involved in parsing a character and testing it for a specific value. The cost estimate for a production includes the costs for any other productions referenced by that production. If the cost cannot be statically determined (for example, for a repetition) or a set of productions is mutually recursive, the cost is assumed to be unlimited, as represented by Integer.MAX_VALUE. This visitor must be invoked by visiting a grammar, which clears any previous cost estimates and annotates each production with its estimated cost.

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

Version:
$Revision: 1.26 $
Author:
Robert Grimm

Field Summary
protected  Analyzer analyzer
          The analyzer utility.
 
Constructor Summary
CostEstimator(Analyzer analyzer)
          Create a new cost estimator.
 
Method Summary
protected static int add(int e1, int e2)
          Add the two specified estimates.
 java.lang.Integer visit(Action a)
          Visit the specified action.
 java.lang.Integer visit(ActionBaseValue v)
          Visit the specified action base value.
 java.lang.Integer visit(Binding b)
          Visit the specified binding.
 java.lang.Integer visit(CharCase c)
          Visit the specified character case.
 java.lang.Integer visit(CharSwitch sw)
          Visit the specified character switch.
 java.lang.Integer visit(GenericActionValue v)
          Visit the specified generic action value.
 java.lang.Integer visit(GenericNodeValue v)
          Visit the specified generic node value.
 java.lang.Integer visit(GenericRecursionValue v)
          Visit the specified generic recursion value.
 void visit(Module m)
          Visit the specified grammar.
 java.lang.Integer visit(NodeMarker m)
          Visit the specified node marker.
 java.lang.Integer visit(NonTerminal nt)
          Visit the specified nonterminal.
 java.lang.Integer visit(NullLiteral l)
          Visit the specified null literal.
 java.lang.Integer visit(Option o)
          Visit the specified option.
 java.lang.Integer visit(OrderedChoice c)
          Visit the specified ordered choice.
 java.lang.Integer visit(ParserAction a)
          Visit the specified parser action.
 java.lang.Integer visit(Predicate p)
          Visit the specified predicate.
 java.lang.Integer visit(Production p)
          Visit the specified production.
 java.lang.Integer visit(ProperListValue v)
          Visit the specified proper list value.
 java.lang.Integer visit(Repetition r)
          Visit the specified repetition.
 java.lang.Integer visit(Sequence s)
          Visit the specified sequence.
 java.lang.Integer visit(StringLiteral l)
          Visit the specified string literal.
 java.lang.Integer visit(StringMatch m)
          Visit the specified string match.
 java.lang.Integer visit(StringValue v)
          Visit the specified string value.
 java.lang.Integer visit(Terminal t)
          Visit the specified terminal.
 java.lang.Integer visit(ValueElement v)
          Visit the specified value element.
 java.lang.Integer visit(VoidedElement v)
          Visit the specified voided element.
 
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

analyzer

protected final Analyzer analyzer
The analyzer utility.

Constructor Detail

CostEstimator

public CostEstimator(Analyzer analyzer)
Create a new cost estimator.

Parameters:
analyzer - The analyzer utility.
Method Detail

visit

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


visit

public java.lang.Integer visit(Production p)
Visit the specified production.


visit

public java.lang.Integer visit(OrderedChoice c)
Visit the specified ordered choice.


visit

public java.lang.Integer visit(Repetition r)
Visit the specified repetition.


visit

public java.lang.Integer visit(Option o)
Visit the specified option.


visit

public java.lang.Integer visit(Sequence s)
Visit the specified sequence.


visit

public java.lang.Integer visit(Predicate p)
Visit the specified predicate.


visit

public java.lang.Integer visit(VoidedElement v)
Visit the specified voided element.


visit

public java.lang.Integer visit(Binding b)
Visit the specified binding.


visit

public java.lang.Integer visit(StringMatch m)
Visit the specified string match.


visit

public java.lang.Integer visit(NonTerminal nt)
Visit the specified nonterminal.


visit

public java.lang.Integer visit(StringLiteral l)
Visit the specified string literal.


visit

public java.lang.Integer visit(CharCase c)
Visit the specified character case.


visit

public java.lang.Integer visit(CharSwitch sw)
Visit the specified character switch.


visit

public java.lang.Integer visit(Terminal t)
Visit the specified terminal. This method provides the default implementation for any character elements, character classes, and character literals.


visit

public java.lang.Integer visit(NodeMarker m)
Visit the specified node marker.


visit

public java.lang.Integer visit(Action a)
Visit the specified action.


visit

public java.lang.Integer visit(ParserAction a)
Visit the specified parser action.


visit

public java.lang.Integer visit(NullLiteral l)
Visit the specified null literal.


visit

public java.lang.Integer visit(StringValue v)
Visit the specified string value.


visit

public java.lang.Integer visit(ProperListValue v)
Visit the specified proper list value.


visit

public java.lang.Integer visit(ActionBaseValue v)
Visit the specified action base value.


visit

public java.lang.Integer visit(GenericNodeValue v)
Visit the specified generic node value.


visit

public java.lang.Integer visit(GenericActionValue v)
Visit the specified generic action value.


visit

public java.lang.Integer visit(GenericRecursionValue v)
Visit the specified generic recursion value.


visit

public java.lang.Integer visit(ValueElement v)
Visit the specified value element. This method provides the default implementation for null values and empty list values.


add

protected static int add(int e1,
                         int e2)
Add the two specified estimates.

Parameters:
e1 - The first estimate.
e2 - The second estimate.
Returns:
The sum.


Copyright © 2012. All Rights Reserved.