|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.scheinerman.phoenix.interpreter.Interpreter
net.scheinerman.phoenix.interpreter.functions.Function
public class Function
A Function
is an Interpreter
that takes can
be run multiple times with different arguments. A function also has
a name, a return value, and a specified order of arguments. The arguments
must be provided in order otherwise an exception is thrown. A Function
can take many forms. Functions are declared by placing the keyword
function
, followed by the return type (void
,
num
, or str
), followed by the left-hand arguments,
then the name followed by the right-hand arguments then a colon (":"). Functions
can also be started with the global
modifier (which globalizes them)
if desired. The left and right hand arguments are both optional, so each of the
following function declarations are valid:
function num (num x) factorial:
function num digits (num x):
function num (num n) nCr (num r):
function void (str s) printStr (num start, num end):
function void tic:
These functions can then be called thus:
(8) factorial
digits (34256)
(6) nCr (3)
("Hello there!") printStr (0,5)
tic
Note: Any whitespace that is not right after a modifier (e.g.
num
or function
) is ignored.
Interpreter}, {@link NativeFunction}
Field Summary | |
---|---|
protected java.lang.String[] |
af_names
An array containing the names of the right-hand arguments to the function. |
protected Variable[] |
af_types
An array containing variables of the same types as the right-hand arguments to the function. |
protected java.util.TreeMap<java.lang.String,java.lang.String> |
argDescriptions
|
protected java.lang.String[] |
b4_names
An array containing the names of the left-hand arguments to the function. |
protected Variable[] |
b4_types
An array containing variables of the same types as the left-hand arguments to the function. |
protected java.lang.String |
description
|
protected java.lang.String |
modifiers
|
protected java.lang.String |
name
The name of the function. |
protected java.lang.String |
returnDescription
|
Fields inherited from class net.scheinerman.phoenix.interpreter.Interpreter |
---|
_break, _continue, _return, breakValue, code, fat, file, keywordList, line, line_diff, printValues, retType, retTypeSet, retValue, run_code, stop, vat |
Constructor Summary | |
---|---|
Function()
The default constructor for a Function .Warning: This constructor bypasses the standard initialization procedure and should not be used. |
|
Function(java.lang.String name,
java.lang.String file,
java.lang.String code,
int line,
Variable[] b4_types,
java.lang.String[] b4_names,
Variable[] af_types,
java.lang.String[] af_names,
Variable retType,
boolean setupDocs)
Constructs a Function with the given variables. |
Method Summary | |
---|---|
protected void |
addArgs(Variable[] b4_args,
Variable[] af_args)
Adds the passed variables to the local VAT and FAT of the function. |
protected boolean |
check(Variable[] b4_args,
Variable[] af_args)
Checks to see whether the variables that were passed to this function are actually of the type that were specified in the function definition. |
protected void |
dealWithReturn(Variable passed)
Deals with a return statement by setting the retValue field, checking whether
it's the right type and stopping the function. |
java.lang.String[] |
getAfterNames()
|
Variable[] |
getAfterTypes()
Returns the default variables that were defined as right-hand parameters of the function. |
java.lang.String[] |
getBeforeNames()
|
Variable[] |
getBeforeTypes()
Returns the default variables that were defined as left-hand parameters of the function. |
java.lang.String |
getDefinition()
|
java.lang.String |
getName()
Returns the name of this function. |
void |
printHelp()
|
void |
run(Variable[] b4_args,
Variable[] af_args)
Runs this function with the given left-hand and right-hand arguments. |
void |
setModifiers(java.lang.String modifiers)
|
void |
setName(java.lang.String name)
|
void |
setVATandFAT(java.util.LinkedList<java.util.HashMap<java.lang.String,Variable>> vat,
java.util.LinkedList<java.util.HashMap<java.lang.String,Function>> fat)
|
java.lang.String |
toString()
|
Methods inherited from class net.scheinerman.phoenix.interpreter.Interpreter |
---|
dealWithBreak, dealWithContinue, dealWithError, delete, doRun, getBlock, getFunction, getFunctionArguments, getFunctionFromDefinition, getReturnValue, getVariable, getWhitespace, initNewTables, isValidIdentifier, makeDefaultVariable, makeFunction, makeVariable, makeVariable, parsePhrase, putFunction, removeComments, removeWhitespace, retValueMatches, run |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.lang.String name
protected Variable[] b4_types
protected java.lang.String[] b4_names
protected Variable[] af_types
protected java.lang.String[] af_names
protected java.lang.String description
protected java.util.TreeMap<java.lang.String,java.lang.String> argDescriptions
protected java.lang.String returnDescription
protected java.lang.String modifiers
Constructor Detail |
---|
public Function()
Function
.
public Function(java.lang.String name, java.lang.String file, java.lang.String code, int line, Variable[] b4_types, java.lang.String[] b4_names, Variable[] af_types, java.lang.String[] af_names, Variable retType, boolean setupDocs)
Function
with the given variables.
name
- - the function identifier.code
- - the code that the function will execute.vat
- - the global VAT variablefat
- - the global FAT variableb4_types
- - an array of variables whose types are equivalent
to the types of variables of the left-hand arguments.b4_names
- - the names of the left-hand arguments.af_types
- - an array of variables whose types are equivalent
to the types of variables of the right-hand arguments.af_names
- - the names of the right-hand arguments.ret_type
- - a variable of the same type as the return type
of this function.Method Detail |
---|
public void setVATandFAT(java.util.LinkedList<java.util.HashMap<java.lang.String,Variable>> vat, java.util.LinkedList<java.util.HashMap<java.lang.String,Function>> fat)
public java.lang.String getName()
public void run(Variable[] b4_args, Variable[] af_args)
SyntaxException
will be thrown.
b4_args
- - The left-hand arguments.af_args
- - The right-hand arguments.
SyntaxException
- if the variables are of the wrong type.protected void dealWithReturn(Variable passed)
retValue
field, checking whether
it's the right type and stopping the function.
dealWithReturn
in class Interpreter
passed
- - The variable passed via the return statement.
SyntaxException
- if the returned value is of the wrong type.protected boolean check(Variable[] b4_args, Variable[] af_args)
true
is returned, otherwise, false
is returned.
b4_args
- - The left-hand arguments passed to the function.af_args
- - The right-hand arguments passed to the function.
true
or false
based on whether or not the passed
variables are of the correct type.protected void addArgs(Variable[] b4_args, Variable[] af_args)
b4_args
- - the passed left-hand argumentsaf_args
- - the passed right-hand argumentspublic Variable[] getBeforeTypes()
public Variable[] getAfterTypes()
public java.lang.String[] getBeforeNames()
public java.lang.String[] getAfterNames()
public void setName(java.lang.String name)
public java.lang.String toString()
toString
in class java.lang.Object
public void setModifiers(java.lang.String modifiers)
public java.lang.String getDefinition()
public void printHelp()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |