Class SingleThreadPushDownMachine

java.lang.Object
org.kigalisim.lang.machine.SingleThreadPushDownMachine
All Implemented Interfaces:
PushDownMachine

public class SingleThreadPushDownMachine extends Object implements PushDownMachine
A push down automaton which can perform mathematical and logical operations for QubecTalk.

A push down automaton which can perform mathematical and logical operations for QubecTalk but which may not necessarily be thread safe.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Create a new SingleThreadPushDownMachine.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add()
    Add the two numbers on top of the stack.
    void
    and()
    Perform a logical AND operation on the two numbers on top of the stack.
    void
    Change the units of the number at the top of the stack.
    void
    changeUnits(String units, boolean force)
    Change the units of the number at the top of the stack, optionally forcing the change.
    void
    Divide the two numbers on top of the stack.
    void
    Draw a random number from a normal distribution.
    void
    Draw a random number from a uniform distribution.
    void
    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.
    void
    Perform a greater-than comparison on the two numbers on top of the stack.
    void
    Perform a greater-than-or-equal comparison on the two numbers on top of the stack.
    void
    Perform a less-than comparison on the two numbers on top of the stack.
    void
    Perform a less-than-or-equal comparison on the two numbers on top of the stack.
    void
    Multiply the two numbers on top of the stack.
    void
    Perform a not-equals comparison on the two numbers on top of the stack.
    void
    or()
    Perform a logical OR operation on the two numbers on top of the stack.
    void
    Raise a number to a power.
    void
    Push a number onto the machine's stack.
    void
    Subtract the two numbers on top of the stack.
    void
    xor()
    Perform a logical XOR operation on the two numbers on top of the stack.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SingleThreadPushDownMachine

      public SingleThreadPushDownMachine(Engine engine)
      Create a new SingleThreadPushDownMachine.
      Parameters:
      engine - The engine in which this machine will run.
  • Method Details

    • push

      public void push(EngineNumber value)
      Push a number onto the machine's stack.
      Specified by:
      push in interface PushDownMachine
      Parameters:
      value - The value to push.
    • getResult

      public EngineNumber getResult()
      Get the result of the machine's calculations.
      Specified by:
      getResult in interface PushDownMachine
      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:
      add in interface PushDownMachine
    • 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:
      subtract in interface PushDownMachine
    • 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:
      multiply in interface PushDownMachine
    • 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:
      power in interface PushDownMachine
    • 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:
      divide in interface PushDownMachine
    • changeUnits

      public void changeUnits(String units)
      Change the units of the number at the top of the stack.
      Specified by:
      changeUnits in interface PushDownMachine
      Parameters:
      units - The new units for the number at the top of the stack.
    • changeUnits

      public void changeUnits(String units, boolean force)
      Change the units of the number at the top of the stack, optionally forcing the change.
      Specified by:
      changeUnits in interface PushDownMachine
      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

      public Engine getEngine()
      Get the engine in which this machine is running.
      Specified by:
      getEngine in interface PushDownMachine
      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:
      and in interface PushDownMachine
    • 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:
      or in interface PushDownMachine
    • 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:
      xor in interface PushDownMachine
    • 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:
      equals in interface PushDownMachine
    • 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:
      notEquals in interface PushDownMachine
    • 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:
      greaterThan in interface PushDownMachine
    • 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:
      lessThan in interface PushDownMachine
    • 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:
      greaterThanOrEqual in interface PushDownMachine
    • 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:
      lessThanOrEqual in interface PushDownMachine
    • 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:
      drawNormal in interface PushDownMachine
    • 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:
      drawUniform in interface PushDownMachine