Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.2.0)

E17493-03


oracle.javatools.parser
Class AbstractSyntaxRecognizer

java.lang.Object
  extended by oracle.javatools.parser.AbstractSyntaxRecognizer

Direct Known Subclasses:
PlsqlSyntaxRecognizer

public abstract class AbstractSyntaxRecognizer
extends java.lang.Object

The 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.

See Also:
Lexer

Field Summary
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 Summary
AbstractSyntaxRecognizer()
           

 

Method Summary
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.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Field Detail

SYNTAX_EOF

public static final int SYNTAX_EOF
Constant indicating that there are no more tokens remaining because the SyntaxRecognizer reached the end of the file.
See Also:
Constant Field Values

SYNTAX_ERROR

public static final int SYNTAX_ERROR
Constant indicating a syntax error construct.
See Also:
Constant Field Values

SYNTAX_ROOT

public static final int SYNTAX_ROOT
Constant indicating the root syntax construct.
See Also:
Constant Field Values

TK_EOF

public static final int TK_EOF
Convenience constant.
See Also:
Constant Field Values

debugLevel

protected int debugLevel
The debug level. Only affects how syntax errors are handled and reported.

DEBUG_OUTPUT

public static final boolean DEBUG_OUTPUT
Whether to print debug output for internal errors to the console. This should be set to false except in development environments.
See Also:
Constant Field Values

lexer

protected Lexer lexer
The Lexer object providing the token stream.

curLexerToken

protected LexerToken curLexerToken
The current LexerToken being examined by the grammar engine.

peekingToken

protected LexerToken peekingToken
The LexerToken used for peeking.

curToken

protected int curToken
The token value of the current lexed token.

listener

protected SyntaxListener listener
The object listening for the stream of syntax tokens.

DEBUGLEVEL_MINIMAL

public static final int DEBUGLEVEL_MINIMAL
This is the default debug level. All syntax errors generate runtime exceptions. The error msg can be retrieved via RuntimeException.toString().
See Also:
Constant Field Values

DEBUGLEVEL_HIGH

public static final int DEBUGLEVEL_HIGH
This is the detailed debug level. All syntax errors are reported as syntax tokens. The error msg can be retrieved via 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.

See Also:
Constant Field Values

INTERNALERR_BACKUP_NOT_IMPLEMENTED_YET

protected static final java.lang.String INTERNALERR_BACKUP_NOT_IMPLEMENTED_YET
See Also:
Constant Field Values

INTERNALERR_BACKEDUP_TWICE

protected static final java.lang.String INTERNALERR_BACKEDUP_TWICE
See Also:
Constant Field Values

INTERNALERR_CANT_ACCESS_LEXER_TOKEN_ON_BACKUP

protected static final java.lang.String INTERNALERR_CANT_ACCESS_LEXER_TOKEN_ON_BACKUP
See Also:
Constant Field Values

SYNTAXERR_SKIPPING

public static final java.lang.String SYNTAXERR_SKIPPING

resources

protected static final oracle.javatools.resource.BundleHelper resources

Constructor Detail

AbstractSyntaxRecognizer

public AbstractSyntaxRecognizer()

Method Detail

getDebugLevel

public int getDebugLevel()

setDebugLevel

public void setDebugLevel(int debugLevel)

getLexer

public Lexer getLexer()

initialize

public void initialize(Lexer lexer)
Initializes the SyntaxRecognizer.

initialize

public void initialize(ReadTextBuffer buffer)
Initializes the SyntaxRecognizer with a preferred lexer.

initialize

public void initialize(ReadTextBuffer buffer,
                       int startOffset)
Initializes the SyntaxRecognizer with a preferred lexer to start at the given start offset.

setListener

public void setListener(SyntaxListener listener)

parse

public abstract void parse()
Does the parse. Should not emit the SYNTAX_ROOT beginning to start off, but it should emit the SYNTAX_ROOT ending at the end.

instantiatePreferredLexer

public abstract Lexer instantiatePreferredLexer()
Subclasses should instantiate and customize preferred lexers here.

getCode

protected int getCode()

getDataValue

protected int getDataValue()

setDataValue

protected void setDataValue(int data)

getContextString

protected java.lang.String getContextString()

setContextString

protected void setContextString(java.lang.String contextString)

copyStartOffset

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. Example use: While parsing a class in a Java file, the modifiers precede the field/method declaration. Until we get past the modifiers we won't know which type of parse tree symbol to instantiate. But we need some sort of "holder" parse tree symbol to catch the modifiers when they fly by. Thus, we start a parent "holder" symbol, parse modifiers, and then copy the start offset of the parent when we create either the method or field parse tree symbol as a child of the "holder".

curTokenToString

protected java.lang.String curTokenToString()
Some parser grammars switch on identifiers that are not keywords. For example, in PL/SQL, "replace" is not a keyword, but requires special handling in the parser. This is intended to be used in those cases.

peekToken

protected final int peekToken()
Lookaheand one token.

nextToken

protected final boolean nextToken(int token)
Require the current token to be equal to the parameter value. If yes, skip it. If no, generate a syntax error.

nextToken

protected final boolean nextToken(int primary,
                                  int secondary)
If neither is present, the error-expecting syntax error will be thrown for the primary token.

optionalToken

protected final boolean optionalToken(int token)
Skips the current token if equal to the parameter value. Does nothing otherwise.
Returns:
True if a token was skipped. False otherwise.

skipToken

protected final void skipToken()
Skips the current token.

start

protected final void start(int code)
Begins a new production and generates a token.

startQuiet

protected final void startQuiet(int code)
Begins a new production and does not generate a token.

finishInherit

protected final void finishInherit()
Finishes the current production and inherits its end offset from the last child.

finish

protected final void finish()
Finishes the current production and takes the current token as its last token, but does NOT advance the lexer. Should very rarely be used...

finishToken

protected final void finishToken()
Finishes the current production and takes the current token as its last token. Advances the lexer.

finishToken

protected final void finishToken(int token)
Finishes the current production and takes the current token as its last token. Requires that the last token be of a certain value. If yes, advances the lexer. If no, it generates an error-expecting syntax error and does not advance the lexer.

finishToken

protected final void finishToken(int primary,
                                 int secondary)
Just like nextToken( int, int ) except that we're finishing. So, if the current token is either the primary or secondary, we finish with the current token as the last token. If not, it generates an error-expecting syntax error on the primary token and does not advance the lexer.

_codeToString

public java.lang.String _codeToString(int syntaxCode)
Converts the syntax code into a string.

errorCheckpoint

protected final 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. So, what we do here is introduce some sort of checkpoint. If we ever checkpoint twice on the same lexer token, then this will generate an errorUnexpected.

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)

Returns:
True if the checkpoint is fine, i.e. no error was generated. This happens if this is the first time we're checkpointing on this lexer token. False otherwise.

notImplementedYet

protected void notImplementedYet(java.lang.String msg)
Generic way of throwing a "Not implemented yet" error.

errorExpecting

protected void errorExpecting(int token)
Generates an error-expecting token. Sub-classes should override and report a more descriptive syntax error.

errorUnexpected

protected void errorUnexpected()
Generates an error-unexpected token. This typically occurs when you have a token that makes absolutely no sense in the current context and so we're going to try to consume it and move on in life.

errorUnexpected

protected void errorUnexpected(boolean consumeToken)
Generates an error-unexpected token. Consumes a token if directed to do so.

errorEof

protected final void errorEof()
Generates an unexpected-EOF token.

reportSyntaxError

protected void reportSyntaxError(java.lang.String errorMsg)
Used by the grammar engine to report a syntax error.
See Also:
reportSyntaxError(java.lang.String, int, boolean)

reportSyntaxError

protected void reportSyntaxError(java.lang.String errorMsg,
                                 boolean useLastTokenOffset)
Used by the grammar engine to report a syntax error.
See Also:
reportSyntaxError(java.lang.String, int, boolean)

reportSyntaxError

protected void reportSyntaxError(java.lang.String errorMsg,
                                 int dataValue,
                                 boolean useLastTokenOffset)
Used by the grammar engine to report a syntax error.
Parameters:
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.

internalError

protected void internalError(java.lang.String errorMsg)
Report an internal error. This also provides the syntax code, resolve level, and current token in the error output.

_assert

protected void _assert(boolean condition)
Very simple assert call.

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.2.0)

E17493-03


Copyright © 1997, 2012, Oracle. All rights reserved.