Class SingleThreadPushDownMachine
- All Implemented Interfaces:
PushDownMachine
A push down automaton which can perform mathematical and logical operations for QubecTalk but which may not necessarily be thread safe.
-
Constructor Summary
ConstructorsConstructorDescriptionSingleThreadPushDownMachine(Engine engine) Create a new SingleThreadPushDownMachine. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd()Add the two numbers on top of the stack.voidand()Perform a logical AND operation on the two numbers on top of the stack.voidchangeUnits(String units) Change the units of the number at the top of the stack.voidchangeUnits(String units, boolean force) Change the units of the number at the top of the stack, optionally forcing the change.voiddivide()Divide the two numbers on top of the stack.voidDraw a random number from a normal distribution.voidDraw a random number from a uniform distribution.voidequals()Perform an equality comparison on the two numbers on top of the stack.Get the engine in which this machine is running.Get the result of the machine's calculations.voidPerform a greater-than comparison on the two numbers on top of the stack.voidPerform a greater-than-or-equal comparison on the two numbers on top of the stack.voidlessThan()Perform a less-than comparison on the two numbers on top of the stack.voidPerform a less-than-or-equal comparison on the two numbers on top of the stack.voidmultiply()Multiply the two numbers on top of the stack.voidPerform a not-equals comparison on the two numbers on top of the stack.voidor()Perform a logical OR operation on the two numbers on top of the stack.voidpower()Raise a number to a power.voidpush(EngineNumber value) Push a number onto the machine's stack.voidsubtract()Subtract the two numbers on top of the stack.voidxor()Perform a logical XOR operation on the two numbers on top of the stack.
-
Constructor Details
-
SingleThreadPushDownMachine
Create a new SingleThreadPushDownMachine.- Parameters:
engine- The engine in which this machine will run.
-
-
Method Details
-
push
Push a number onto the machine's stack.- Specified by:
pushin interfacePushDownMachine- Parameters:
value- The value to push.
-
getResult
Get the result of the machine's calculations.- Specified by:
getResultin interfacePushDownMachine- Returns:
- The result of the calculations.
-
add
public void add()Add the two numbers on top of the stack.Add the two numbers on top of the stack, pushing the result of the calculation to the top of the stack.
- Specified by:
addin interfacePushDownMachine
-
subtract
public void subtract()Subtract the two numbers on top of the stack.Subtract the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
- Specified by:
subtractin interfacePushDownMachine
-
multiply
public void multiply()Multiply the two numbers on top of the stack.Multiply the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
- Specified by:
multiplyin interfacePushDownMachine
-
power
public void power()Raise a number to a power.The right operand (top of stack) is the power and the left operand is the base (next on stack). Goes through double.
- Specified by:
powerin interfacePushDownMachine
-
divide
public void divide()Divide the two numbers on top of the stack.Divide the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
- Specified by:
dividein interfacePushDownMachine
-
changeUnits
Change the units of the number at the top of the stack.- Specified by:
changeUnitsin interfacePushDownMachine- Parameters:
units- The new units for the number at the top of the stack.
-
changeUnits
Change the units of the number at the top of the stack, optionally forcing the change.- Specified by:
changeUnitsin interfacePushDownMachine- Parameters:
units- The new units for the number at the top of the stack.force- If true, force the unit change even if the current units do not match.
-
getEngine
Get the engine in which this machine is running.- Specified by:
getEnginein interfacePushDownMachine- Returns:
- The engine in which this machine is running.
-
and
public void and()Perform a logical AND operation on the two numbers on top of the stack.Perform a logical AND operation on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below. Non-zero values are treated as true, zero values as false.
- Specified by:
andin interfacePushDownMachine
-
or
public void or()Perform a logical OR operation on the two numbers on top of the stack.Perform a logical OR operation on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below. Non-zero values are treated as true, zero values as false.
- Specified by:
orin interfacePushDownMachine
-
xor
public void xor()Perform a logical XOR operation on the two numbers on top of the stack.Perform a logical XOR operation on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below. Non-zero values are treated as true, zero values as false.
- Specified by:
xorin interfacePushDownMachine
-
equals
public void equals()Perform an equality comparison on the two numbers on top of the stack.Perform an equality comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
- Specified by:
equalsin interfacePushDownMachine
-
notEquals
public void notEquals()Perform a not-equals comparison on the two numbers on top of the stack.Perform a not-equals comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
- Specified by:
notEqualsin interfacePushDownMachine
-
greaterThan
public void greaterThan()Perform a greater-than comparison on the two numbers on top of the stack.Perform a greater-than comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
- Specified by:
greaterThanin interfacePushDownMachine
-
lessThan
public void lessThan()Perform a less-than comparison on the two numbers on top of the stack.Perform a less-than comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
- Specified by:
lessThanin interfacePushDownMachine
-
greaterThanOrEqual
public void greaterThanOrEqual()Perform a greater-than-or-equal comparison on the two numbers on top of the stack.Perform a greater-than-or-equal comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
- Specified by:
greaterThanOrEqualin interfacePushDownMachine
-
lessThanOrEqual
public void lessThanOrEqual()Perform a less-than-or-equal comparison on the two numbers on top of the stack.Perform a less-than-or-equal comparison on the two numbers on top of the stack, pushing the result of the calculation to the top of the stack. It assumes that the left operand was pushed prior to the right operand such that the right operand is on the top of the stack and the left operand is right below.
- Specified by:
lessThanOrEqualin interfacePushDownMachine
-
drawNormal
public void drawNormal()Draw a random number from a normal distribution.Draw a random number from a normal distribution using the two numbers on top of the stack as the mean and standard deviation. The right operand (top of stack) is the standard deviation and the left operand (next on stack) is the mean. Pushes the sampled value to the top of the stack.
- Specified by:
drawNormalin interfacePushDownMachine
-
drawUniform
public void drawUniform()Draw a random number from a uniform distribution.Draw a random number from a uniform distribution using the two numbers on top of the stack as the low and high bounds. The right operand (top of stack) is the high bound and the left operand (next on stack) is the low bound. Pushes the sampled value to the top of the stack.
- Specified by:
drawUniformin interfacePushDownMachine
-