Package antlr
Class Parser
- java.lang.Object
-
- antlr.Parser
-
- Direct Known Subclasses:
LLkParser
public abstract class Parser extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description protected ASTFactoryastFactoryAST support code; parser delegates to this object.protected ParserSharedInputStateinputStateprotected ASTreturnASTAST return value for a rule is squirreled away hereprotected java.lang.String[]tokenNamesTable of token type to token namesprotected java.util.HashtabletokenTypeToASTClassMapConstructed if any AST types specified in tokens{..}.protected inttraceDepthUsed to keep track of indentdepth for traceIn/Out
-
Constructor Summary
Constructors Constructor Description Parser()Parser(ParserSharedInputState state)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddMessageListener(MessageListener l)voidaddParserListener(ParserListener l)voidaddParserMatchListener(ParserMatchListener l)voidaddParserTokenListener(ParserTokenListener l)voidaddSemanticPredicateListener(SemanticPredicateListener l)voidaddSyntacticPredicateListener(SyntacticPredicateListener l)voidaddTraceListener(TraceListener l)abstract voidconsume()Get another token object from the token streamvoidconsumeUntil(int tokenType)Consume tokens until one matches the given tokenvoidconsumeUntil(BitSet set)Consume tokens until one matches the given token setprotected voiddefaultDebuggingSetup(TokenStream lexer, TokenBuffer tokBuf)ASTgetAST()Get the AST return value squirreled away in the parserASTFactorygetASTFactory()java.lang.StringgetFilename()ParserSharedInputStategetInputState()java.lang.StringgetTokenName(int num)java.lang.String[]getTokenNames()java.util.HashtablegetTokenTypeToASTClassMap()If the user specifies a tokens{} section with heterogeneous AST node types, then ANTLR generates code to fill this mapping.booleanisDebugMode()abstract intLA(int i)Return the token type of the ith token of lookahead where i=1 is the current token being examined by the parser (i.e., it has not been matched yet).abstract TokenLT(int i)Return the ith token of lookaheadintmark()voidmatch(int t)Make sure current lookahead symbol matches token type t.voidmatch(BitSet b)Make sure current lookahead symbol matches the given set Throw an exception upon mismatch, which is catch by either the error handler or by the syntactic predicate.voidmatchNot(int t)static voidpanic()Deprecated.as of 2.7.2.voidrecover(RecognitionException ex, BitSet tokenSet)voidremoveMessageListener(MessageListener l)voidremoveParserListener(ParserListener l)voidremoveParserMatchListener(ParserMatchListener l)voidremoveParserTokenListener(ParserTokenListener l)voidremoveSemanticPredicateListener(SemanticPredicateListener l)voidremoveSyntacticPredicateListener(SyntacticPredicateListener l)voidremoveTraceListener(TraceListener l)voidreportError(RecognitionException ex)Parser error-reporting function can be overridden in subclassvoidreportError(java.lang.String s)Parser error-reporting function can be overridden in subclassvoidreportWarning(java.lang.String s)Parser warning-reporting function can be overridden in subclassvoidrewind(int pos)voidsetASTFactory(ASTFactory f)Specify an object with support code (shared by Parser and TreeParser.voidsetASTNodeClass(java.lang.String cl)voidsetASTNodeType(java.lang.String nodeType)Deprecated.since 2.7.1voidsetDebugMode(boolean debugMode)voidsetFilename(java.lang.String f)voidsetIgnoreInvalidDebugCalls(boolean value)voidsetInputState(ParserSharedInputState state)voidsetTokenBuffer(TokenBuffer t)Set or change the input token buffervoidtraceIn(java.lang.String rname)voidtraceIndent()voidtraceOut(java.lang.String rname)
-
-
-
Field Detail
-
inputState
protected ParserSharedInputState inputState
-
tokenNames
protected java.lang.String[] tokenNames
Table of token type to token names
-
returnAST
protected AST returnAST
AST return value for a rule is squirreled away here
-
astFactory
protected ASTFactory astFactory
AST support code; parser delegates to this object. This is set during parser construction by default to either "new ASTFactory()" or a ctor that has a token type to class map for hetero nodes.
-
tokenTypeToASTClassMap
protected java.util.Hashtable tokenTypeToASTClassMap
Constructed if any AST types specified in tokens{..}. Maps an Integer->Class object.
-
traceDepth
protected int traceDepth
Used to keep track of indentdepth for traceIn/Out
-
-
Constructor Detail
-
Parser
public Parser()
-
Parser
public Parser(ParserSharedInputState state)
-
-
Method Detail
-
getTokenTypeToASTClassMap
public java.util.Hashtable getTokenTypeToASTClassMap()
If the user specifies a tokens{} section with heterogeneous AST node types, then ANTLR generates code to fill this mapping.
-
addMessageListener
public void addMessageListener(MessageListener l)
-
addParserListener
public void addParserListener(ParserListener l)
-
addParserMatchListener
public void addParserMatchListener(ParserMatchListener l)
-
addParserTokenListener
public void addParserTokenListener(ParserTokenListener l)
-
addSemanticPredicateListener
public void addSemanticPredicateListener(SemanticPredicateListener l)
-
addSyntacticPredicateListener
public void addSyntacticPredicateListener(SyntacticPredicateListener l)
-
addTraceListener
public void addTraceListener(TraceListener l)
-
consume
public abstract void consume() throws TokenStreamExceptionGet another token object from the token stream- Throws:
TokenStreamException
-
consumeUntil
public void consumeUntil(int tokenType) throws TokenStreamExceptionConsume tokens until one matches the given token- Throws:
TokenStreamException
-
consumeUntil
public void consumeUntil(BitSet set) throws TokenStreamException
Consume tokens until one matches the given token set- Throws:
TokenStreamException
-
defaultDebuggingSetup
protected void defaultDebuggingSetup(TokenStream lexer, TokenBuffer tokBuf)
-
getAST
public AST getAST()
Get the AST return value squirreled away in the parser
-
getASTFactory
public ASTFactory getASTFactory()
-
getFilename
public java.lang.String getFilename()
-
getInputState
public ParserSharedInputState getInputState()
-
setInputState
public void setInputState(ParserSharedInputState state)
-
getTokenName
public java.lang.String getTokenName(int num)
-
getTokenNames
public java.lang.String[] getTokenNames()
-
isDebugMode
public boolean isDebugMode()
-
LA
public abstract int LA(int i) throws TokenStreamExceptionReturn the token type of the ith token of lookahead where i=1 is the current token being examined by the parser (i.e., it has not been matched yet).- Throws:
TokenStreamException
-
LT
public abstract Token LT(int i) throws TokenStreamException
Return the ith token of lookahead- Throws:
TokenStreamException
-
mark
public int mark()
-
match
public void match(int t) throws MismatchedTokenException, TokenStreamExceptionMake sure current lookahead symbol matches token type t. Throw an exception upon mismatch, which is catch by either the error handler or by the syntactic predicate.
-
match
public void match(BitSet b) throws MismatchedTokenException, TokenStreamException
Make sure current lookahead symbol matches the given set Throw an exception upon mismatch, which is catch by either the error handler or by the syntactic predicate.
-
matchNot
public void matchNot(int t) throws MismatchedTokenException, TokenStreamException
-
panic
public static void panic()
Deprecated.as of 2.7.2. This method calls System.exit() and writes directly to stderr, which is usually not appropriate when a parser is embedded into a larger application. Since the method isstatic, it cannot be overridden to avoid these problems. ANTLR no longer uses this method internally or in generated code.
-
removeMessageListener
public void removeMessageListener(MessageListener l)
-
removeParserListener
public void removeParserListener(ParserListener l)
-
removeParserMatchListener
public void removeParserMatchListener(ParserMatchListener l)
-
removeParserTokenListener
public void removeParserTokenListener(ParserTokenListener l)
-
removeSemanticPredicateListener
public void removeSemanticPredicateListener(SemanticPredicateListener l)
-
removeSyntacticPredicateListener
public void removeSyntacticPredicateListener(SyntacticPredicateListener l)
-
removeTraceListener
public void removeTraceListener(TraceListener l)
-
reportError
public void reportError(RecognitionException ex)
Parser error-reporting function can be overridden in subclass
-
reportError
public void reportError(java.lang.String s)
Parser error-reporting function can be overridden in subclass
-
reportWarning
public void reportWarning(java.lang.String s)
Parser warning-reporting function can be overridden in subclass
-
recover
public void recover(RecognitionException ex, BitSet tokenSet) throws TokenStreamException
- Throws:
TokenStreamException
-
rewind
public void rewind(int pos)
-
setASTFactory
public void setASTFactory(ASTFactory f)
Specify an object with support code (shared by Parser and TreeParser. Normally, the programmer does not play with this, using setASTNodeType instead.
-
setASTNodeClass
public void setASTNodeClass(java.lang.String cl)
-
setASTNodeType
public void setASTNodeType(java.lang.String nodeType)
Deprecated.since 2.7.1Specify the type of node to create during tree building; use setASTNodeClass now to be consistent with Token Object Type accessor.
-
setDebugMode
public void setDebugMode(boolean debugMode)
-
setFilename
public void setFilename(java.lang.String f)
-
setIgnoreInvalidDebugCalls
public void setIgnoreInvalidDebugCalls(boolean value)
-
setTokenBuffer
public void setTokenBuffer(TokenBuffer t)
Set or change the input token buffer
-
traceIndent
public void traceIndent()
-
traceIn
public void traceIn(java.lang.String rname) throws TokenStreamException- Throws:
TokenStreamException
-
traceOut
public void traceOut(java.lang.String rname) throws TokenStreamException- Throws:
TokenStreamException
-
-