Module Simula

Class Parse

java.lang.Object
simula.compiler.parsing.Parse

public final class Parse extends Object
The Simula Parser Utilities.

It contains all static utilities for parsing Simula Syntax.

The Simula Compiler uses Recursive Descent Parsing. Each syntax class is a subclass of this class.

A NonTerminal object represents non terminal symbol in the formal syntax.

Parsing descends in a top-down manner, until the final nonterminal has been processed. The parsing process depends on a global variable, currentToken, which contains the current symbol from the input, and the function nextToken, which updates currentToken when called.

For further description of Recursive Descent Parsing see Wikipedia.

 
 ***********************************************************************        
  META-SYNTAX:
  
       MetaSymbol                    Meaning
       
           =                     is defined to be
           |                     alternatively
         [ x ]                   0 or 1 instance of x
         { x }                   0 or more instances of x
       ( x | y )                 grouping: either x or y
          xyz                    the terminal symbol xyz
     MetaIdentifier              a non terminal symbol
 ***********************************************************************
 
Link to GitHub: Source File.
Author:
Øystein Myhre Andersen
  • Field Details

    • savedToken

      private static Token savedToken
      The saved Token used by 'pushBack'
    • endOfFileErrorGiven

      private static boolean endOfFileErrorGiven
      Indicate that endOfFile error is given
    • simulaScanner

      private static SimulaScanner simulaScanner
      The SimulaScanner
    • prevToken

      public static Token prevToken
      The previous Token.
    • currentToken

      public static Token currentToken
      The current Token.
  • Constructor Details

    • Parse

      Parse()
      Default constructor.
  • Method Details

    • initiate

      public static void initiate(Reader reader)
      Initiate Parsing utilities.
      Parameters:
      reader - the source file reader.
    • close

      public static void close()
      Close the Simula scanner.
    • saveCurrentToken

      public static void saveCurrentToken()
      Save current Token
    • nextToken

      public static void nextToken()
      Advance to next Token.
    • accept

      public static boolean accept(KeyWord... key)
      Test to accept a KeyWord.

      Test currentToken against each given key. If accepted 'nextToken' is called, thus setting prevToken.

      Parameters:
      key - t the given keywords
      Returns:
      true if a keyword is accepted, false otherwise.
    • expect

      public static boolean expect(KeyWord key)
      Expect the given KeyWord.

      If it is not accepted an error message is given.

      Parameters:
      key - a keyword
      Returns:
      true if the keyword was accepted, otherwise false
    • skipMisplacedCurrentSymbol

      public static void skipMisplacedCurrentSymbol()
      Skip misplaced current symbol.
    • acceptIdentifier

      public static String acceptIdentifier()
      Test to accept an identifier.
      Returns:
      the identifier or null
    • expectIdentifier

      public static String expectIdentifier()
      Test to expect an identifier.

      If failing to do so, an error is printed.

      Returns:
      the identifier or null
    • acceptType

      public static Type acceptType()
      Test to accept a Type.
      Returns:
      the type or null
    • acceptPostfixOprator

      public static boolean acceptPostfixOprator()
      Test to accept a postfix operator ( DOT, IS, IN, QUA).
      Returns:
      true if the keyword is accepted, false otherwise.
    • acceptRelationalOperator

      public static boolean acceptRelationalOperator()
      Test to accept a relational operator.
                       value-relational-operator
                           =  <  |  <=  |  =  |  >=  |  >  |  <> | == | =/=
       
      Returns:
      true if the keyword is accepted, false otherwise.
    • TRACE

      public static void TRACE(String msg)
      Utility TRACE.
      Parameters:
      msg - a message