org.inxar.syntacs.analyzer.syntactic
Interface Sentence


public interface Sentence

The Sentence interface is essentially a view into the top of the LR parse stack. For example, assume that the following production has been defined in the grammar: Term := OPEN_PAREN Expr CLOSE_PAREN. When the Parser discovers this production and attempts to reduce the parse stack, it passes those three Symbols in a Sentence to the ParserInterpreter. OPEN_PAREN would be located at position 0, Expr at position 1, and CLOSE_PAREN at position 2 in the Sentence. The ParserInterpreter would most likely not care about the PAREN symbols, create a Symbol for Term, and pass it back to the Parser.


Method Summary
 Symbol at(int index)
          Returns the Symbol at the nth visible position of the stack such that position 0 is the top of the stack.
 Symbol get(int index)
          Returns the Symbol at the nth visible position of the stack such that position n is the shallowest part of the stack.
 int length()
          Returns the length of the Sentence, aka the exposed portion of the stack for this reduction.
 

Method Detail

at

public Symbol at(int index)
Returns the Symbol at the nth visible position of the stack such that position 0 is the top of the stack. Therefore, the largest index contains the least recently pushed item (the bottom). This is useful when indexing the parse stack during a reduction as it mirrors the definition of a production rather then the reverse.

get

public Symbol get(int index)
Returns the Symbol at the nth visible position of the stack such that position n is the shallowest part of the stack. Therefore, the largest index contains the most recently pushed item. This is useful when evaluating left context.

length

public int length()
Returns the length of the Sentence, aka the exposed portion of the stack for this reduction. The length of a Sentence is determined by the number of symbols on the right-hand-side of a production.