public class WordList
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
name
The name of the word list, if any.
|
Modifier and Type | Method and Description |
---|---|
void |
add(XT xt)
Add a new word to the word list.
|
static WordList |
find(VM vm,
java.lang.String name)
Return a named word list if available or
null if the
word list has not been defined. |
static void |
forget(VM vm,
int addr)
Remove all words with a definition later than the specified
address.
|
static WordList |
forWordList(VM vm,
java.lang.String name)
Create a new word list, the new list has no words and is
case sensitive.
|
void |
loadForth(java.lang.String fileName)
Read and interpret a forth file, placing all definitions in
the current word list.
|
boolean |
loadJava(java.lang.String className)
Load the word list with definitions from a given Java primitives
class file.
|
XT |
search(java.lang.String name)
Search the word list for a given word, returning the associated
execution token (XT) if found or
null if the word is
not found. |
java.lang.String |
search(XT target)
Search the word list for the name of a given execution token
(XT) behaviour, returning the associated word name if found
or
null if the XT is not found. |
boolean |
setSensitivity(boolean flag)
Set the case sensitivity of the word list to a given value.
|
java.lang.String |
toString()
Return a string representation of the wordlist.
|
public static WordList forWordList(VM vm, java.lang.String name)
add(XT)
method to
add new words to the list and the
setSensitivity(bool)
method to alter the case sensitive nature of the word list.vm
- the virtual machine to which the word list belongsname
- the name of the word list.public static WordList find(VM vm, java.lang.String name)
null
if the
word list has not been defined.vm
- the virtual machine to search.name
- name of the word list to search for.null
if the word list has not been defined.public void add(XT xt)
xt
- The XT associated with the word.public boolean setSensitivity(boolean flag)
flag
- false to enable case insensitivity and
true to enable case sensitivity.public XT search(java.lang.String name)
null
if the word is
not found.
The search starts at the end of the word list, working toward
the start of the list, as we are looking for the most recent
occurrence of the word.
The search takes account of the sensitive
flag.name
- the string with the name of the word to find.null
if not found.public java.lang.String search(XT target)
null
if the XT is not found.target
- the XT to search for.null
if not found.public boolean loadJava(java.lang.String className) throws java.io.IOException, ForthException
The class file must extend the WordSet
super
class.
High level forth definitions may be provided via the use of
the @Forth
and @Interpret
annotations. These
high level definitions are processed after the primitives have
been loaded, so they may refer to the primitive definitions.
The class may extend the list of available environment queries
by using the @Environment
annotation. A primitive
marked with this annotation will be added to the list of
environment queries rather than the current word list.
It is our intention to provide support to load native
Java class files (classes that do not extend the WordSet
class) but this will be some distance in the future.
Currently an attempt to load such a class will raise an
Unsupported Function exception.
className
- The name of the class to be loaded.java.io.IOException
- reading the class file.ForthException
- generated by an error in the high
level forth source.WordSet
public void loadForth(java.lang.String fileName) throws java.io.FileNotFoundException, java.io.IOException, ForthException
fileName
- the name of the Forth file to be loaded.java.io.FileNotFoundException
- when the Forth file can not be found.java.io.IOException
- when there is a difficulty in reading the file.ForthException
- when the text in the forth source generates
an error.public static void forget(VM vm, int addr)
vm
- the virtual machine to which the word lists belongaddr
- forget all definitions from this address.public java.lang.String toString()
toString
in class java.lang.Object