antlr

Class DefineGrammarSymbols

Implemented Interfaces:
ANTLRGrammarParseBehavior
Known Direct Subclasses:
MakeGrammar

public class DefineGrammarSymbols
extends Object
implements ANTLRGrammarParseBehavior

DefineGrammarSymbols is a behavior for the ANTLRParser that adds all the token and rule symbols to the grammar symbol table. Token types are assigned to token symbols in this class also. The token type for a token is done in the order seen (lexically).

Field Summary

(package private) static String
DEFAULT_TOKENMANAGER_NAME
(package private) LLkAnalyzer
analyzer
(package private) String[]
args
protected Grammar
grammar
protected Hashtable
grammars
protected Hashtable
headerActions
(package private) String
language
protected int
numLexers
protected int
numParsers
protected int
numTreeParsers
(package private) Token
thePreambleAction
protected Hashtable
tokenManagers
protected Tool
tool

Constructor Summary

DefineGrammarSymbols(Tool tool_, String[] args_, LLkAnalyzer analyzer_)

Method Summary

void
_refStringLiteral(Token lit, Token label, int autoGenType, boolean lastInRule)
void
_refToken(Token assignId, Token t, Token label, Token args, boolean inverted, int autoGenType, boolean lastInRule)
Reference a token
void
abortGrammar()
Abort the processing of a grammar due to syntax errors
void
beginAlt(boolean doAST_)
void
beginChildList()
void
beginExceptionGroup()
void
beginExceptionSpec(Token label)
void
beginSubRule(Token label, Token start, boolean not)
void
beginTree(Token tok)
void
defineRuleName(Token r, String access, boolean ruleAutoGen, String docComment)
Define a lexer or parser rule
void
defineToken(Token tokname, Token tokliteral)
Define a token from tokens {...}.
void
endAlt()
void
endChildList()
void
endExceptionGroup()
void
endExceptionSpec()
void
endGrammar()
void
endOptions()
Called after the optional options section, to compensate for options that may not have been set.
void
endRule(String r)
void
endSubRule()
void
endTree()
String
getHeaderAction(String name)
void
hasError()
void
noASTSubRule()
void
oneOrMoreSubRule()
void
optionalSubRule()
void
refAction(Token action)
void
refArgAction(Token action)
void
refCharLiteral(Token lit, Token label, boolean inverted, int autoGenType, boolean lastInRule)
void
refCharRange(Token t1, Token t2, Token label, int autoGenType, boolean lastInRule)
void
refElementOption(Token option, Token value)
void
refExceptionHandler(Token exTypeAndName, Token action)
void
refHeaderAction(Token name, Token act)
void
refInitAction(Token action)
void
refMemberAction(Token act)
void
refPreambleAction(Token act)
void
refReturnAction(Token returnAction)
void
refRule(Token idAssign, Token r, Token label, Token args, int autoGenType)
void
refSemPred(Token pred)
void
refStringLiteral(Token lit, Token label, int autoGenType, boolean lastInRule)
void
refToken(Token assignId, Token t, Token label, Token args, boolean inverted, int autoGenType, boolean lastInRule)
Reference a token
void
refTokenRange(Token t1, Token t2, Token label, int autoGenType, boolean lastInRule)
void
refTokensSpecElementOption(Token tok, Token option, Token value)
void
refTreeSpecifier(Token treeSpec)
void
refWildcard(Token t, Token label, int autoGenType)
void
reset()
Get ready to process a new grammar
void
setArgOfRuleRef(Token argaction)
void
setCharVocabulary(BitSet b)
Set the character vocabulary for a lexer
void
setFileOption(Token key, Token value, String filename)
setFileOption: Associate an option value with a key.
void
setGrammarOption(Token key, Token value)
setGrammarOption: Associate an option value with a key.
void
setRuleOption(Token key, Token value)
void
setSubruleOption(Token key, Token value)
void
setUserExceptions(String thr)
void
startLexer(String file, Token name, String superClass, String doc)
Start a new lexer
void
startParser(String file, Token name, String superClass, String doc)
Start a new parser
void
startTreeWalker(String file, Token name, String superClass, String doc)
Start a new tree-walker
void
synPred()
void
zeroOrMoreSubRule()

Field Details

DEFAULT_TOKENMANAGER_NAME

(package private) static final String DEFAULT_TOKENMANAGER_NAME


analyzer

(package private)  LLkAnalyzer analyzer


args

(package private)  String[] args


grammar

protected Grammar grammar


grammars

protected Hashtable grammars


headerActions

protected Hashtable headerActions


language

(package private)  String language


numLexers

protected int numLexers


numParsers

protected int numParsers


numTreeParsers

protected int numTreeParsers


thePreambleAction

(package private)  Token thePreambleAction


tokenManagers

protected Hashtable tokenManagers


tool

protected Tool tool

Constructor Details

DefineGrammarSymbols

public DefineGrammarSymbols(Tool tool_,
                            String[] args_,
                            LLkAnalyzer analyzer_)

Method Details

_refStringLiteral

public void _refStringLiteral(Token lit,
                              Token label,
                              int autoGenType,
                              boolean lastInRule)


_refToken

public void _refToken(Token assignId,
                      Token t,
                      Token label,
                      Token args,
                      boolean inverted,
                      int autoGenType,
                      boolean lastInRule)
Reference a token


abortGrammar

public void abortGrammar()
Abort the processing of a grammar due to syntax errors
Specified by:
abortGrammar in interface ANTLRGrammarParseBehavior


beginAlt

public void beginAlt(boolean doAST_)
Specified by:
beginAlt in interface ANTLRGrammarParseBehavior


beginChildList

public void beginChildList()
Specified by:
beginChildList in interface ANTLRGrammarParseBehavior


beginExceptionGroup

public void beginExceptionGroup()
Specified by:
beginExceptionGroup in interface ANTLRGrammarParseBehavior


beginExceptionSpec

public void beginExceptionSpec(Token label)
Specified by:
beginExceptionSpec in interface ANTLRGrammarParseBehavior


beginSubRule

public void beginSubRule(Token label,
                         Token start,
                         boolean not)
Specified by:
beginSubRule in interface ANTLRGrammarParseBehavior


beginTree

public void beginTree(Token tok)
            throws SemanticException
Specified by:
beginTree in interface ANTLRGrammarParseBehavior


defineRuleName

public void defineRuleName(Token r,
                           String access,
                           boolean ruleAutoGen,
                           String docComment)
            throws SemanticException
Define a lexer or parser rule
Specified by:
defineRuleName in interface ANTLRGrammarParseBehavior


defineToken

public void defineToken(Token tokname,
                        Token tokliteral)
Define a token from tokens {...}. Must be label and literal or just label or just a literal.
Specified by:
defineToken in interface ANTLRGrammarParseBehavior


endAlt

public void endAlt()
Specified by:
endAlt in interface ANTLRGrammarParseBehavior


endChildList

public void endChildList()
Specified by:
endChildList in interface ANTLRGrammarParseBehavior


endExceptionGroup

public void endExceptionGroup()
Specified by:
endExceptionGroup in interface ANTLRGrammarParseBehavior


endExceptionSpec

public void endExceptionSpec()
Specified by:
endExceptionSpec in interface ANTLRGrammarParseBehavior


endGrammar

public void endGrammar()
Specified by:
endGrammar in interface ANTLRGrammarParseBehavior


endOptions

public void endOptions()
Called after the optional options section, to compensate for options that may not have been set. This method is bigger than it needs to be, but is much more clear if I delineate all the cases.
Specified by:
endOptions in interface ANTLRGrammarParseBehavior


endRule

public void endRule(String r)
Specified by:
endRule in interface ANTLRGrammarParseBehavior


endSubRule

public void endSubRule()
Specified by:
endSubRule in interface ANTLRGrammarParseBehavior


endTree

public void endTree()
Specified by:
endTree in interface ANTLRGrammarParseBehavior


getHeaderAction

public String getHeaderAction(String name)


hasError

public void hasError()
Specified by:
hasError in interface ANTLRGrammarParseBehavior


noASTSubRule

public void noASTSubRule()
Specified by:
noASTSubRule in interface ANTLRGrammarParseBehavior


oneOrMoreSubRule

public void oneOrMoreSubRule()
Specified by:
oneOrMoreSubRule in interface ANTLRGrammarParseBehavior


optionalSubRule

public void optionalSubRule()
Specified by:
optionalSubRule in interface ANTLRGrammarParseBehavior


refAction

public void refAction(Token action)
Specified by:
refAction in interface ANTLRGrammarParseBehavior


refArgAction

public void refArgAction(Token action)
Specified by:
refArgAction in interface ANTLRGrammarParseBehavior


refCharLiteral

public void refCharLiteral(Token lit,
                           Token label,
                           boolean inverted,
                           int autoGenType,
                           boolean lastInRule)
Specified by:
refCharLiteral in interface ANTLRGrammarParseBehavior


refCharRange

public void refCharRange(Token t1,
                         Token t2,
                         Token label,
                         int autoGenType,
                         boolean lastInRule)
Specified by:
refCharRange in interface ANTLRGrammarParseBehavior


refElementOption

public void refElementOption(Token option,
                             Token value)
Specified by:
refElementOption in interface ANTLRGrammarParseBehavior


refExceptionHandler

public void refExceptionHandler(Token exTypeAndName,
                                Token action)
Specified by:
refExceptionHandler in interface ANTLRGrammarParseBehavior


refHeaderAction

public void refHeaderAction(Token name,
                            Token act)
Specified by:
refHeaderAction in interface ANTLRGrammarParseBehavior


refInitAction

public void refInitAction(Token action)
Specified by:
refInitAction in interface ANTLRGrammarParseBehavior


refMemberAction

public void refMemberAction(Token act)
Specified by:
refMemberAction in interface ANTLRGrammarParseBehavior


refPreambleAction

public void refPreambleAction(Token act)
Specified by:
refPreambleAction in interface ANTLRGrammarParseBehavior


refReturnAction

public void refReturnAction(Token returnAction)
Specified by:
refReturnAction in interface ANTLRGrammarParseBehavior


refRule

public void refRule(Token idAssign,
                    Token r,
                    Token label,
                    Token args,
                    int autoGenType)
Specified by:
refRule in interface ANTLRGrammarParseBehavior


refSemPred

public void refSemPred(Token pred)
Specified by:
refSemPred in interface ANTLRGrammarParseBehavior


refStringLiteral

public void refStringLiteral(Token lit,
                             Token label,
                             int autoGenType,
                             boolean lastInRule)
Specified by:
refStringLiteral in interface ANTLRGrammarParseBehavior


refToken

public void refToken(Token assignId,
                     Token t,
                     Token label,
                     Token args,
                     boolean inverted,
                     int autoGenType,
                     boolean lastInRule)
Reference a token
Specified by:
refToken in interface ANTLRGrammarParseBehavior


refTokenRange

public void refTokenRange(Token t1,
                          Token t2,
                          Token label,
                          int autoGenType,
                          boolean lastInRule)
Specified by:
refTokenRange in interface ANTLRGrammarParseBehavior


refTokensSpecElementOption

public void refTokensSpecElementOption(Token tok,
                                       Token option,
                                       Token value)
Specified by:
refTokensSpecElementOption in interface ANTLRGrammarParseBehavior


refTreeSpecifier

public void refTreeSpecifier(Token treeSpec)
Specified by:
refTreeSpecifier in interface ANTLRGrammarParseBehavior


refWildcard

public void refWildcard(Token t,
                        Token label,
                        int autoGenType)
Specified by:
refWildcard in interface ANTLRGrammarParseBehavior


reset

public void reset()
Get ready to process a new grammar


setArgOfRuleRef

public void setArgOfRuleRef(Token argaction)
Specified by:
setArgOfRuleRef in interface ANTLRGrammarParseBehavior


setCharVocabulary

public void setCharVocabulary(BitSet b)
Set the character vocabulary for a lexer
Specified by:
setCharVocabulary in interface ANTLRGrammarParseBehavior


setFileOption

public void setFileOption(Token key,
                          Token value,
                          String filename)
setFileOption: Associate an option value with a key. This applies to options for an entire grammar file.
Specified by:
setFileOption in interface ANTLRGrammarParseBehavior

Parameters:
key - The token containing the option name
value - The token containing the option value.


setGrammarOption

public void setGrammarOption(Token key,
                             Token value)
setGrammarOption: Associate an option value with a key. This function forwards to Grammar.setOption for some options.
Specified by:
setGrammarOption in interface ANTLRGrammarParseBehavior

Parameters:
key - The token containing the option name
value - The token containing the option value.


setRuleOption

public void setRuleOption(Token key,
                          Token value)
Specified by:
setRuleOption in interface ANTLRGrammarParseBehavior


setSubruleOption

public void setSubruleOption(Token key,
                             Token value)
Specified by:
setSubruleOption in interface ANTLRGrammarParseBehavior


setUserExceptions

public void setUserExceptions(String thr)
Specified by:
setUserExceptions in interface ANTLRGrammarParseBehavior


startLexer

public void startLexer(String file,
                       Token name,
                       String superClass,
                       String doc)
Start a new lexer
Specified by:
startLexer in interface ANTLRGrammarParseBehavior


startParser

public void startParser(String file,
                        Token name,
                        String superClass,
                        String doc)
Start a new parser
Specified by:
startParser in interface ANTLRGrammarParseBehavior


startTreeWalker

public void startTreeWalker(String file,
                            Token name,
                            String superClass,
                            String doc)
Start a new tree-walker
Specified by:
startTreeWalker in interface ANTLRGrammarParseBehavior


synPred

public void synPred()
Specified by:
synPred in interface ANTLRGrammarParseBehavior


zeroOrMoreSubRule

public void zeroOrMoreSubRule()
Specified by:
zeroOrMoreSubRule in interface ANTLRGrammarParseBehavior