|
Building Parsers with Java | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--sjm.engine.Scope
A scope is a repository for variables. A dynamic rule has a scope, which means that variables with the same name are the same variable. Consider a rule that describes big cities:
bigCity(Name) :- city(Name, Pop), >(Pop, 1000000);
This example follows the Prolog convention of using
capitalized words for variables. The variables Name
and Pop have scope throughout the rule.
The bigCity rule proves itself by finding
a city and checking its population. When the city
structure binds with a city fact in a program, its
variables take on the values of the fact. For example,
city might bind with the fact
city(bigappolis, 8733352) . Then Name
and Pop will bind to the values "bigappolis"
and 8733352.
When the comparison proves itself, it will compare
Pop to 1000000. This is the same variable as
Pop in the city structure of the rule.
With this successful comparison, the rule completes a
successful proof, with Name bound to
"bigappolis".
| Constructor Summary | |
Scope()
Create an empty scope. |
|
Scope(Term[] terms)
Create a scope that uses the variables in the supplied terms. |
|
| Method Summary | |
void |
clear()
Remove all variables from this scope. |
java.lang.Object |
clone()
Return a copy of this object. |
boolean |
isDefined(java.lang.String name)
Returns true if a variable of the given name appears in this scope. |
Variable |
lookup(java.lang.String name)
Returns a variable of the given name from this scope. |
| Methods inherited from class java.lang.Object |
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
| Constructor Detail |
public Scope()
public Scope(Term[] terms)
Term[] - the terms to seed this scope with| Method Detail |
public void clear()
public java.lang.Object clone()
public boolean isDefined(java.lang.String name)
String - the variable namepublic Variable lookup(java.lang.String name)
String - the variable name
|
by Steve Metsker | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||