xtc.parser
Class Resolver

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

public class Resolver
extends Visitor

Visitor to resolve grammar module dependencies.

Note that this visitor marks text-only productions as such. It also detects left recursions and marks direct left recursions. Furthermore, it sets a grammar's Properties.GENERIC and Properties.RECURSIVE properties as appropriate.

Version:
$Revision: 1.128 $
Author:
Robert Grimm

Field Summary
protected  Analyzer analyzer
          The analyzer utility.
protected  AST ast
          The type operations.
protected  java.util.Map<NonTerminal,NonTerminal> badNTs
          The identity hash map of erroneous nonterminals.
protected  boolean hasState
          The flag for whether the current module has a stateful attribute.
protected  boolean isMofunctor
          The flag for whether the current module is a mofunctor.
protected  boolean isPredicate
          Flag for whether the current expression is a predicate.
protected  int phase
          The current checking phase.
protected  Runtime runtime
          The runtime.
protected  java.util.Set<SequenceName> sequenceNames
          The set of sequence names for the current production.
 
Constructor Summary
Resolver(Runtime runtime, Analyzer analyzer, AST ast)
          Create a new resolver.
 
Method Summary
protected  void apply(AlternativeAddition p1, FullProduction p2)
          Apply the specified alternative addition to the specified full production.
protected  void apply(AlternativeRemoval p1, FullProduction p2)
          Apply the specified alternative removal to the specified full production.
protected  void apply(ProductionOverride p1, FullProduction p2)
          Apply the specified production override to the specified full production.
protected  void applyModifications(Grammar g)
          Apply any module modifications.
protected  java.util.List<Attribute> check(Grammar g)
          Perform basic checking for the specified grammar.
protected  void checkExplicit(Grammar g)
          Check that explicit productions do not match the empty input.
protected  void checkRecursions(Grammar g)
          Check for left-recursive productions.
protected  void checkRepetitions(Grammar g)
          Check repetitions for elements that accept the empty input.
protected  Module combine(Grammar g, java.util.List<Attribute> attributes)
          Combine the modules in the specified grammar.
protected  void internTypes(Grammar g)
          Intern the grammar's types.
protected  Grammar load(Module m)
          Load all dependent modules.
protected  Module load(java.lang.String name)
          Load the module with the specified name.
protected  void rename(Module module, ModuleMap renaming)
          Rename the specified module.
protected  void signature(Module m)
          Print the specified module's signature.
protected  Production strip(Production p)
          Strip the specified production's ordered choice.
 void visit(Action a)
          Analyze the specified action.
 void visit(Binding b)
          Analyze the specified binding.
 void visit(CharClass c)
          Analyze the specified character class.
 void visit(InternalElement e)
          Analyze the specified internal element.
 java.lang.Object visit(Module m)
          Visit the specified module.
 void visit(NodeMarker m)
          Analyze the specified node marker.
 void visit(NonTerminal nt)
          Analyze the specified nonterminal.
 void visit(NullLiteral l)
          Analyze the specified null literal.
 void visit(Option o)
          Analyze the specified option.
 void visit(OrderedChoice c)
          Analyze the specified ordered choice.
 void visit(ParserAction pa)
          Analyze the specified parser action.
 void visit(Predicate p)
          Analyze the specified predicate.
 void visit(Production p)
          Analyze the specified production.
 void visit(Repetition r)
          Analyze the specified repetition.
 void visit(SemanticPredicate p)
          Analyze the specified semantic predicate.
 void visit(Sequence s)
          Analyze the specified sequence.
 void visit(StringLiteral l)
          Analyze the specified string literal.
 void visit(StringMatch m)
          Analyze the specified string match.
 void visit(Terminal t)
          Analyze the specified terminal.
 void visit(VoidedElement v)
          Analyze 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

runtime

protected final Runtime runtime
The runtime.


analyzer

protected final Analyzer analyzer
The analyzer utility.


ast

protected final AST ast
The type operations.


phase

protected int phase
The current checking phase.


badNTs

protected java.util.Map<NonTerminal,NonTerminal> badNTs
The identity hash map of erroneous nonterminals.


hasState

protected boolean hasState
The flag for whether the current module has a stateful attribute.


isMofunctor

protected boolean isMofunctor
The flag for whether the current module is a mofunctor.


isPredicate

protected boolean isPredicate
Flag for whether the current expression is a predicate.


sequenceNames

protected java.util.Set<SequenceName> sequenceNames
The set of sequence names for the current production.

Constructor Detail

Resolver

public Resolver(Runtime runtime,
                Analyzer analyzer,
                AST ast)
Create a new resolver.

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

signature

protected void signature(Module m)
Print the specified module's signature.

Parameters:
m - The module.

load

protected Module load(java.lang.String name)
               throws java.io.IOException,
                      ParseException
Load the module with the specified name.

Parameters:
name - The name.
Returns:
The corresponding grammar module.
Throws:
IllegalArgmentException - Signals that the file is too large.
java.io.FileNotFoundException - Signals that the file does not exist.
java.io.IOException - Signals an exceptional condition while accessing the file.
ParseException - Signals a parse error.

rename

protected void rename(Module module,
                      ModuleMap renaming)
Rename the specified module. This method renames all module names in the specified module, including the module's name, the module's dependencies, and each production's qualified name (if it is not null).

Parameters:
module - The module.
renaming - The renaming.

strip

protected Production strip(Production p)
Strip the specified production's ordered choice.

Parameters:
p - The production to strip.
Returns:
The specified production.
See Also:
Analyzer.stripChoices(xtc.parser.OrderedChoice)

apply

protected void apply(AlternativeAddition p1,
                     FullProduction p2)
Apply the specified alternative addition to the specified full production.

Parameters:
p1 - The alternative addition.
p2 - The full production.

apply

protected void apply(AlternativeRemoval p1,
                     FullProduction p2)
Apply the specified alternative removal to the specified full production.

Parameters:
p1 - The alternative removal.
p2 - The full production.

apply

protected void apply(ProductionOverride p1,
                     FullProduction p2)
Apply the specified production override to the specified full production.

Parameters:
p1 - The production override.
p2 - The full production.

load

protected Grammar load(Module m)
Load all dependent modules. This method loads the transitive closure of all dependent modules for the specified top-level module and returns the closure as a list, with the specified module being the first list element. It checks that the specified top-level module is not parameterized, that the parameters of parameterized modules are well-formed, that arguments match parameters when instantiating parameterized modules, that different instantiations are consistent with each other, that a module does not have more than one modifies clause, and that module modifications do not result in circular dependencies. This method also reports any file access and parsing errors. Finally, this method fills in the auxiliary modification field for all loaded modules.

Parameters:
m - The module.
Returns:
The corresponding grammar or null in the case of errors.

check

protected java.util.List<Attribute> check(Grammar g)
Perform basic checking for the specified grammar. This method does all correctness checking besides checking the contents of partial productions and checking for left-recursive definitions. Note that this method initializes the analyzer with the specified grammar.

Parameters:
g - The grammar.
Returns:
The list of global attributes, if any.

applyModifications

protected void applyModifications(Grammar g)
Apply any module modifications. This method applies all module modifications appearing in the specified grammar. It also removes unused modules from the grammar. This method assumes that all module dependencies have been successfully resolved, i.e., the specified grammar contains all module dependencies. This method also assumes that each module modification's modification field has been correctly initialized.

Parameters:
g - The grammar.

internTypes

protected void internTypes(Grammar g)
Intern the grammar's types. This method assumes that all module modifications have been applied.

Parameters:
g - The grammar.

checkRecursions

protected void checkRecursions(Grammar g)
Check for left-recursive productions. This method assumes that all module modifications have been applied.

Parameters:
g - The grammar.

checkRepetitions

protected void checkRepetitions(Grammar g)
Check repetitions for elements that accept the empty input. This method assumes that all module modifications have been applied.

Parameters:
g - The grammar.

checkExplicit

protected void checkExplicit(Grammar g)
Check that explicit productions do not match the empty input.

Parameters:
g - The grammar.

combine

protected Module combine(Grammar g,
                         java.util.List<Attribute> attributes)
Combine the modules in the specified grammar. This method combines the modules in the grammar by modifying the grammar's top-level module and then returns that module.

Parameters:
g - The grammar.
attributes - The list of global attributes.
Returns:
The grammar as a single module.

visit

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

Parameters:
m - The module to resolve.
Returns:
A single, self-contained grammar module or null on an error condition.

visit

public void visit(Production p)
Analyze the specified production.


visit

public void visit(OrderedChoice c)
Analyze the specified ordered choice.


visit

public void visit(Repetition r)
Analyze the specified repetition.


visit

public void visit(Option o)
Analyze the specified option.


visit

public void visit(Sequence s)
Analyze the specified sequence.


visit

public void visit(Predicate p)
Analyze the specified predicate.


visit

public void visit(SemanticPredicate p)
Analyze the specified semantic predicate.


visit

public void visit(VoidedElement v)
Analyze the specified voided element.


visit

public void visit(Binding b)
Analyze the specified binding.


visit

public void visit(StringMatch m)
Analyze the specified string match.


visit

public void visit(NonTerminal nt)
Analyze the specified nonterminal.


visit

public void visit(Terminal t)
Analyze the specified terminal.


visit

public void visit(StringLiteral l)
Analyze the specified string literal.


visit

public void visit(CharClass c)
Analyze the specified character class.


visit

public void visit(NullLiteral l)
Analyze the specified null literal.


visit

public void visit(NodeMarker m)
Analyze the specified node marker.


visit

public void visit(Action a)
Analyze the specified action.


visit

public void visit(ParserAction pa)
Analyze the specified parser action.


visit

public void visit(InternalElement e)
Analyze the specified internal element.



Copyright © 2012. All Rights Reserved.