Class Operator

java.lang.Object
com.maroontress.intexpr.impl.Operator
All Implemented Interfaces:
Instruction

public final class Operator extends Object implements Instruction
The instruction that pops the operand(s) from the stack, executes the function with the operand(s), and pushes the return value to the stack.
  • Method Details

    • of

      public static Optional<Operator> of(com.maroontress.clione.Token token, OperatorType type)
      Creates a new Operator object corresponding to the specified token and OperatorType.
      Parameters:
      token - The token corresponding to the operator.
      type - The operator type (OperatorType.UNARY or OperatorType.BINARY).
      Returns:
      The new operator.
    • getSpec

      public OperatorSpec getSpec()
      Returns the OperatorSpec object of this operator.
      Returns:
      The OperatorSpec object.
    • getToken

      public com.maroontress.clione.Token getToken()
      Returns the token of this operator.
      Returns:
      The token.
    • accept

      public void accept(Deque<SyntaxNode> stack)
      Interacts with the specified stack of the SyntaxNode object to build a SyntaxTree object.
      Specified by:
      accept in interface Instruction
      Parameters:
      stack - The stack of a SyntaxNode object.
    • apply

      public int apply(int[] stack, int offset)
      Interacts with the specified stack of an integer.
      Specified by:
      apply in interface Instruction
      Parameters:
      stack - The stack of an integer.
      offset - The position of the top of the stack.
      Returns:
      The new offset of the top of the stack.
    • toString

      public String toString()
      Overrides:
      toString in class Object