Class UnaryOperation


public final class UnaryOperation extends Expression

Unary Operation.


Syntax:

  unary-operation =  unary-operator  Expression
  
     unary-operator = NOT | + | -

Link to GitHub: Source File.

Author:
Øystein Myhre Andersen
  • Field Details

    • oprator

      int oprator
      The unary operator.
    • operand

      Expression operand
      The operand Expression.
  • Constructor Details

    • UnaryOperation

      private UnaryOperation(int oprator, Expression operand)
      Create a new UnaryOperation.
      Parameters:
      oprator - the unary operator.
      operand - the operand Expression
    • UnaryOperation

      private UnaryOperation()
      Default constructor used by Attribute File I/O
  • Method Details

    • create

      static Expression create(int oprator, Expression operand)
      Create a new UnaryOperation.
      Parameters:
      oprator - the unary operator.
      operand - the operand Expression
      Returns:
      the newly created UnaryOperation
    • evaluate

      public Expression evaluate()
      Description copied from class: Expression
      Try to Compile-time Evaluate this expression
      Overrides:
      evaluate in class Expression
      Returns:
      the resulting evaluated expression
    • doChecking

      public void doChecking()
      Description copied from class: SyntaxClass

      Perform semantic checking.

      This must be redefined in every subclass.

      Overrides:
      doChecking in class SyntaxClass
    • maybeStatement

      public boolean maybeStatement()
      Description copied from class: Expression
      Returns true if this expression may be used as a statement.
      Specified by:
      maybeStatement in class Expression
      Returns:
      true if this expression may be used as a statement
    • buildEvaluation

      public void buildEvaluation(Expression rightPart, CodeBuilder codeBuilder)
      Description copied from class: Expression
      ClassFile coding utility: Build Evaluation Code.
      Specified by:
      buildEvaluation in class Expression
      Parameters:
      rightPart - expression
      codeBuilder - the codeBuilder used.
    • buildNOT

      public static void buildNOT(CodeBuilder codeBuilder)
      Build code for the NOT operation.
      Parameters:
      codeBuilder - the codeBuilder to use.
    • toJavaCode

      public String toJavaCode()
      Description copied from class: SyntaxClass
      Generate Java code for this Syntax Class.
      Overrides:
      toJavaCode in class SyntaxClass
      Returns:
      Java code
    • toString

      public String toString()
      Overrides:
      toString in class Expression
    • writeObject

      public void writeObject(AttributeOutputStream oupt) throws IOException
      Description copied from class: SyntaxClass
      Write a SyntaxClass object to a AttributeOutputStream.
      Overrides:
      writeObject in class SyntaxClass
      Parameters:
      oupt - the AttributeOutputStream to write to.
      Throws:
      IOException - if something went wrong.
    • readObject

      public static UnaryOperation readObject(AttributeInputStream inpt) throws IOException
      Read and return an UnaryOperation object.
      Parameters:
      inpt - the AttributeInputStream to read from
      Returns:
      the UnaryOperation object read from the stream.
      Throws:
      IOException - if something went wrong.