|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object tribble.io.Lr1Parser
public abstract class Lr1Parser
Generic LR(1) parser.
This implements an LR(1) parser, as a deterministic finite automaton (DFA)
with a push-down stack. It reads tokens from an input source stream
(implementing the LexerI
interface).
LexerI
,
Lr1Parser
Field Summary | |
---|---|
protected static short |
_A_ACCEPT
Reserved action number: $accept. |
protected static short |
_A_ERROR
Reserved action number: $error. |
protected short[] |
_ACTION
State transition action table. |
protected short[] |
_ACTION_LOOKUP
State transition lookup table. |
protected boolean |
_debug
Enable debugging tracing output. |
protected short[] |
_GOTO
State reduction goto table. |
protected short[] |
_GOTO_LOOKUP
State reduction goto lookup table. |
protected LexerI |
_lexer
Lexer input stream. |
protected java.lang.String[] |
_NONTERM_ID
Nonterminal symbol names. |
protected java.lang.Object[] |
_nStack
Nonterminal stack, of user-defined type '%stacktype'. |
protected DiagnosticOutputI |
_out
Output stream. |
protected java.lang.Object |
_r
Rule reduction result value ('$$'), of user-defined type '%stacktype'. |
protected short[] |
_RHS_LEN
Rule RHS lengths. |
protected java.lang.String[] |
_RULE_ID
Rule names. |
protected static int |
_SERIES
LR(1) parsing table format number. |
protected java.lang.String |
_sourceName
Input source (file) name. |
protected int |
_sp
Current stack pointer (for all three stacks). |
protected short[] |
_sStack
State stack, containing DFS state numbers. |
protected int |
_state
Current DFA state number. |
protected static short |
_T_ANY
Reserved token code: $any. |
protected static short |
_T_EMPTY
Reserved token code: $empty. |
protected static short |
_T_END
Reserved token code: $end. |
protected static short |
_T_ERROR
Reserved token code: error. |
protected java.lang.String[] |
_TERM_ID
Terminal symbol names. |
protected TokenI |
_tok
Current lookahead token. |
protected int |
_tokCode
Current token code (type). |
protected int |
_tokLine
Current token line number. |
protected TokenI[] |
_tStack
Terminal (token) stack, containing input terminal symbols. |
(package private) static java.lang.String |
REV
Revision information. |
Constructor Summary | |
---|---|
protected |
Lr1Parser(int series)
Constructor. |
protected |
Lr1Parser(int series,
LexerI in)
Constructor. |
Method Summary | |
---|---|
protected abstract void |
_action(int n)
Perform a specific user-defined action for a given grammar rule (production). |
protected int |
_getToken()
Read the next token from the lexer input stream. |
protected boolean |
_resumeParse()
Parse the token input stream, recognizing valid sentences of an LR(1) grammar. |
void |
close()
Close the input stream. |
protected void |
finalize()
Finalization. |
boolean |
parse()
Parse the token input stream, recognizing valid sentences of an LR(1) grammar. |
void |
setInput(LexerI in)
Establish the lexical analyzer (lexer) input stream from which to read tokens during parsing. |
void |
setOutput(DiagnosticOutputI out)
Establish the output stream to which diagnostic messages (warning and error messages) are written during parsing. |
void |
setSourceName(java.lang.String fn)
Establish the input source filename. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final java.lang.String REV
protected static final int _SERIES
protected static final short _T_END
protected static final short _T_ERROR
protected static final short _T_ANY
protected static final short _T_EMPTY
protected static final short _A_ACCEPT
protected static final short _A_ERROR
protected final java.lang.String[] _TERM_ID
protected final java.lang.String[] _NONTERM_ID
protected final java.lang.String[] _RULE_ID
protected final short[] _RHS_LEN
protected final short[] _ACTION_LOOKUP
protected final short[] _ACTION
protected final short[] _GOTO_LOOKUP
protected final short[] _GOTO
protected short[] _sStack
protected TokenI[] _tStack
protected java.lang.Object[] _nStack
protected int _sp
protected int _state
protected java.lang.Object _r
protected TokenI _tok
protected int _tokCode
protected int _tokLine
protected LexerI _lexer
protected java.lang.String _sourceName
protected DiagnosticOutputI _out
protected boolean _debug
Constructor Detail |
---|
protected Lr1Parser(int series)
series
- LR(1) parser table format number. This must be compatible with
_SERIES
.protected Lr1Parser(int series, LexerI in)
series
- LR(1) parser table format number. This must be compatible with
_SERIES
.in
- The lexer input stream from which to read tokens.Method Detail |
---|
public void setOutput(DiagnosticOutputI out)
setOutput
in interface DiagnosticWriterI
out
- The error output stream.public void setInput(LexerI in)
setInput
in interface ParserI
in
- The lexer input stream from which to read tokens.public void setSourceName(java.lang.String fn)
setSourceName
in interface ParserI
fname
- The source filename.public void close()
It is typically not necessary to invoke this method since the input stream is usually closed automatically once parsing has completed, unless it is necessary to close the input stream deliberately or prematurely.
Note that this method does not throw any exceptions.
close
in interface ParserI
public boolean parse() throws java.lang.Exception
...
parse
in interface ParserI
java.lang.Exception
- Thrown if an I/O error or parsing error occurs.protected boolean _resumeParse() throws java.lang.Exception
java.lang.Exception
- Thrown if an I/O error or parsing error occurs.protected int _getToken() throws java.io.IOException
_tokCode
to the same token code, and sets
_tok
to the token object just read.
java.io.IOException
protected abstract void _action(int n) throws java.lang.Exception
n
- The rule (production) number of the associated code block.
java.lang.Exception
- Thrown if an error (i.e., a semantic error) occurs.protected void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |