|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjaitools.jiffle.parser.SymbolScopeStack
public class SymbolScopeStack
Used in the Jiffle tree parser grammars to track symbols defined at different scopes in a script. The name of this class comes from the ANTLR scope stack mechanism on which it is loosely based.
Jiffle's scoping rules are almost identical to Java. At the top level of a script the accessible variables are those declared in an init (image-scope variables) plus any declared in the script outside other blocks. Within a block, the accessible variables are those at the top level plus any additional variables defined in the block itself. The latter go out of scope when leaving the block. A foreach loop variable's scope is the statement or block associated with the loop.
| Constructor Summary | |
|---|---|
SymbolScopeStack()
Creates a new scope stack. |
|
| Method Summary | |
|---|---|
void |
addLevel()
Pushes a new scope level onto the stack. |
void |
addLevel(String label)
Pushes a new scope level onto the stack. |
void |
addSymbol(String name,
SymbolType type,
ScopeType scopeType)
Adds a new symbol to the current scope level. |
SymbolScope |
dropLevel()
Drops (ie. |
Symbol |
findSymbol(String name)
Gets the first symbol found with the given name. |
boolean |
isDefined(String name)
Tests if a symbol with the given name is defined within the top scope or any enclosing scopes. |
boolean |
isDefined(String name,
ScopeType scopeType)
Tests if a symbol with the given name and scope type is defined within the top scope or any enclosing scopes. |
boolean |
isDefined(String name,
SymbolType type)
Tests if a symbol with the given name and type is defined within the top scope or any enclosing scopes. |
boolean |
isEmpty()
Tests if there are any scope levels. |
int |
size()
Gets the number of scope levels. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SymbolScopeStack()
| Method Detail |
|---|
public void addLevel()
public void addLevel(String label)
label - label for the new scopepublic SymbolScope dropLevel()
null if the
stack was empty
public void addSymbol(String name,
SymbolType type,
ScopeType scopeType)
name - symbol nametype - symbol typescopeType - symbol scope
IllegalArgumentException - if no scope levels have been addedpublic boolean isEmpty()
true if the stack is empty; false otherwisepublic int size()
public boolean isDefined(String name)
name - symbol name
true if the symbol is found; false otherwise
public boolean isDefined(String name,
SymbolType type)
name - symbol nametype - symbol type
true if the symbol is found; false otherwise
public boolean isDefined(String name,
ScopeType scopeType)
name - symbol namescopeType - the symbol scope
true if the symbol is found; false otherwisepublic Symbol findSymbol(String name)
name - symbol name
null if there was no match
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||