public class StackMachine
extends java.lang.Object
implements java.io.Serializable
StackMachine
here.Modifier and Type | Class and Description |
---|---|
class |
StackMachine.Abs
Describe class
Abs here. |
class |
StackMachine.Add
Describe class
Add here. |
class |
StackMachine.And
Describe class
And here. |
class |
StackMachine.Asin
Describe class
Asin here. |
class |
StackMachine.Assign
Assign the top value on stack to a variable.
|
class |
StackMachine.Atan
Describe class
Atan here. |
class |
StackMachine.BinaryMathFunction
Describe class
BinaryMathFunction here. |
class |
StackMachine.Branch
Describe class
Branch here. |
class |
StackMachine.Call
Describe class
Call here. |
class |
StackMachine.Constant
Describe class
Constant here. |
class |
StackMachine.Cos
Describe class
Cos here. |
class |
StackMachine.Div
Describe class
Div here. |
class |
StackMachine.DumpStack
Output the current contents of the stack.
|
class |
StackMachine.Eq
Describe class
Eq here. |
class |
StackMachine.Exp
Describe class
Exp here. |
class |
StackMachine.Function
Describe class
Function here. |
class |
StackMachine.Ge
Describe class
Ge here. |
class |
StackMachine.GoTo
Goto
|
class |
StackMachine.Gt
Describe class
Gt here. |
class |
StackMachine.If
Describe class
If here. |
static interface |
StackMachine.Instruction
Describe interface
Instruction here. |
class |
StackMachine.Le
Describe class
Le here. |
class |
StackMachine.Ln
Describe class
Ln here. |
class |
StackMachine.Lt
Describe class
Lt here. |
class |
StackMachine.MathFunction
Describe class
MathFunction here. |
class |
StackMachine.Max
Describe class
Max here. |
class |
StackMachine.Min
Describe class
Min here. |
class |
StackMachine.Mul
Describe class
Mul here. |
class |
StackMachine.Ne
Describe class
Ne here. |
class |
StackMachine.Negate
Describe class
Negate here. |
class |
StackMachine.Or
Describe class
Or here. |
class |
StackMachine.Pop
Describe class
Pop here. |
class |
StackMachine.PopPrint
Print the top of the stack.
|
class |
StackMachine.Pow
Describe class
Pow here. |
class |
StackMachine.Print
Print the top of the stack.
|
class |
StackMachine.PushAddress
Push address on stack.
|
class |
StackMachine.PushConstant
Push constant on stack.
|
class |
StackMachine.PushVariable
Push value of a variable on stack.
|
class |
StackMachine.Return
Return from a function
|
class |
StackMachine.Sgn
Describe class
Sgn here. |
class |
StackMachine.Sin
Describe class
Sin here. |
class |
StackMachine.Sqrt
Describe class
Sqrt here. |
class |
StackMachine.Step
Describe class
Step here. |
class |
StackMachine.Stop
Describe class
Stop here. |
class |
StackMachine.Sub
Describe class
Sub here. |
class |
StackMachine.SymbolTableEntry
Describe class
SymbolTableEntry here. |
class |
StackMachine.Tan
Describe class
Tan here. |
class |
StackMachine.TernaryMathFunction
Describe class
TernaryMathFunction here. |
class |
StackMachine.UnaryMathFunction
Describe class
UnaryMathFunction here. |
class |
StackMachine.Variable
Describe class
Variable here. |
Constructor and Description |
---|
StackMachine()
Creates a new
StackMachine instance. |
Modifier and Type | Method and Description |
---|---|
int |
allocateVariable()
Add a new uninitialized variable.
|
int |
allocateVariable(double value)
Add a new initialized variable.
|
void |
assign(int address,
double value)
Assign value to a variable.
|
void |
clear()
Describe
clear method here. |
void |
clearData()
Describe
clearData method here. |
void |
clearGlobalSymbolTable()
Describe
clearGlobalSymbolTable method here. |
void |
clearLocalSymbolTable()
Describe
clearLocalSymbolTable method here. |
void |
clearProgram()
Describe
clearProgram method here. |
void |
clearProgram(int beg)
Describe
clearProgram method here. |
void |
clearReturnStack()
Describe
clearReturnStack method here. |
void |
clearStack()
Describe
clearStack method here. |
void |
createConstant(java.lang.String id,
double value)
Create a new constant and place it in the global symbol table.
|
void |
createFunction(java.lang.String id,
int progbase,
int argbase,
int nargs)
Describe
createFunction method here. |
StackMachine.Variable |
createVariable(java.lang.String id)
Create a new global variable.
|
StackMachine.Variable |
createVariable(java.lang.String id,
double value)
Create a new global variable.
|
void |
dumpStack()
Describe
dumpStack method here. |
void |
enterLocalScope()
Describe
enterLocalScope method here. |
void |
execute()
Execute the entire code of the program.
|
void |
execute(int progbase)
Execute code of the program, starting at a given program counter.
|
void |
exitLocalScope()
Describe
exitLocalScope method here. |
double |
getData(int address)
Describe
getData method here. |
int |
getProgramBase()
Describe
getProgramBase method here. |
void |
globalScope()
Describe
globalScope method here. |
void |
initMathConstants()
Describe
initMathConstants method here. |
boolean |
isConstant(java.lang.String id)
Describe
isConstant method here. |
StackMachine.SymbolTableEntry |
lookup(java.lang.String name)
Lookup symbol in a symbol table.
|
java.lang.Object |
peek()
Describe
peek method here. |
double |
peekDouble()
Describe
peekDouble method here. |
int |
peekInt()
Describe
peekInt method here. |
java.lang.Object |
pop()
Describe
pop method here. |
double |
popDouble()
Describe
popDouble method here. |
int |
popInt()
Describe
popInt method here. |
int |
popReturn()
Describe
popReturn method here. |
void |
pushDouble(double x)
Describe
pushDouble method here. |
void |
pushInstruction(StackMachine.Instruction i)
Add an instruction at the end of the program
|
void |
pushInstruction(StackMachine.Instruction i,
java.lang.String name,
int nargs)
Push instruction with arity check
|
void |
pushInt(int x)
Describe
pushInt method here. |
void |
pushReturn(int location)
Describe
pushReturn method here. |
java.lang.Object |
removeSymbol(java.lang.String id)
Remove a symbol from the current scope.
|
void |
renameSymbol(java.lang.String old,
java.lang.String id)
Rename a global symbol.
|
boolean |
scopeIsLocal()
Describe
scopeIsLocal method here. |
void |
setInstructionAt(StackMachine.Instruction i,
int location)
Sets an instruction at a given location in the program
|
public final int getProgramBase()
getProgramBase
method here.public final boolean scopeIsLocal()
scopeIsLocal
method here.boolean
valuepublic final void enterLocalScope() throws ParseException
enterLocalScope
method here.ParseException
- if an error occurspublic final void exitLocalScope() throws ParseException
exitLocalScope
method here.ParseException
- if an error occurspublic final void globalScope()
globalScope
method here.public final void initMathConstants()
initMathConstants
method here.public final void clearProgram()
clearProgram
method here.public final void clearProgram(int beg)
clearProgram
method here.beg
- an int
valuepublic final void clearStack()
clearStack
method here.public final void clearReturnStack()
clearReturnStack
method here.public final void clearGlobalSymbolTable()
clearGlobalSymbolTable
method here.public final void clearLocalSymbolTable()
clearLocalSymbolTable
method here.public final void clear()
clear
method here.public final void dumpStack()
dumpStack
method here.public final boolean isConstant(java.lang.String id)
isConstant
method here.id
- a String
valueboolean
valuepublic final void renameSymbol(java.lang.String old, java.lang.String id) throws ParseException
old
- Old symbol name.id
- New symbol name.ParseException
- if an error occurspublic final StackMachine.Variable createVariable(java.lang.String id)
id
- The name of the variableVariable
valuepublic final StackMachine.Variable createVariable(java.lang.String id, double value)
id
- The name of the variablevalue
- a double
valueVariable
valuepublic final java.lang.Object removeSymbol(java.lang.String id)
id
- The name of the symbol.public final void createConstant(java.lang.String id, double value)
id
- The name of the constant.value
- The value of the constant.public final void createFunction(java.lang.String id, int progbase, int argbase, int nargs)
createFunction
method here.id
- a String
valueprogbase
- an int
valueargbase
- an int
valuenargs
- an int
valuepublic StackMachine.SymbolTableEntry lookup(java.lang.String name)
name
- Name of symbol to be looked uppublic final double getData(int address) throws ParseException
getData
method here.address
- an int
valuedouble
valueParseException
- if an error occurspublic final void pushInstruction(StackMachine.Instruction i)
i
- The instructionpublic final void setInstructionAt(StackMachine.Instruction i, int location)
i
- The instructionlocation
- an int
valuepublic final int allocateVariable()
public final void clearData()
clearData
method here.public final int allocateVariable(double value)
value
- a double
valuepublic final void assign(int address, double value) throws ParseException
address
- The address of the variable.value
- The value to be assigned.ParseException
- if an error occurspublic final void pushInstruction(StackMachine.Instruction i, java.lang.String name, int nargs) throws ParseException
i
- The instruction.name
- The name of the function to be reported if arity and the number
of arguments don't matchnargs
- The number of arguments.ParseException
- if an error occurspublic final java.lang.Object pop() throws ParseException
pop
method here.Object
valueParseException
- if an error occurspublic final int popReturn() throws ParseException
popReturn
method here.int
valueParseException
- if an error occurspublic final void pushReturn(int location)
pushReturn
method here.location
- an int
valuepublic final java.lang.Object peek() throws ParseException
peek
method here.Object
valueParseException
- if an error occurspublic final int popInt() throws ParseException
popInt
method here.int
valueParseException
- if an error occurspublic final int peekInt() throws ParseException
peekInt
method here.int
valueParseException
- if an error occurspublic final double peekDouble() throws ParseException
peekDouble
method here.double
valueParseException
- if an error occurspublic final double popDouble() throws ParseException
popDouble
method here.double
valueParseException
- if an error occurspublic final void pushInt(int x)
pushInt
method here.x
- an int
valuepublic final void pushDouble(double x)
pushDouble
method here.x
- a double
valuepublic final void execute(int progbase) throws ParseException
progbase
- an int
valueParseException
- if an error occurspublic final void execute() throws ParseException
ParseException
- if an error occurs