Module Simula

Class Constant

All Implemented Interfaces:
Externalizable, Serializable

public final class Constant extends Expression implements Externalizable
Constant.

All constants are treated by the Lexicographical Scanner.

 
 Syntax:
 
   Constant = unsigned-number | string | character-constant | NONE | NOTEXT
   
 
Link to GitHub: Source File.
Author:
Øystein Myhre Andersen
See Also:
  • Field Details

    • value

      public Object value
      The constant's value
  • Constructor Details

    • Constant

      public Constant(Type type, Object value)
      Create a new Constant.
      Parameters:
      type - the constant's type
      value - the constant's value
    • Constant

      public Constant()
      Default constructor used by Externalization.
  • Method Details

    • createRealType

      static Constant createRealType(Object value)
      Create a real type Constant.
      Parameters:
      value - a real type value
      Returns:
      the resulting Constant
    • getType

      private static Type getType(Number n)
      Returns the type of this number.
      Parameters:
      n - the number
      Returns:
      the type of this number.
    • evaluate

      static Constant evaluate(KeyWord opr, Number rhn)
      Simplify this Constant.
      Parameters:
      opr - an unary operation
      rhn - a right hand Number
      Returns:
      the resulting Constant
    • evaluate

      static Constant evaluate(Number lhn, KeyWord opr, Number rhn)
      Simplify this Constant.
      Parameters:
      lhn - a left hand Number
      opr - an binary operation
      rhn - a right hand Number
      Returns:
      the resulting Constant
    • 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
    • toJavaCode

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

      private String encode(String s)
      Encode a string with escape sequences.
      Parameters:
      s - the string
      Returns:
      a string with escape sequences.
    • appendHex

      private void appendHex(StringBuilder sb, char c)
      Encoding Utility: Edit hex(c) and append it to the given StringBuilder.
      Parameters:
      sb - the StringBuilder
      c - the input character
    • toString

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

      public void writeExternal(ObjectOutput oupt) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput inpt) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException