Module Simula

Class SwitchStatement


public final class SwitchStatement extends Statement
Switch Statement. This is a S-PORT extension to the language.
 
 Syntax:
 
 switch-statement = SWITCH ( lowKey : hiKey ) switchKey BEGIN { switch-case } [ none-case ] END [ otherwise-case ]
 
      switch-case = WHEN caseKey-list do statement ;
      
      none-case   = WHEN NONE do statement ;
      
      otherwise-case = OTHERWISE statement ;
      
         caseKey-list = caseKey { , caseKey }
      
            caseKey = caseConstant  | caseConstant : caseConstant
            
               caseConstant = integer-or-character-constant
      
      lowKey = integer-or-character-expression
      hiKey = integer-or-character-expression
      switchKey = integer-or-character-expression

 Translated into a Java Switch Statement with break after each statement.
 
 Example:
 
   switch(lowkey:hikey) key
   begin
      when 0 do statement-0 ;
      ...
      when none do statement-e ;
   end
   
   Is compiled into Java-code:
   
   if(key < lowkey || key > hikey) throw new RTS_SimulaRuntimeError("Switch key outside key interval");
   switch(key) {
       case 0: statement-0; break;
       ...
       default: statement-e; break;
   }
   
 
Link to GitHub: Source File.
Author:
Øystein Myhre Andersen
  • Field Details

  • Constructor Details

    • SwitchStatement

      SwitchStatement(int line)
      Create a new SwitchStatement.
      Parameters:
      line - the source line number
  • Method Details

    • expectCasePair

      private SwitchStatement.SwitchInterval expectCasePair()
      Parse Utility: Expect case pair.
      Returns:
      the resulting SwitchInterval
    • doChecking

      public void doChecking()
      Description copied from class: SyntaxClass
      Perform semantic checking.

      This must be redefined in every subclass.

      Overrides:
      doChecking in class SyntaxClass
    • doJavaCoding

      public void doJavaCoding()
      Description copied from class: SyntaxClass
      Output Java code.
      Overrides:
      doJavaCoding in class Statement
    • print

      public void print(int indent)
      Description copied from class: SyntaxClass
      Utility print method.
      Overrides:
      print in class SyntaxClass
      Parameters:
      indent - number of spaces leading the line
    • printTree

      public void printTree(int indent)
      Description copied from class: SyntaxClass
      Utility print syntax tree method.
      Overrides:
      printTree in class SyntaxClass
      Parameters:
      indent - number of spaces leading the lines
    • toString

      public String toString()
      Overrides:
      toString in class Object