Module Simula

Class RTS_TXT

java.lang.Object
simula.runtime.RTS_TXT

public final class RTS_TXT extends Object
The type text.

The type text serves to declare or specify a text variable quantity.

A text value is a string, i.e. an ordered sequence (possibly empty) of characters. The number of characters is called the "length" of the text value.

A text frame is a memory device which contains a nonempty text value. A text frame has a fixed length and can only contain text values of this length. A text frame may be "alterable" or "constant". A constant frame always contains the same text value. An alterable text frame may have its contents modified. The maximum length of a text frame is implementation-defined.

A text reference identifies a text frame. The reference is said to possess a value, which is the contents of the identified frame. The special text reference notext identifies "no frame". The value of notext is the empty text value.

A text variable is conceptually an instance of a composite structure

        ref(TEXTOBJ) OBJ; integer START, LENGTH, POS;
 

It references (and has as its value the contents of) some text frame defined by the three first components. POS identifies the current character. See 3.1.2.

Link to GitHub: Source File.

Author:
SIMULA Standards Group, Øystein Myhre Andersen
  • Field Details

    • UNICODE_MINUS_SIGN

      private static final int UNICODE_MINUS_SIGN
      Unicode minus sign = 8722 = 0x2212
      See Also:
    • OBJ

      The Text object referred.
    • START

      int START
      Start index of OBJ.MAIN[], counting from zero.

      Note this differ from Simula Definition.

    • LENGTH

      int LENGTH
      The length of this text.
    • POS

      int POS
      Current index of OBJ.MAIN[], counting from zero.

      Note this differ from Simula Definition.

  • Constructor Details

    • RTS_TXT

      public RTS_TXT()
      Create a new _TXT.
    • RTS_TXT

      public RTS_TXT(String s)
      Create a new _TXT containing the string s.
      Parameters:
      s - initial string value
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • edText

      String edText()
      Utility: Edit text into a String.
      Returns:
      the resulting String
    • edStripedText

      String edStripedText()
      Utility: Edit stripped text into a String.
      Returns:
      the resulting String
    • edTextToPos

      String edTextToPos()
      Utility: Edit text until current pos into a String.
      Returns:
      the resulting String
    • constant

      public static boolean constant(RTS_TXT T)
      Procedure constant.
      Parameters:
      T - the argument text reference
      Returns:
      true if T is constant, otherwise false
    • start

      public static int start(RTS_TXT T)
      Procedure start.
      Parameters:
      T - the argument text reference
      Returns:
      the start position of T within T'main frame
    • length

      public static int length(RTS_TXT T)
      Procedure length.
      Parameters:
      T - the argument text reference
      Returns:
      the length of T
    • main

      public static RTS_TXT main(RTS_TXT T)
      Procedure main.

      "X.main" is a reference to the main frame which contains the frame referenced by X.

      The following relations are true for any text variable X:

                X.main.length  >=  X.length
                X.main.main    ==  X.main
       
      In addition,
                notext.main    ==  notext
                "ABC".main     =   "ABC" 
               (but "ABC".main =/= "ABC")
       
      Parameters:
      T - the argument text reference
      Returns:
      the main frame of T
    • pos

      public static int pos(RTS_TXT T)
      Procedure pos.
                      integer procedure pos; pos := POS;
       
      Parameters:
      T - the argument text reference
      Returns:
      the current POS
    • setpos

      public static void setpos(RTS_TXT T, int p)
      Procedure setpos.
                      procedure setpos(i); integer i;
                              POS := if i < 1 or i > LENGTH + 1 then LENGTH + 1 else i;
       
      Parameters:
      T - the argument text reference
      p - the new POS
    • more

      public static boolean more(RTS_TXT T)
      Procedure more.
      Parameters:
      T - the argument text reference
      Returns:
      true if T.pos < T.length, otherwise false
    • getchar

      public static char getchar(RTS_TXT T)
      Procedure getchar.

      Get the character at the current POS of T. POS is then incremented.

      Parameters:
      T - the argument text reference
      Returns:
      the character at the current pos
      Throws:
      RTS_SimulaRuntimeError - if the operation fail
    • checkAssignable

      private static void checkAssignable(RTS_TXT T)
      Check if it is legal to assign to the given text reference.
      Parameters:
      T - the given text reference
      Throws:
      RTS_SimulaRuntimeError - if assignment is illegal
    • putchar

      public static void putchar(RTS_TXT T, char c)
      Procedure putchar.

      Put the character c into the text T at the current POS. POS is then incremented.

      Parameters:
      T - the argument text reference
      c - the argument character
      Throws:
      RTS_SimulaRuntimeError - if the operation fail
    • sub

      public static RTS_TXT sub(RTS_TXT T, int i, int n)
      Procedure sub.

      If legal, "X.sub(i,n)" references that subframe of X whose first character is character number i of X, and which contains n consecutive characters. The POS attribute of the expression defines a local numbering of the characters within the subframe. If n = 0, the expression references notext.

      If legal, the following Boolean expressions are true for any text variable X:

              X.sub(i,n).sub(j,m) == X.sub(i+j-1,m)
       
              n ne 0  imp  X.main == X.sub(i,n).main
       
              X.main.sub(X.start,X.length) == X
       
      Parameters:
      T - the argument text reference
      i - first character index
      n - number of charaters
      Returns:
      the resulting text reference
      Throws:
      RTS_SimulaRuntimeError - if the operation fail
    • strip

      public static RTS_TXT strip(RTS_TXT T)
      Procedure strip.

      The expression "X.strip" is equivalent to "X.sub(1,n)", where n indicates the position of the last non-blank character in X. If X does not contain any non-blank character, notext is returned.

      Let X and Y be text variables. Then after the value assignment "X:=Y", if legal, the relation "X.strip = Y.strip" has the value true, while "X = Y" is true only if X.length = Y.length.

      Parameters:
      T - the argument text reference
      Returns:
      the resulting text reference
    • getIntegerItem

      private static String getIntegerItem(RTS_TXT T)
      Scan the input text for an integer item.
       INTEGER-ITEM = SIGN-PART DIGITS
      
          SIGN-PART = BLANKS [ SIGN ] BLANKS
      
             SIGN = + | -
      
             DIGITS = DIGIT { DIGIT }
      
             DIGIT = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
       
      Parameters:
      T - the input text
      Returns:
      the resulting string
    • getint

      public static int getint(RTS_TXT T)
      Procedure getint.
       INTEGER-ITEM = SIGN-PART DIGITS
      
          SIGN-PART = BLANKS [ SIGN ] BLANKS
      
             SIGN = + | -
      
             DIGITS = DIGIT { DIGIT }
      
             DIGIT = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
       
      The procedure locates an INTEGER ITEM. The function value is equal to the corresponding integer.
      Parameters:
      T - the text reference
      Returns:
      the resulting real
    • getRealItem

      private static String getRealItem(RTS_TXT T)
      Scan the input text for a real item.
       REAL-ITEM = DECIMAL-ITEM [ EXPONENT ] | SIGN-PART EXPONENT
      
          DECIMAL-ITEM = INTEGER-ITEM [ FRACTION ] | SIGN-PART FRACTION
      
             INTEGER-ITEM = SIGN-PART DIGITS
      
             FRACTION = DECIMAL-MARK DIGITS
      
             SIGN-PART = BLANKS [ SIGN ] BLANKS
      
          EXPONENT = LOWTEN-CHARACTER INTEGER-ITEM
      
                SIGN = + | -
      
                DIGITS = DIGIT { DIGIT }
      
                DIGIT = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
      
                LOWTEN-CHARACTER = & | ...
      
                DECIMAL-MARK = . | ,
      
                BLANKS = { BLANK | TAB }
       
      Parameters:
      T - the input text
      Returns:
      the resulting string
    • getreal

      public static double getreal(RTS_TXT T)
      Procedure getreal.
       REAL-ITEM = DECIMAL-ITEM [ EXPONENT ] | SIGN-PART EXPONENT
      
          DECIMAL-ITEM = INTEGER-ITEM [ FRACTION ] | SIGN-PART FRACTION
      
             INTEGER-ITEM = SIGN-PART DIGITS
      
             FRACTION = DECIMAL-MARK DIGITS
      
             SIGN-PART = BLANKS [ SIGN ] BLANKS
      
          EXPONENT = LOWTEN-CHARACTER INTEGER-ITEM
      
                SIGN = + | -
      
                DIGITS = DIGIT { DIGIT }
      
                DIGIT = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
      
                LOWTEN-CHARACTER = & | ...
      
                DECIMAL-MARK = . | ,
      
                BLANKS = { BLANK | TAB }
       
      The procedure locates a REAL ITEM. The function value is equal to or approximates to the corresponding number. An INTEGER ITEM exceeding a certain implementation-defined range may lose precision when converted to long real.
      Parameters:
      T - the text reference
      Returns:
      the resulting real
    • getFracItem

      private static String getFracItem(RTS_TXT T)
      Scan the input text for a fraction item.
       GROUPED-ITEM = SIGN-PART GROUPS [ DECIMAL-MARK GROUPS ]
                    | SIGN-PART DECIMAL-MARK GROUPS
      
       SIGN-PART = BLANKS [ SIGN ] BLANKS
      
       SIGN = + | -
      
       GROUPS = DIGITS { BLANK DIGITS } DIGITS = DIGIT { DIGIT }
      
       DIGIT = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
       
      Parameters:
      T - the input text
      Returns:
      the resulting string
    • getfrac

      public static int getfrac(RTS_TXT T)
      Procedure getfrac.
       GROUPED-ITEM = SIGN-PART GROUPS [ DECIMAL-MARK GROUPS ]
                    | SIGN-PART DECIMAL-MARK GROUPS
      
       SIGN-PART = BLANKS [ SIGN ] BLANKS
      
       SIGN = + | -
      
       GROUPS = DIGITS { BLANK DIGITS } DIGITS = DIGIT { DIGIT }
      
       DIGIT = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
       
      The procedure locates a GROUPED ITEM. The function value is equal to the resulting integer. The digits of a GROUPED ITEM may be interspersed with BLANKS and a single DECIMAL MARK which are ignored by the procedure.
      Parameters:
      T - the text reference
      Returns:
      the resulting integer
    • putRealResult

      private static void putRealResult(RTS_TXT T, String output)
      Put the result of putReal type operation into the text T.
      Parameters:
      T - the text reference
      output - the result of putReal
    • putResult

      private static void putResult(RTS_TXT T, String s)
      Put the result of put... operation into the text T.

      If the text frame is too short to contain the resulting numeric item, the text frame into which the number was to be edited is filled with asterisks. The final value of the position indicator of X is X.length+1.

      Parameters:
      T - the text reference
      s - the result of put... operation
    • putint

      public static void putint(RTS_TXT T, int i)
      Procedure putint.

      The value of the parameter is converted to an INTEGER ITEM which designates an integer equal to that value.

      Parameters:
      T - the text reference
      i - the integer value to be edited
    • putfix

      public static void putfix(RTS_TXT T, double r, int n)
      Procedure putfix.

      The resulting numeric item is an INTEGER ITEM if n=0 or a DECIMAL ITEM with a FRACTION of n digits if n>0. It designates a number equal to the value of r or an approximation to the value of r, correctly rounded to n decimal places. If n<0, a run-time error is caused.

      Parameters:
      T - the text reference
      r - the long real value to be edited
      n - the number of digits after decimal sign
    • putreal

      public static void putreal(RTS_TXT T, double r, int n)
      Procedure putreal.

      The resulting numeric item is a REAL ITEM containing an EXPONENT with a fixed implementation-defined number of characters. The EXPONENT is preceded by a SIGN PART if n=0, or by an INTEGER ITEM with one digit if n=1, or if n>1, by a DECIMAL ITEM with an INTEGER ITEM of 1 digit only, and a fraction of n-1 digits. If n<0 a runtime error is caused.

      Parameters:
      T - the text reference
      r - the long real value to be edited
      n - the number of digits after decimal sign
    • putreal

      public static void putreal(RTS_TXT T, float r, int n)
      Procedure putreal.

      See putreal(RTS_TXT,double,int)

      Parameters:
      T - the text reference
      r - the real value to be edited
      n - the number of digits after decimal sign
    • addPlussExponent

      private static String addPlussExponent(String s)
      Real Edit Utility: Add plus exponent to the given string
      Parameters:
      s - the given string
      Returns:
      the resulting string
    • putfrac

      public static void putfrac(RTS_TXT T, int val, int n)
      Procedure putfrac.

      The resulting numeric item is a GROUPED ITEM with no DECIMAL MARK if n<=0, and with a DECIMAL MARK followed by total of n digits if n>0. Each digit group consists of 3 digits, except possibly the first one, and possibly the last one following a DECIMAL MARK. The numeric item is an exact representation of the number i * 10**(-n).

      Parameters:
      T - the text reference
      val - an integer value
      n - number of digits after a decimal mark