Interface PushDownMachine

All Known Implementing Classes:
SingleThreadPushDownMachine

public interface PushDownMachine
A push down automaton which can perform mathematical and logical operations for QubecTalk.

A stack-based machine which can perform mathematical calculations as part of the QubecTalk runtime. It assumes that units provided are appropriately converted prior to pushing. It also can perform logical operations like ternary operations.

  • 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.
  • Method Details

    • push

      void push(EngineNumber value)
      Push a number onto the machine's stack.
      Parameters:
      value - The value to push.
    • getResult

      EngineNumber getResult()
      Get the result of the machine's calculations.
      Returns:
      The result of the calculations.
      Throws:
      RuntimeException - if the machine does not have exactly one result waiting at the top of its stack.
    • add

      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.

    • subtract

      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.

    • multiply

      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.

    • divide

      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.

      Throws:
      ArithmeticException - If the right operand (divisor) is zero.
    • changeUnits

      void changeUnits(String units)
      Change the units of the number at the top of the stack.
      Parameters:
      units - The new units for the number at the top of the stack.
      Throws:
      RuntimeException - If the stack is empty or the top value already has units which do not match the desired units.
    • changeUnits

      void changeUnits(String units, boolean force)
      Change the units of the number at the top of the stack, optionally forcing the change.
      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.
      Throws:
      RuntimeException - If the stack is empty, or if force is false and the top value already has units which do not match the desired units.
    • getEngine

      Engine getEngine()
      Get the engine in which this machine is running.
      Returns:
      The engine in which this machine is running.
    • and

      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.

    • or

      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.

    • xor

      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.

    • equals

      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.

    • notEquals

      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.

    • greaterThan

      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.

    • lessThan

      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.

    • greaterThanOrEqual

      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.

    • lessThanOrEqual

      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.

    • drawNormal

      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.

    • drawUniform

      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.

    • power

      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.