com.inxar.syntacs.translator.lr
Class StandardLRTranslatorInterpreter

java.lang.Object
  |
  +--com.inxar.syntacs.translator.lr.AbstractLRTranslationComponent
        |
        +--com.inxar.syntacs.translator.lr.StandardLRTranslatorInterpreter
All Implemented Interfaces:
LexerInterpreter, LRTranslationComponent, LRTranslatorInterpreter, ParserInterpreter
Direct Known Subclasses:
RegexpInterpreter, SyntacsInterpreter

public class StandardLRTranslatorInterpreter
extends AbstractLRTranslationComponent
implements LRTranslatorInterpreter

Concrete implementation of LRInterpreter.


Constructor Summary
StandardLRTranslatorInterpreter()
          Constructs the StandardLRInterpreter.
 
Method Summary
 void accept()
          This method will be called by the parser when the ACCEPT instruction occurs.
 int error(int off, int len)
          Notify an error starting at the given offset having the given length.
 Parser getParser()
          Gets the Parser object which this LexerInterpreter may relay Symbol events to.
 Object getResult()
          When translation is complete and there were no unrecoverable errors, the LRTranslatorInterpreter should be able to produce some Object which was built from the parse tree.
 void match(int type, int off, int len)
          The match method is used by the Lexer to inform the interpreter that a new token has been found at the given offset with the given length.
 Recovery recover(int type, Sentence left_context)
          This method will be called by the parser when an ERROR instruction is hit.
 Symbol reduce(int type, Sentence sentence)
          ParserInterpreter.reduce(int, Sentence) is called when a reduction occurs.
 void setParser(Parser parser)
          Sets the Parser object to which this LexerInterpreter may relay Symbol events to.
 void stop()
          Notify that the end of the Input has been reached.
 
Methods inherited from class com.inxar.syntacs.translator.lr.AbstractLRTranslationComponent
getAuditor, getInput, getLRTranslatorGrammar, getProperties, initialize, reset, setAuditor, setInput, setLRTranslatorGrammar, setProperties
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.inxar.syntacs.translator.lr.LRTranslationComponent
getAuditor, getInput, getLRTranslatorGrammar, getProperties, initialize, reset, setAuditor, setInput, setLRTranslatorGrammar, setProperties
 

Constructor Detail

StandardLRTranslatorInterpreter

public StandardLRTranslatorInterpreter()
Constructs the StandardLRInterpreter.
Method Detail

match

public void match(int type,
                  int off,
                  int len)
           throws TranslationException
Description copied from interface: LexerInterpreter
The match method is used by the Lexer to inform the interpreter that a new token has been found at the given offset with the given length.
Specified by:
match in interface LexerInterpreter

error

public int error(int off,
                 int len)
          throws TranslationException
Description copied from interface: LexerInterpreter
Notify an error starting at the given offset having the given length. The return value is a code which instructs the lexer how to recover. Since there is currently no lexical error recovery implemented, the return value is meaningless.
Specified by:
error in interface LexerInterpreter

stop

public void stop()
          throws TranslationException
Description copied from interface: LexerInterpreter
Notify that the end of the Input has been reached.
Specified by:
stop in interface LexerInterpreter

setParser

public void setParser(Parser parser)
Description copied from interface: LexerInterpreter
Sets the Parser object to which this LexerInterpreter may relay Symbol events to.
Specified by:
setParser in interface LexerInterpreter

getParser

public Parser getParser()
Description copied from interface: LexerInterpreter
Gets the Parser object which this LexerInterpreter may relay Symbol events to.
Specified by:
getParser in interface LexerInterpreter

reduce

public Symbol reduce(int type,
                     Sentence sentence)
              throws TranslationException
Description copied from interface: ParserInterpreter
ParserInterpreter.reduce(int, Sentence) is called when a reduction occurs. The type of the reduction (from the grammar) as well as the top of the parse stack is passed to the method. The ParserInterpreter is expected to construct a Symbol and return it back to the Parser (to be placed at the top of the parse stack).
Specified by:
reduce in interface ParserInterpreter

recover

public Recovery recover(int type,
                        Sentence left_context)
                 throws TranslationException
Description copied from interface: ParserInterpreter
This method will be called by the parser when an ERROR instruction is hit. The argument is the Symbol type that was being parsed at the time of error. The return value should be a Symbol to try instead of the one that invoked the error. If the return value is null, the error will be ignored. If the return value is not null and another error is encountered, one symbol will be removed from the stack and the parser will try again wil the given return symbol. This will happen recursively until the error is resolved and the parse can continue or the stack is empty.
Specified by:
recover in interface ParserInterpreter

accept

public void accept()
            throws TranslationException
Description copied from interface: ParserInterpreter
This method will be called by the parser when the ACCEPT instruction occurs.
Specified by:
accept in interface ParserInterpreter

getResult

public Object getResult()
Description copied from interface: LRTranslatorInterpreter
When translation is complete and there were no unrecoverable errors, the LRTranslatorInterpreter should be able to produce some Object which was built from the parse tree. This Object will be returned by the Translator if appropriate.
Specified by:
getResult in interface LRTranslatorInterpreter