| java.lang.Object xtc.tree.Visitor xtc.parser.Annotator
Annotator | public class Annotator extends Visitor (Code) | | Visitor to inject source code annotations into a grammar.
This visitor distinguishes between bindable elements, i.e.,
elements that would contribute to the value of a generic
production, and valuable element, i.e., elements that can be
rewritten to have a semantic value. The latter include voided
elements and references to void productions that consume the input.
For directly left-recursive alternatives in generic
productions, this visitor may annotate the last sequence with the
Properties.FORMATTING property, indicating valuable
elements that need to be captured in the promise generated by
DirectLeftRecurser .
This visitor assumes that the entire grammar is contained in a
single module, that the grammar has been tokenized, and that
productions that may consume the input have been marked.
See Also: Tokenizer See Also: Analyzer.consumesInput(Element) author: Robert Grimm version: $Revision: 1.30 $ |
Inner Class :public static class Index | |
Inner Class :public static class IndexPair | |
Inner Class :public class Detector extends Visitor | |
Inner Class :public class Rewriter extends Visitor | |
Field Summary | |
final public static String | MARKER The marker for synthetic variables. | protected List<List<Binding>> | after The list of bindings for valuable elements after the regular,
bindable value, organized as a stack of copies. | final protected Analyzer | analyzer The analyzer. | protected List<List<Binding>> | before The list of bindings for valuable elements before the regular,
bindable value, organized as a stack of copies. | protected List<Index> | elementIdx The index of the regular, bindable value, organized as a stack of
copies. | protected boolean | isGeneric The flag for whether the current production is generic. | protected boolean | isList The flag for whether the current production is list-valued. | protected boolean | isRecursive The flag for whether the current production or sequence is
directly left-recursive. | protected boolean | isTopLevel The flag for whether the current choice is top-level. | final protected Runtime | runtime The runtime. | protected List<Index> | sequenceIdx The index of the sequence with the regular, bindable value,
organized as a stack of copies. | protected List<Sequence> | sequences The elements as a list of sequences. | protected int | toProcessIdx The index of the next sequence to process. |
Method Summary | |
protected List<Binding> | after() Get the current list of bindings after the regular value. | protected void | annotate() Process all elements in the current list of sequences. | protected List<Binding> | before() Get the current list of bindings before the regular value. | protected VoidedElement | bindAndVoid(Element e) Bind and void the specified element. | protected Binding | bindAndVoid() Bind and void the current regular, bindable element. | protected Index | elementIndex() Get the current element index of the regular value. | protected boolean | hasBindable() Determine whether a bindable element has been processed. | protected boolean | hasValuable() Determine whether any valuable elements have been processed. | protected boolean | isBoundAndVoided(Element e) Determine whether the specified element already is bound and
voided.
Parameters: e - The element. | public static boolean | isGeneric(FullProduction p) Determine whether the specified production effectively is
generic. | public static boolean | isList(Type type) Determine whether the specified type is a list type that can be
processed by this visitor.
Parameters: type - The type. | protected boolean | isParseTreeNode(Element e) Determine whether the specified element is a possibly bound or
voided parse tree node.
Parameters: e - The element. | public static boolean | isSingleRepetition(FullProduction p) Determine whether the specified production recognizes only a
single repetition. | protected boolean | isValuable(Element e) Determine whether the specified element is valuable. | public static boolean | isValuable(FullProduction p) Determine whether the specified production can have a semantic
value. | protected void | pop() Pop the top elements from the state for tracking bindable and
valuable elements. | protected void | push() Push a copy of the state for tracking bindable and valuable
elements. | protected void | recurse(Element e) Recursively process the specified element. | protected void | reset() Reset the current state for tracking bindable and valuable
elements. | protected Index | sequenceIndex() Get the current sequence index of the regular value. | public void | visit(Module m) Visit the specified grammar. | public void | visit(FullProduction p) Visit the specified production. | public void | visit(OrderedChoice c) Visit the specified choice. | public void | visit(Sequence s) Visit the specified sequence. |
MARKER | final public static String MARKER(Code) | | The marker for synthetic variables.
|
elementIdx | protected List<Index> elementIdx(Code) | | The index of the regular, bindable value, organized as a stack of
copies. A value of -1 indicates no bindable value.
See Also: Annotator.toProcessIdx |
isGeneric | protected boolean isGeneric(Code) | | The flag for whether the current production is generic.
|
isList | protected boolean isList(Code) | | The flag for whether the current production is list-valued.
|
isRecursive | protected boolean isRecursive(Code) | | The flag for whether the current production or sequence is
directly left-recursive.
|
isTopLevel | protected boolean isTopLevel(Code) | | The flag for whether the current choice is top-level.
|
sequenceIdx | protected List<Index> sequenceIdx(Code) | | The index of the sequence with the regular, bindable value,
organized as a stack of copies. A value of -1 indicates no
bindable value.
See Also: Annotator.toProcessIdx |
toProcessIdx | protected int toProcessIdx(Code) | | The index of the next sequence to process. The stacks capturing
the state for tracking bindable and valuable must have as many
elements as indicated by this index.
|
Annotator | public Annotator(Runtime runtime, Analyzer analyzer)(Code) | | Create a new annotator.
Parameters: runtime - The runtime. Parameters: analyzer - The analyzer utility. |
after | protected List<Binding> after()(Code) | | Get the current list of bindings after the regular value.
The current list of bindings. |
annotate | protected void annotate()(Code) | | Process all elements in the current list of sequences.
|
before | protected List<Binding> before()(Code) | | Get the current list of bindings before the regular value.
The current list of bindings. |
bindAndVoid | protected VoidedElement bindAndVoid(Element e)(Code) | | Bind and void the specified element. The specified element must
be valuable, i.e., can be rewritten to yield a semantic value.
See Also: Annotator.isValuable(Element) Parameters: e - The element. The voided, bound element. |
bindAndVoid | protected Binding bindAndVoid()(Code) | | Bind and void the current regular, bindable element.
The binding. |
elementIndex | protected Index elementIndex()(Code) | | Get the current element index of the regular value.
The current element index. |
hasBindable | protected boolean hasBindable()(Code) | | Determine whether a bindable element has been processed.
See Also: Analyzer.isBindable(Element) true if a bindable element has beenprocessed. |
hasValuable | protected boolean hasValuable()(Code) | | Determine whether any valuable elements have been processed.
See Also: Annotator.isValuable(Element) true if any valuable elements have beenprocessed. |
isBoundAndVoided | protected boolean isBoundAndVoided(Element e)(Code) | | Determine whether the specified element already is bound and
voided.
Parameters: e - The element. true if the specified element already isbound and voided. |
isGeneric | public static boolean isGeneric(FullProduction p)(Code) | | Determine whether the specified production effectively is
generic. This method returns true if the specified
production is, in fact, generic or it is a void production that
also is non-lexical and consumes the input.
See Also: Generifier.isGeneric(FullProduction) Parameters: p - The production. true if the specified production should betreated as generic. |
isList | public static boolean isList(Type type)(Code) | | Determine whether the specified type is a list type that can be
processed by this visitor.
Parameters: type - The type. true if the specified type is a list typethat can be processed by this visitor. |
isParseTreeNode | protected boolean isParseTreeNode(Element e)(Code) | | Determine whether the specified element is a possibly bound or
voided parse tree node.
Parameters: e - The element. true if the specified element is a parsetree node. |
isSingleRepetition | public static boolean isSingleRepetition(FullProduction p)(Code) | | Determine whether the specified production recognizes only a
single repetition. This method returns true if the
specified production returns a list of objects, nodes, generic
nodes, tokens, or strings and each alternative consists of only a
single, optionally bound repetition.
Parameters: p - The production. true if the specified production recognizesonly a single repetition. |
isValuable | protected boolean isValuable(Element e)(Code) | | Determine whether the specified element is valuable. This method
returns true if the specified element has a semantic
value or can be rewritten to yield a semantic value. Rewriting
includes eliminating any voided element or converting a void
production into a production returning a semantic value.
Parameters: e - The element. true if the specified element is valuable. |
isValuable | public static boolean isValuable(FullProduction p)(Code) | | Determine whether the specified production can have a semantic
value. Any production that is not void or that consumes the
input can have a semantic value. This method assumes that
productions have been correctly annotated with the
Properties.INPUT property.
Parameters: p - The production. true if the specified production can have asemantic value. |
pop | protected void pop()(Code) | | Pop the top elements from the state for tracking bindable and
valuable elements.
|
push | protected void push()(Code) | | Push a copy of the state for tracking bindable and valuable
elements. This method pushes copies of the top elemens of the
tracking state onto the respective stacks. If the stacks are
empty, it initializes the lists of bindings with empty lists and
the indices with -1.
|
recurse | protected void recurse(Element e)(Code) | | Recursively process the specified element.
Parameters: e - The element. |
reset | protected void reset()(Code) | | Reset the current state for tracking bindable and valuable
elements. This method replaces the current lists of bindings
with new, empty lists and sets the current indices to -1.
|
sequenceIndex | protected Index sequenceIndex()(Code) | | Get the current sequence index of the regular value.
The current sequence index. |
visit | public void visit(Module m)(Code) | | Visit the specified grammar.
|
visit | public void visit(Sequence s)(Code) | | Visit the specified sequence.
|
|
|