|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jext.dawn.DawnParser
DawnParser
is the Dawn scripting language interpreter.
Dawn is a language based on RPN. Dawn is also a very modulary language.
Basic usage of Dawn is:
DawnParser.init(); // code is a String containing the script DawnParser parser = new DawnParser(new StringReader(code)); try { parser.exec(); } catch (DawnRuntimeException dre) { System.err.println(dre.getMessage()); }
Note the call to init()
. You may not want to call this method,
but if you don't, then Dawn will provide NO FUNCTION AT ALL. Even basic ones,
like + - * drop sto rcl, won't work !! This is due to the fact Dawn can be
entirely customized.
In fact, init()
simply install basic packages (loop, test,
util, stack, math, err, io, string, naming). But you can load only one, or
many, of them and also install your own packages to replace default ones.
You may also load extra packages with the: installPackage()
method.
Read the documentation for further informations.
Field Summary | |
static int |
DAWN_ARRAY_TYPE
Identifier for a stack element defining an array |
static int |
DAWN_LITERAL_TYPE
Identifier for a stack element defining a literal (variable name) |
static int |
DAWN_NUMERIC_TYPE
Identifier for a stack element containing a numeric value |
static int |
DAWN_STRING_TYPE
Identifier for a stack element containing a string |
static java.lang.String |
DAWN_VERSION
Gives Dawn interpreter version numbering |
java.io.PrintStream |
err
|
java.io.InputStream |
in
|
int |
lineno
|
java.io.PrintStream |
out
|
Constructor Summary | |
DawnParser(java.io.Reader in)
Creates a new parser. |
Method Summary | |
static void |
addGlobalFunction(Function function)
Adds given function to the global functions list. |
void |
addRuntimeFunction(Function function)
Adds given function to the runtime functions list. |
void |
checkArgsNumber(Function function,
int nb)
Checks if stack contains enough datas to feed a function. |
void |
checkEmpty(Function function)
Checks if the stack is empty. |
void |
checkLevel(Function function,
int level)
Checks if a given level is bound in the limits of the stack. |
void |
checkVarName(Function function,
java.lang.String var)
Checks if a given variable name is valid or not. |
static void |
clearGlobalVariables()
Clears all the global variables. |
static void |
createGlobalFunction(java.lang.String name,
java.lang.String code)
Creates dynamically a function which can execute the Dawn script passed in parameter. |
Function |
createOnFlyFunction(java.lang.String code)
Creates dynamically a function which can execute the Dawn script passed in parameter. |
void |
createRuntimeFunction(java.lang.String name,
java.lang.String code)
Creates dynamically a function which can execute the Dawn script passed in parameter. |
java.io.StreamTokenizer |
createTokenizer(java.io.Reader in)
Creates a new StreamTokenizer, setting its properties according to the Dawn scripting language specifications. |
java.lang.String |
dump()
Returns a String containing a simple description of the current stack
state. |
void |
exec()
Executes loaded script. |
static java.util.Hashtable |
getFunctions()
Returns an Hashtable containing all the current global functions. |
java.util.Hashtable |
getGlobalVariables()
Returns the Hashtable which contains the global variables. |
java.lang.Object |
getProperty(java.lang.Object name)
Returns a property according a given key. |
java.util.Hashtable |
getRuntimeFunctions()
Returns the set of runtimes functions. |
java.util.Stack |
getStack()
Returns the stack which containes all the current availables datas. |
java.io.StreamTokenizer |
getStream()
Returns current StreamTokenizer . |
int |
getTopType()
Returns topmost stack element type. |
java.lang.Object |
getVariable(java.lang.String var)
Returns the value of a given variable. |
java.util.Hashtable |
getVariables()
Returns the Hashtable which contains the local variables. |
static void |
init()
Initializes Dawn default packages. |
static void |
installPackage(java.lang.Class loader,
java.lang.String packageName)
Installs a package specific to a given class. |
static void |
installPackage(java.lang.Class loader,
java.lang.String packageName,
DawnParser parser)
Installs a package specific to a given class. |
static void |
installPackage(java.lang.String packageName)
Installs a package from Dawn archive. |
static boolean |
isInitialized()
Returns true if the parser has already been initialized. |
boolean |
isTopArray()
Tells wether topmost object is an array or not. |
boolean |
isTopLiteral()
Tells wether topmost object is a literal identifier or not. |
boolean |
isTopNumeric()
Tells wether topmost object is a numeric value or not. |
boolean |
isTopString()
Tells wether topmost object is a string or not. |
int |
lineno()
Returns current line number in the script. |
java.lang.Object |
peek()
Returns topmost object of the stack. |
java.util.Vector |
peekArray()
Gets topmost stack element and returns it as a Vector
which is the Java object for Dawn arrays. |
double |
peekNumber()
Get topmost element of the stack and return is as a double value if it can. |
java.lang.String |
peekString()
Get the topmost element of the stack and returns it as a String . |
java.lang.Object |
pop()
Returns topmost objet of the stack and remove it. |
java.util.Vector |
popArray()
Gets topmost stack element and returns it as a Vector
which is the Java object for Dawn arrays. |
double |
popNumber()
Get topmost element of the stack and return is as a double value if it can. |
java.lang.String |
popString()
Get the topmost element of the stack and returns it as a String . |
void |
push(java.lang.Object obj)
Puts an object on the top of the stack. |
void |
pushArray(java.util.Vector array)
Pushes an array on top of the stack. |
void |
pushNumber(double number)
Pushes a number on top of the stack. |
void |
pushString(java.lang.String str)
Puts a String on top of the stack. |
void |
setErr(java.io.PrintStream err)
Sets the parser error print stream. |
static void |
setGlobalVariable(java.lang.String var,
java.lang.Object value)
Sets a global variable. |
void |
setIn(java.io.InputStream in)
Sets the parser input stream. |
void |
setOut(java.io.PrintStream out)
Sets the parser print stream. |
void |
setProperty(java.lang.Object name,
java.lang.Object property)
Sets a property in the parser. |
void |
setStream(java.io.StreamTokenizer _st)
Sets the StreamTokenizer used to execute a script. |
void |
setVariable(java.lang.String var,
java.lang.Object value)
Sets a runtime variable. |
void |
stop()
Stops the parser. |
void |
unsetProperty(java.lang.Object name)
Unsets (remove) a given property. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String DAWN_VERSION
public static final int DAWN_NUMERIC_TYPE
public static final int DAWN_STRING_TYPE
public static final int DAWN_LITERAL_TYPE
public static final int DAWN_ARRAY_TYPE
public int lineno
public java.io.PrintStream out
public java.io.PrintStream err
public java.io.InputStream in
Constructor Detail |
public DawnParser(java.io.Reader in)
in
- A Reader
which will deliver the script to the parserMethod Detail |
public static void init()
public static boolean isInitialized()
init()
has been made.
public static void installPackage(java.lang.String packageName)
packageName
- The package to loadpublic static void installPackage(java.lang.Class loader, java.lang.String packageName)
loader
- The Class
which calls this, if the class is
not part of Dawn standard packagepackageName
- The package to loadpublic static void installPackage(java.lang.Class loader, java.lang.String packageName, DawnParser parser)
loader
- The Class
which calls this, if the class is
not part of Dawn standard packagepackageName
- The package to loadparser
- If this parameter is not set to null, the package is loaded
as runtime packagepublic void setOut(java.io.PrintStream out)
out
- The new PrintStream
public void setErr(java.io.PrintStream err)
err
- The new PrintStream
used for errorspublic void setIn(java.io.InputStream in)
public void setStream(java.io.StreamTokenizer _st)
StreamTokenizer
used to execute a script.
It is HIGHLY recommended NOT TO CALL this without a very good
reason.
_st
- The new stream where to get the script frompublic java.io.StreamTokenizer getStream()
StreamTokenizer
. It is mostly used
by functions to parse the script further. 'if' statement from
test package is a good example (see also for and while from the
loop package).
public java.io.StreamTokenizer createTokenizer(java.io.Reader in)
in
- The Reader
which will deliver the scriptpublic static java.util.Hashtable getFunctions()
public java.util.Hashtable getRuntimeFunctions()
public java.util.Stack getStack()
public void checkVarName(Function function, java.lang.String var) throws DawnRuntimeException
var
- The variable name to be tested
DawnRuntimeException
public void checkArgsNumber(Function function, int nb) throws DawnRuntimeException
nb
- The amount of arguments needed
DawnRuntimeException
public void checkEmpty(Function function) throws DawnRuntimeException
DawnRuntimeException
public void checkLevel(Function function, int level) throws DawnRuntimeException
level
- The level to be tested
DawnRuntimeException
public void setProperty(java.lang.Object name, java.lang.Object property)
name
- An Object
describing the property. It stands for the keyproperty
- The property valuepublic java.lang.Object getProperty(java.lang.Object name)
name
- The property keypublic void unsetProperty(java.lang.Object name)
public void stop()
public void exec() throws DawnRuntimeException
DawnRuntimeException
public java.util.Hashtable getVariables()
Hashtable
which contains the local variables.
public java.util.Hashtable getGlobalVariables()
Hashtable
which contains the global variables.
public java.lang.Object getVariable(java.lang.String var)
var
- The variable to be recalledpublic void setVariable(java.lang.String var, java.lang.Object value)
var
- The variable namevalue
- An Object
containg the variable valuepublic static void setGlobalVariable(java.lang.String var, java.lang.Object value)
clearGlobalVariables()
is called.
var
- The variable namevalue
- An Object
containg the variable valuepublic static void clearGlobalVariables()
public int lineno()
public java.lang.String dump()
String
containing a simple description of the current stack
state. All the levels are shown, each labeled by its level number.
public double popNumber() throws DawnRuntimeException
DawnRuntimeException
public double peekNumber() throws DawnRuntimeException
DawnRuntimeException
public void pushNumber(double number)
number
- The number to be put on the stackpublic java.lang.String popString() throws DawnRuntimeException
String
. If the string is enclosed by " quote
characters, they are removed. The element is removed from the stack.
DawnRuntimeException
public java.lang.String peekString() throws DawnRuntimeException
String
. If the string is enclosed by " quote
characters, they are removed.
DawnRuntimeException
public void pushString(java.lang.String str)
String
on top of the stack.
str
- The string to be put on the stackpublic java.util.Vector popArray() throws DawnRuntimeException
Vector
which is the Java object for Dawn arrays. The element is removed
from the stack.
DawnRuntimeException
public java.util.Vector peekArray() throws DawnRuntimeException
Vector
which is the Java object for Dawn arrays.
DawnRuntimeException
public void pushArray(java.util.Vector array)
array
- The array to be put on the stackpublic java.lang.Object pop() throws DawnRuntimeException
DawnRuntimeException
public java.lang.Object peek() throws DawnRuntimeException
DawnRuntimeException
public void push(java.lang.Object obj)
obj
- The object to be put on the toppublic boolean isTopNumeric()
public boolean isTopString()
public boolean isTopArray()
public boolean isTopLiteral()
public int getTopType()
public static void addGlobalFunction(Function function)
function
- The Function
to be addedpublic void addRuntimeFunction(Function function)
function
- The Function
to be addedpublic Function createOnFlyFunction(java.lang.String code)
code
- The Dawn code which will be executed by the returned
function on invoke() callpublic static void createGlobalFunction(java.lang.String name, java.lang.String code)
name
- Function Dawn namecode
- The Dawn code which will be executed by functionpublic void createRuntimeFunction(java.lang.String name, java.lang.String code)
name
- Function Dawn namecode
- The Dawn code which will be executed by function
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |