public abstract class AbstractSyntaxRecognizer
extends java.lang.Object
AbstractSyntaxRecognizer
is a basic abstract
implementation which takes care of common functionality across
SyntaxRecognizers for LL(1) parsers. It's primarily designed
as an error-tolerant parser framework.Lexer
Modifier and Type | Field and Description |
---|---|
protected LexerToken |
curLexerToken
The current LexerToken being examined by the grammar engine.
|
protected int |
curToken
The token value of the current lexed token.
|
static boolean |
DEBUG_OUTPUT
Whether to print debug output for internal errors to the console.
|
protected int |
debugLevel
The debug level.
|
static int |
DEBUGLEVEL_HIGH
This is the detailed debug level.
|
static int |
DEBUGLEVEL_MINIMAL
This is the default debug level.
|
protected static java.lang.String |
INTERNALERR_BACKEDUP_TWICE |
protected static java.lang.String |
INTERNALERR_BACKUP_NOT_IMPLEMENTED_YET |
protected static java.lang.String |
INTERNALERR_CANT_ACCESS_LEXER_TOKEN_ON_BACKUP |
protected Lexer |
lexer
The Lexer object providing the token stream.
|
protected SyntaxListener |
listener
The object listening for the stream of syntax tokens.
|
protected LexerToken |
peekingToken
The LexerToken used for peeking.
|
protected static oracle.javatools.resource.BundleHelper |
resources |
static int |
SYNTAX_EOF
Constant indicating that there are no more tokens remaining
because the SyntaxRecognizer reached the end of the file.
|
static int |
SYNTAX_ERROR
Constant indicating a syntax error construct.
|
static int |
SYNTAX_ROOT
Constant indicating the root syntax construct.
|
static java.lang.String |
SYNTAXERR_SKIPPING |
static int |
TK_EOF
Convenience constant.
|
Constructor and Description |
---|
AbstractSyntaxRecognizer() |
Modifier and Type | Method and Description |
---|---|
protected void |
_assert(boolean condition)
Very simple assert call.
|
java.lang.String |
_codeToString(int syntaxCode)
Converts the syntax code into a string.
|
protected void |
copyStartOffset()
Saves the start offset of the top production so that the next child
(presumably created with the current top as the parent) will inherit
the same start offset.
|
protected java.lang.String |
curTokenToString()
Some parser grammars switch on identifiers that are not
keywords.
|
protected boolean |
errorCheckpoint()
The idea is that on certain syntactic elements, we'll just go 'round
and 'round saying, "Expecting this" or "Expecting that" and never
actually consuming a token.
|
protected void |
errorEof()
Generates an unexpected-EOF token.
|
protected void |
errorExpecting(int token)
Generates an error-expecting token.
|
protected void |
errorUnexpected()
Generates an error-unexpected token.
|
protected void |
errorUnexpected(boolean consumeToken)
Generates an error-unexpected token.
|
protected void |
finish()
Finishes the current production and takes the current token as
its last token, but does NOT advance the lexer.
|
protected void |
finishInherit()
Finishes the current production and inherits its end offset from
the last child.
|
protected void |
finishToken()
Finishes the current production and takes the current token as
its last token.
|
protected void |
finishToken(int token)
Finishes the current production and takes the current token as
its last token.
|
protected void |
finishToken(int primary,
int secondary)
Just like nextToken( int, int ) except that we're finishing.
|
protected int |
getCode() |
protected java.lang.String |
getContextString() |
protected int |
getDataValue() |
int |
getDebugLevel() |
Lexer |
getLexer() |
void |
initialize(Lexer lexer)
Initializes the SyntaxRecognizer.
|
void |
initialize(ReadTextBuffer buffer)
Initializes the SyntaxRecognizer with a preferred lexer.
|
void |
initialize(ReadTextBuffer buffer,
int startOffset)
Initializes the SyntaxRecognizer with a preferred lexer to
start at the given start offset.
|
abstract Lexer |
instantiatePreferredLexer()
Subclasses should instantiate and customize preferred lexers
here.
|
protected void |
internalError(java.lang.String errorMsg)
Report an internal error.
|
protected boolean |
nextToken(int token)
Require the current token to be equal to the parameter value.
|
protected boolean |
nextToken(int primary,
int secondary)
If neither is present, the error-expecting syntax error will be
thrown for the primary token.
|
protected void |
notImplementedYet(java.lang.String msg)
Generic way of throwing a "Not implemented yet" error.
|
protected boolean |
optionalToken(int token)
Skips the current token if equal to the parameter value.
|
abstract void |
parse()
Does the parse.
|
protected int |
peekToken()
Lookaheand one token.
|
protected void |
reportSyntaxError(java.lang.String errorMsg)
Used by the grammar engine to report a syntax error.
|
protected void |
reportSyntaxError(java.lang.String errorMsg,
boolean useLastTokenOffset)
Used by the grammar engine to report a syntax error.
|
protected void |
reportSyntaxError(java.lang.String errorMsg,
int dataValue,
boolean useLastTokenOffset)
Used by the grammar engine to report a syntax error.
|
protected void |
setContextString(java.lang.String contextString) |
protected void |
setDataValue(int data) |
void |
setDebugLevel(int debugLevel) |
void |
setListener(SyntaxListener listener) |
protected void |
skipToken()
Skips the current token.
|
protected void |
start(int code)
Begins a new production and generates a token.
|
protected void |
startQuiet(int code)
Begins a new production and does not generate a token.
|
public static final int SYNTAX_EOF
public static final int SYNTAX_ERROR
public static final int SYNTAX_ROOT
public static final int TK_EOF
protected int debugLevel
public static final boolean DEBUG_OUTPUT
protected Lexer lexer
protected LexerToken curLexerToken
protected LexerToken peekingToken
protected int curToken
protected SyntaxListener listener
public static final int DEBUGLEVEL_MINIMAL
RuntimeException.toString()
.public static final int DEBUGLEVEL_HIGH
SyntaxToken.getContextString()
. We may possibly want to add more granularity in debug level later on, but right now, it's pretty binary, throw an exception or notify of an error and continue.
protected static final java.lang.String INTERNALERR_BACKUP_NOT_IMPLEMENTED_YET
protected static final java.lang.String INTERNALERR_BACKEDUP_TWICE
protected static final java.lang.String INTERNALERR_CANT_ACCESS_LEXER_TOKEN_ON_BACKUP
public static final java.lang.String SYNTAXERR_SKIPPING
protected static final oracle.javatools.resource.BundleHelper resources
public int getDebugLevel()
public void setDebugLevel(int debugLevel)
public Lexer getLexer()
public void initialize(Lexer lexer)
public void initialize(ReadTextBuffer buffer)
public void initialize(ReadTextBuffer buffer, int startOffset)
public void setListener(SyntaxListener listener)
public abstract void parse()
public abstract Lexer instantiatePreferredLexer()
protected int getCode()
protected int getDataValue()
protected void setDataValue(int data)
protected java.lang.String getContextString()
protected void setContextString(java.lang.String contextString)
protected void copyStartOffset()
protected java.lang.String curTokenToString()
protected final int peekToken()
protected final boolean nextToken(int token)
protected final boolean nextToken(int primary, int secondary)
protected final boolean optionalToken(int token)
protected final void skipToken()
protected final void start(int code)
protected final void startQuiet(int code)
protected final void finishInherit()
protected final void finish()
protected final void finishToken()
protected final void finishToken(int token)
protected final void finishToken(int primary, int secondary)
public java.lang.String _codeToString(int syntaxCode)
protected final boolean errorCheckpoint()
I came up with the term "error checkpoint" because I didn't know what the heck else to call it. :P (acyu 9/19/2002)
protected void notImplementedYet(java.lang.String msg)
protected void errorExpecting(int token)
protected void errorUnexpected()
protected void errorUnexpected(boolean consumeToken)
protected final void errorEof()
protected void reportSyntaxError(java.lang.String errorMsg)
protected void reportSyntaxError(java.lang.String errorMsg, boolean useLastTokenOffset)
protected void reportSyntaxError(java.lang.String errorMsg, int dataValue, boolean useLastTokenOffset)
dataValue
- The data value to associate with the syntax error.inheritEndOffset
- Use the end offset of the last token + 1. For
example, when reporting a java "Expecting ;" error, you want
the error offset to be where you expect the semicolon to be,
i.e. right after the last token. Don't set the offset to be
the next token as is expected usually.protected void internalError(java.lang.String errorMsg)
protected void _assert(boolean condition)