xtc.parser

Class Analyzer

  • A mapping from module names to modules, which is initialized through init(Grammar) and accessed through lookup(String) and lookup(ModuleName). After initialization, the grammar can be accessed through grammar().

  • A mapping from nonterminals to productions, which is initialized either through init(Grammar) or init(Module) and accessed through lookup(NonTerminal), lookup(NonTerminal,Module), and lookupGlobally(NonTerminal). When initializing this mapping through a grammar, relative look ups can only be performed within the context of processing a module. Note that the mapping contains both qualified and unqualified names.

  • Methods to test for and access the top-level (or root) module of a grammar.

  • Methods to add and remove modules. These methods update both the mapping from module names to modules and from nonterminals to productions, but they do not update the current grammar.

  • Methods to test whether a module is imported by another, to trace a module's dependencies, and to test whether a module or any of its dependencies has a specified attribute.

  • Methods to test whether a production is defined by a module and to test whether a production is imported by a module.

  • Methods to start processing a module and to determine the current module; additionally, methods to switch to a different module and switch back again when processing productions from several modules.

  • A method to uniquely uniquify() the names of all productions across all modules.

  • Methods to start processing a production and to determine the current production.

  • A working set, marked set, and processed set to determine properties of productions. The idea behind these three sets is that the working set keeps track of all productions during an analysis pass and is used to prevent infinite recursions, the marked set tracks the productions having the property, and the processed set (which typically is a superset of the marked set) tracks the analyzed productions. The working set is accessed through workingOn(NonTerminal), notWorkingOn(NonTerminal), notWorkingOnAny(), isBeingWorkedOn(NonTerminal), and working(). The marked set is accessed through mark(NonTerminal), mark(Collection), markAll(), unmark(NonTerminal), unmarkAll(), hasMarked(), isMarked(NonTerminal), and marked(). Finally, the processed set is accessed through clearProcessed(), processed(NonTerminal), and isProcessed(NonTerminal). Note that all nonterminals used in these sets should be fully qualified.

  • Methods to add and remove productions from a grammar. New productions are prepared for addition through add(FullProduction) and committed to the grammar through addNewProductionsAt(int). Existing productions are removed through remove(FullProduction).

  • A set of methods for creating synthetic variable names and nonterminals for new productions: variable(), split(), choice(), star(), plus(), option(), tail(), and shared(). Also, a method to test whether a given variable or nonterminal is synthetic. Besides shared variables, synthetic variables can only be created while processing a production.

  • A method to strip unnecessary ordered choices and sequences from an element and a method to strip only ordered choices.

  • A method to copy an element.

  • A set of methods for optimizing sequences that start with terminals through character switches: hasTerminalPrefix(Sequence), normalizeTerminals(Sequence), and joinTerminals(Sequence,Element).

  • The corresponding set of methods for folding common prefixes: haveCommonPrefix(Sequence,Sequence), normalizePrefix(Sequence,Sequence), and joinPrefixes(Sequence,Element).

  • A method to get the text of an element.

  • A method to determine whether an element restricts the input.

  • A method to determine whether an element consumes the input.

  • A method to determine whether an element matches the empty input.

  • A method to determine whether an element relies only on not-followed-by predicates.

  • A set of methods to process bindings, notably a method to determine whether an element can be bound, a method to add a binding to a list of elements, a method to access the only binding in a list of elements, and methods to unbind and strip and unbind an element.

  • A method to get a list's value.
  • Two methods to determine whether an element or a list sets the semantic value, either through a binding, semantic action, or value element. Another method to determine whether a list sets the semantic value to null.

  • A method to determine whether an element's list value may be null.

  • A method to type an element.

  • To utilize this analyzer, the utility must be initialized with a grammar or a module and the visitor must be registered. When processing modules in a grammar, this utility must be notified. When processing productions, this utility must also be notified.

    The analyzer utility tracks the current grammar or module so that it need not recreate its internal state as long as the same analyzer utility is used across different visitors.

    Version:
    $Revision: 1.147 $
    Author:
    Robert Grimm

    Copyright © 2014. All Rights Reserved.