Module Simula

Class SimulaScanner

java.lang.Object
simula.compiler.parsing.DefaultScanner
simula.compiler.parsing.SimulaScanner

public final class SimulaScanner extends DefaultScanner
The Simula Scanner.

Link to GitHub: Source File.

Author:
Øystein Myhre Andersen
  • Field Details

    • EOF_MARK

      private static final int EOF_MARK
      ISO EM(EndMedia) character used to denote end-of-input
      See Also:
    • EOF_SEEN

      private boolean EOF_SEEN
      Set 'true' when EOF-character ( -1 ) was read.
    • puchBackStack

      private Stack<Character> puchBackStack
      The pushBack stack
    • accum

      private StringBuilder accum
      StringBuilder used to accumulate input strings for Simula Editor.
    • editorMode

      private final boolean editorMode
      Editor mode. Set when the scanner is used by Simula Editor
    • tokenQueue

      private LinkedList<Token> tokenQueue
      The Token queue. The method nextToken will pick Tokens from the queue first.
    • sourceFileReader

      SourceFileReader sourceFileReader
      The current source file reader;
    • selector

      public static boolean[] selector
      The selector array.
    • pardepth

      private int pardepth
      NOTE: An initial "-" in array upper bound may follow : directly (cf. 1.3). The scanner will treat ":-" within parentheses (round brackets) as two separate symbols ":" and "-" thus solving this ambiguity in the syntax.

      This variable is used to cover such situations.

    • prevChar

      private int prevChar
      The previous character read.
    • current

      private int current
      The current character read.
  • Constructor Details

    • SimulaScanner

      public SimulaScanner(Reader reader, boolean editorMode)
      Constructs a new SimulaScanner that produces Items scanned from the specified source.
      Parameters:
      reader - The character source to scan
      editorMode - true: delivers tokens to the SimulaEditor
  • Method Details

    • insert

      void insert(File file)
      Insert a file.
      Parameters:
      file - the file to be inserted
    • close

      void close()
      Close the scanner.
    • nextToken

      public Token nextToken()
      Description copied from class: DefaultScanner
      Returns the next Token.
      Overrides:
      nextToken in class DefaultScanner
      Returns:
      the next Token
    • scanToken

      private Token scanToken()
      Scan and return a Token.
       End-Condition: current is last character of construct
                      getNext will return first character after construct
       
      Returns:
      next Token
    • scanBasic

      private Token scanBasic()
      Scan basic Token
      Returns:
      next Token
    • javaKeyword

      private Token javaKeyword(String name)
      Scanner Utility: Create an Java-name Token.
      Parameters:
      name - the Token's Java-name
      Returns:
      an identifier Token
    • identifierToken

      private Token identifierToken(String name)
      Scanner Utility: Create an identifier Token.
      Parameters:
      name - the Token's name
      Returns:
      an identifier Token
    • scanIdentifier

      private Token scanIdentifier()
      Scan and return an identifier Token.
       End-Condition: current is last character of construct
                      getNext will return first character after construct
       
      Returns:
      next Token
    • scanNumber

      private Token scanNumber()
      Scan a unsigned number.
        Reference-Syntax:
            unsigned-number
              = decimal-number  [  exponent-part  ]
              | exponent-part
            decimal-number
              = unsigned-integer  [  decimal-fraction  ]
              | decimal-fraction
            decimal-fraction
              = .  unsigned-integer
            exponent-part
              =  ( & | && )  [ + | - ]  unsigned-integer
            unsigned-integer
              =  digit  {  digit  |  _  }
              |  radix  R  radix-digit  {  radix-digit  |  _  radix-digit  }
            radix
              =  2  |  4  |  8  |  16
            radix-digit
              =  digit  |  A  |  B  |  C  |  D  |  E  |  F
       
      End-Condition:
      • current is last character of construct
      • getNext will return first character after construct
      Returns:
      A Token representing a unsigned number.
    • scanDotDigit

      private Token scanDotDigit(StringBuilder number)
      Scan decimal-fraction possibly followed by an exponent-part. And append it to the given number.
       Reference-Syntax:
       
            decimal-fraction = .  unsigned-integer
            
            
       End-Condition: current is last character of construct                 
                      getNext will return first character after construct
       
      Parameters:
      number - The edited number so far
      Returns:
      next Token
    • scanDigitsExp

      private Token scanDigitsExp(StringBuilder number)
      Scan exponent-part. And append it to the given number.
       Reference-Syntax:
       
            exponent-part =  ( & | && )  [ + | - ]  unsigned-integer
       
      Pre-Condition: First & is already read End-Condition: current is last character of construct getNext will return first character after construct
      Parameters:
      number - The edited number so far
      Returns:
      next Token
    • scanName

      private String scanName()
      Scan identifier or reserved name.
       Reference-Syntax:
       
          identifier = letter  { letter  |  digit  |  _  }
          
          
       End-Condition: current is last character of construct
                      getNext will return first character after construct
       
      Returns:
      the resulting identifier
    • scanCharacterConstant

      private Token scanCharacterConstant()
      Scan and deliver a Character constant.
        Reference-Syntax:   
                                                         
            character-constant  = '  character-designator  '
            
            character-designator
               = iso-code
               |  non-quote-character
               |  "
               
               iso-code =  ! digit  [ digit ]  [ digit ]  !
             
             
       End-Condition: current is last character of construct
                      getNext will return first character after construct
       
      Returns:
      next Token
    • scanTextConstant

      private Token scanTextConstant()
      Scan and deliver a Text constant.
        Reference-Syntax:   
                                                         
            string = simple-string  {  string-separator  simple-string  }
            
               simple-string = " { iso-code |  non-quote-character  |  ""  }  "
               
                  iso-code = ! digit  [ digit ]  [ digit ]  !
                  
               string-separator = token-separator  {  token-separator  }
               
                  token-separator
                      = a direct comment
                      |  a space  { except in simple strings and character constants }
                      |  a format effector  { except as noted for spaces }
                      |  the separation of consecutive lines
              
              
       End-Condition: current is last character of construct
                      getNext will return first character after construct
       
      Returns:
      next Token
    • currentIsStringSeparator

      private boolean currentIsStringSeparator()
      Scanner Utility: Check if current is a string separator.
        Reference-Syntax:
        
            string-separator = token-separator  {  token-separator  }
            
               token-separator
                  = a direct comment
                  | a space  { except in simple strings and character constants }
                  | a format effector  { except as noted for spaces }
                  | the separation of consecutive lines
              
              
       End-Condition: current is last character of construct
                      getNext will return first character after construct
       
      Returns:
      true if current is a string separator
    • scanPossibleIsoCode

      private int scanPossibleIsoCode()
      Scanner Utility: Scan possible iso-code
        Reference-Syntax:
        
            iso-code =  ! digit  [ digit ]  [ digit ]  !
             
       
       Pre-Condition: The leading character ! is already read
       
       End-Condition: current is last character of construct
                      getNext will return first character after construct
       
      Returns:
      the resulting iso-code
    • scanDirectiveLine

      private Token scanDirectiveLine()
      Scan a %Directive line
        Reference-Syntax:
        
            directive =  % { any character except end-of-line }
      
        A conditional line takes the form:
          
                      %selector-expression text-line
      
              where text-line represents the line to be conditionally included
              and the selector-expression has the form:
      
                      Selector-expression
                              = selector-group { selector-group }
      
                      Selector-group
                              = + letter_or_digit { letter_or_digit }
                              | - letter_or_digit { letter_or_digit }
      
              i.e. a string of letters and signs, with the first character being a sign.
              The selector-expression is terminated by a SPACE.
      
      
       End-Condition: current is last character of construct
                      getNext will return first character after construct
       
      Returns:
      a Comment Token
    • readUntilEndofLine

      private String readUntilEndofLine()
      Utility: Read until end-of-line.
      Returns:
      the string read
    • setSelectors

      private void setSelectors()
      %SELECT select-character { select-character }

      Set selectors for conditional compilation.

    • lineSelected

      private boolean lineSelected()
      Determine if current line is selected.
      Returns:
      true if current line is selected
    • scanComment

      private Token scanComment()
      Scan a Comment.
       Reference-Syntax:
       
             comment = COMMENT { any character except semicolon } ;
             
             
       End-Condition: current is last character of construct 
                      getNext will return first character after construct
       
      Returns:
      a Comment Token
    • scanCommentToEndOfLine

      private Token scanCommentToEndOfLine()
      Scan Comment to end-of-line.
       Reference-Syntax:
       
             comment = -- { any character until end-of-line }
             
             
       End-Condition: current is last character of construct 
                      getNext will return first character after construct
       
      Returns:
      a Comment Token
    • scanEndComment

      private Token scanEndComment()
      Scan end-comment.
       reference-Syntax:
       
             The sequence:
             
                END { any sequence of printable characters not containing END, ELSE, WHEN, OTHERWISE or ; }
                
             is equivalent to:
             
                END
       
       
       End-Condition: current is last character of construct
                      getNext will return first character after construct
       
      Returns:
      next Token
    • getNext

      private int getNext()
      Returns next input character.
      Returns:
      next input character
    • pushBack

      private void pushBack(int chr)
      Push a character onto the puchBackStack.
      Parameters:
      chr - character to be pushed
    • pushBack

      private void pushBack(String s)
      Push a string onto the puchBackStack.
      Parameters:
      s - string to be pushed
    • newToken

      private Token newToken(KeyWord keyWord, Object value)
      Create a new Token
      Parameters:
      keyWord - the KeyWord
      value - the value
      Returns:
      the newly created Token
    • newToken

      private Token newToken(KeyWord keyWord)
      Create a new Token without a value
      Parameters:
      keyWord - the KeyWord
      Returns:
      the newly created Token
    • edcurrent

      private String edcurrent()
      Utility: Edit current character.
      Returns:
      edited current character
    • isHexDigit

      private boolean isHexDigit(int c)
      Utility: Check if a character is a hex digit.
      Parameters:
      c - the character
      Returns:
      true if character c is a hex digit
    • isPrintable

      private boolean isPrintable(int c)
      Utility: Check if a character is printable.
      Parameters:
      c - the character
      Returns:
      true if character c is printable
    • isWhiteSpace

      private boolean isWhiteSpace(int c)
      Utility: Check if a character is a whiteSpace.
      Parameters:
      c - the character
      Returns:
      true if character c is a whiteSpace