|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.inxar.syntacs.translator.lr.StandardLRTranslatorGrammar
This is a "mutable" implementation of
LRTranslatorGrammar
used by both the
SyntacsTranslator
and the
XML2LRTranslatorGrammarTransformer
when a grammar is
parsed into memory. It does all the dirty work of semantic checks
after the parse has been completed, and is pretty much a central
part of the whole enchilada.
Fields inherited from interface org.inxar.syntacs.translator.lr.LRTranslatorGrammar |
ACTION_PEEK, ACTION_PEEL, ACTION_POP, ACTION_POUNCE, ACTION_PUSH, UNDEFINED, UNDEFINED_CONTEXT, UNDEFINED_NONTERMINAL, UNDEFINED_PRODUCTION, UNDEFINED_SYMBOL, UNDEFINED_TERMINAL |
Constructor Summary | |
StandardLRTranslatorGrammar()
Constructs a new empty grammar. |
Method Summary | |
void |
addContext(String name)
Adds a context having the given name to the list of contexts. |
void |
addNonTerminal(String name)
Adds a new nonterminal to the list of nonterminal having the given name. |
void |
addProduction(String nonterminalName,
List symbolNames)
Adds a new production to the grammar having the given nonterminal as the right-hand-side and the given List of symbol names as the left-hand-side. |
void |
addSemanticError(String msg)
|
void |
addSemanticWarning(String msg)
|
void |
addTerminal(String name)
Adds a new terminal to the list of terminal having the given name. |
void |
compile(Properties p)
Once all the grammar declarations and definitions have been done, compile() will go through everything and do
all the semantic checks. |
Auditor |
getAuditor()
|
String |
getContext(int ID)
Returns the name of the context having the given ID or null if no such ID is known. |
int |
getContext(String name)
Returns the ID of the context with the given name or UNDEFINED_CONTEXT if no such context exists. |
int |
getContextAction(int contextID,
int symbolID)
Returns the action defined for the given grammar symbol in the given context as one of the ACTION_XXX constants
in this interface. |
int |
getContextRegister(int contextID,
int symbolID)
Returns an integer stored at the value of the given contextID and symbolID . |
IntArray |
getContexts()
Returns the list of context ID numbers as an IntArray . |
IntArray |
getContextTerminals(int contextID)
Returns a list of terminals defined within the context having the given ID or null if no such ID is known. |
int |
getGoalNonTerminal()
Returns the ID of the goal symbol (a nonterminal) or UNDEFINED_NONTERMINAL is no such goal symbol has
been set. |
Input |
getInput()
|
String |
getName()
Returns the name of the Translator . |
String |
getNonTerminal(int ID)
Returns the name of the nonterminal having the given ID or null if no such ID is known. |
int |
getNonTerminal(String name)
Returns the ID of the nonterminal having the given name or UNDEFINED_NONTERMINAL if no such nonterminal
exists. |
IntArray |
getNonTerminals()
Returns the list of nonterminal ID numbers as an IntArray . |
String |
getProduction(int ID)
Returns the name of the production having the given ID or null if no such ID is known. |
int |
getProduction(String name)
Returns the production having the given name or UNDEFINED_PRODUCTION is no such production exists. |
int |
getProductionLength(int ID)
Returns the length of the list of grammar symbols of the right-hand-side of the production having the given ID or UNDEFINED_PRODUCTION if no such ID is known. |
int |
getProductionNonTerminal(int ID)
Returns the ID of the nonterminal obtained by reduction of the given productionID or
UNDEFINED_PRODUCTION if no such production is known. |
IntArray |
getProductions()
Returns the list of production ID numbers as an IntArray . |
IntArray |
getProductionSymbols(int ID)
Returns the list of grammar symbols of the right-hand-side of the production having the given ID as an IntArray
or null if no such ID is known. |
String |
getProperty(String name)
Returns the value of the given property key or null of no such property exists. |
int |
getStartContext()
Returns the ID of the initial context. |
String |
getSymbol(int ID)
Returns the name of the symbol having the given ID or null if no such ID exists. |
int |
getSymbol(String name)
Returns the ID of the given terminal or nonterminal (symbols) or UNDEFINED_SYMBOL if no such name exists in the
list of grammar symbols. |
String |
getTerminal(int ID)
Returns the name of the terminal having the given ID or null if no such ID is known. |
int |
getTerminal(String name)
Returns the ID of the terminal having the given name or UNDEFINED_TERMINAL if no such terminal exists. |
IntArray |
getTerminalContexts(int ID)
Returns a list of contexts in which this terminal is defined. |
Object |
getTerminalRegexp(int ID)
Returns the regular expression String for the
terminal having the given ID or null if no such ID
is known. |
IntArray |
getTerminals()
Returns the list of terminal ID numbers as an IntArray . |
String |
getVersion()
Returns the version number given to this grammar. |
boolean |
hasContext(String name)
Returns true if there is an existing context with
the given name, false otherwise. |
boolean |
hasGoalNonTerminal()
Returns true if a goal symbol has been set,
false otherwise (the goal symbol has not been
set). |
boolean |
hasNonTerminal(int ID)
Returns true if a nonterminal having the given
ID exists in this grammar, false otherwise. |
boolean |
hasNonTerminal(String name)
Returns true if a nonterminal having the given
name exists in this grammar, false otherwise. |
boolean |
hasProduction(String name)
Returns true if a production having the given name exists, false otherwise. |
boolean |
hasStartContext()
Returns true if the start context has already been
set, false otherwise. |
boolean |
hasTerminal(int ID)
Returns true if there is a terminal with the given
ID, falsew otherwise. |
boolean |
hasTerminal(String name)
Returns true if there is a terminal with the given
name, falsew otherwise. |
boolean |
isTerminal(int ID)
|
Translator |
newTranslator()
Returns a new Translator for this
TranslatorGrammar having some default set of
properties. |
Translator |
newTranslator(Properties p)
Returns a new Translator for this
TranslatorGrammar using the given
Properties . |
void |
setAuditor(Auditor auditor)
|
void |
setContextPeek(String contextName,
String symbolName)
Sets the lexical context action to PEEK for the given context and symbol. |
void |
setContextPop(String contextName,
String symbolName)
Sets the lexical context action to POP for the given context and symbol. |
void |
setContextPush(String contextName,
String symbolName,
String contextPushed)
Sets the lexical context action to PUSH for the given context and symbol. |
void |
setGoalNonTerminal(String name)
Sets the goal symbol to the nonterminal with the given name. |
void |
setInput(Input in)
|
void |
setName(String grammarName)
Sets the name of the grammar to the given String . |
void |
setProperty(String name,
String value)
Sets the property with the given name to the given value. |
void |
setStartContext(String name)
Sets the start context to the context with the given name. |
void |
setTerminalRegexp(String name,
Object regexp)
Sets the regular expression for the terminal having the given name. |
void |
setVersion(String version)
Sets the version of the grammar to the given String . |
String |
toString()
|
String |
toString2()
|
String |
toSyntacs()
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public StandardLRTranslatorGrammar()
Method Detail |
public String getName()
TranslatorGrammar
Translator
.getName
in interface TranslatorGrammar
public String getVersion()
TranslatorGrammar
getVersion
in interface TranslatorGrammar
public Translator newTranslator()
TranslatorGrammar
Translator
for this
TranslatorGrammar
having some default set of
properties.newTranslator
in interface TranslatorGrammar
public Translator newTranslator(Properties p)
TranslatorGrammar
Translator
for this
TranslatorGrammar
using the given
Properties
. The names and values of the elements
in the Properties
may be used to modify or
communicate with the internals of the Translator
instance (such as turning on debugging). The specifics
reagarding the names and values of the properties are specific
to the translator itself and need be documented elsewhere.newTranslator
in interface TranslatorGrammar
public IntArray getContexts()
LRTranslatorGrammar
IntArray
.getContexts
in interface LRTranslatorGrammar
public String getContext(int ID)
LRTranslatorGrammar
null
if no such ID is known.getContext
in interface LRTranslatorGrammar
public int getStartContext()
LRTranslatorGrammar
getStartContext
in interface LRTranslatorGrammar
public int getContextAction(int contextID, int symbolID)
LRTranslatorGrammar
ACTION_XXX
constants
in this interface. If the contextID or symbolID is not known,
UNDEFINED_CONTEXT
or UNDEFINED_SYMBOL
will be returned. Note: If UNDEFINED_SYMBOL is returned the ID
may still be a valid terminal or nonterminal, but it not a
member of the given context.getContextAction
in interface LRTranslatorGrammar
public int getContextRegister(int contextID, int symbolID)
LRTranslatorGrammar
contextID
and symbolID
. This is used
in conjunction with getContextAction(int, int)
such that the second member in the tuple (action, register) is
returned. If the contextID or symbolID is not known,
UNDEFINED_CONTEXT
or UNDEFINED_SYMBOL
will be returned.getContextRegister
in interface LRTranslatorGrammar
public IntArray getContextTerminals(int contextID)
LRTranslatorGrammar
null
if no such ID is known.getContextTerminals
in interface LRTranslatorGrammar
public IntArray getTerminals()
LRTranslatorGrammar
IntArray
.getTerminals
in interface LRTranslatorGrammar
public String getTerminal(int ID)
LRTranslatorGrammar
null
if no such ID is known.getTerminal
in interface LRTranslatorGrammar
public Object getTerminalRegexp(int ID)
LRTranslatorGrammar
String
for the
terminal having the given ID or null
if no such ID
is known. If the terminal ID is valid but no definition has
been provided for that terminal, the empty string
""
will be returned.getTerminalRegexp
in interface LRTranslatorGrammar
public IntArray getTerminalContexts(int ID)
LRTranslatorGrammar
getTerminalContexts
in interface LRTranslatorGrammar
public boolean isTerminal(int ID)
public IntArray getNonTerminals()
LRTranslatorGrammar
IntArray
.getNonTerminals
in interface LRTranslatorGrammar
public String getNonTerminal(int ID)
LRTranslatorGrammar
null
if no such ID is known.getNonTerminal
in interface LRTranslatorGrammar
public int getGoalNonTerminal()
LRTranslatorGrammar
UNDEFINED_NONTERMINAL
is no such goal symbol has
been set.getGoalNonTerminal
in interface LRTranslatorGrammar
public IntArray getProductions()
LRTranslatorGrammar
IntArray
.getProductions
in interface LRTranslatorGrammar
public String getProduction(int ID)
LRTranslatorGrammar
null
if no such ID is known. The
String
has the format "nonterminal: sym1
sym2 sym3
" such that the nonterminal name is the first
part of the string, followed by a colon, followed by a space
delimited list of symbols.getProduction
in interface LRTranslatorGrammar
public int getProductionNonTerminal(int ID)
LRTranslatorGrammar
productionID
or
UNDEFINED_PRODUCTION
if no such production is known.getProductionNonTerminal
in interface LRTranslatorGrammar
public IntArray getProductionSymbols(int ID)
LRTranslatorGrammar
IntArray
or null
if no such ID is known.getProductionSymbols
in interface LRTranslatorGrammar
public int getProductionLength(int ID)
LRTranslatorGrammar
UNDEFINED_PRODUCTION
if no such ID is known.getProductionLength
in interface LRTranslatorGrammar
public void setName(String grammarName)
String
.public void setVersion(String version)
String
.public boolean hasContext(String name)
true
if there is an existing context with
the given name, false
otherwise.public int getContext(String name)
UNDEFINED_CONTEXT
if no such context exists.public void addContext(String name)
public boolean hasStartContext()
true
if the start context has already been
set, false
otherwise.public void setStartContext(String name)
public void setContextPush(String contextName, String symbolName, String contextPushed)
public void setContextPeek(String contextName, String symbolName)
public void setContextPop(String contextName, String symbolName)
public boolean hasTerminal(String name)
true
if there is a terminal with the given
name, falsew
otherwise.public boolean hasTerminal(int ID)
true
if there is a terminal with the given
ID, falsew
otherwise.public int getTerminal(String name)
UNDEFINED_TERMINAL
if no such terminal exists.public void addTerminal(String name)
public void setTerminalRegexp(String name, Object regexp)
public boolean hasNonTerminal(String name)
true
if a nonterminal having the given
name exists in this grammar, false
otherwise.public boolean hasNonTerminal(int ID)
true
if a nonterminal having the given
ID exists in this grammar, false
otherwise.public int getNonTerminal(String name)
UNDEFINED_NONTERMINAL
if no such nonterminal
exists.public void addNonTerminal(String name)
public boolean hasGoalNonTerminal()
true
if a goal symbol has been set,
false
otherwise (the goal symbol has not been
set).public void setGoalNonTerminal(String name)
public boolean hasProduction(String name)
nonterminal-name: symbol symbol symbol
". This is
a simple string match, so caveat emptor.public int getProduction(String name)
UNDEFINED_PRODUCTION
is no such production exists.public void addProduction(String nonterminalName, List symbolNames)
List
of symbol names as the left-hand-side. Each
member in the List
should be a
String
. If the given nonterminal or any of the
symbols are unknown, an error will be noted.public int getSymbol(String name)
UNDEFINED_SYMBOL
if no such name exists in the
list of grammar symbols.public String getSymbol(int ID)
null
if no such ID exists.public String getProperty(String name)
null
of no such property exists.public void setProperty(String name, String value)
public void compile(Properties p)
compile()
will go through everything and do
all the semantic checks.public void setInput(Input in)
public Input getInput()
public void setAuditor(Auditor auditor)
public Auditor getAuditor()
public void addSemanticError(String msg)
public void addSemanticWarning(String msg)
public String toString()
toString
in class Object
public String toString2()
public String toSyntacs()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |