java.lang.Object
simula.compiler.syntaxClass.SyntaxClass
simula.compiler.syntaxClass.statement.Statement
simula.compiler.syntaxClass.statement.SwitchStatement
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
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate class
Utility class SwitchIntervalprivate class
Utility class WhenPart. -
Field Summary
Modifier and TypeFieldDescriptionprivate final Expression
The high keyprivate final Expression
The low key.private final Vector
<SwitchStatement.WhenPart> The list of When partsprivate Expression
The switchKeyFields inherited from class simula.compiler.syntaxClass.SyntaxClass
lineNumber
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Perform semantic checking.void
Output Java code.private SwitchStatement.SwitchInterval
Parse Utility: Expect case pair.void
print
(int indent) Utility print method.void
printTree
(int indent) Utility print syntax tree method.toString()
Methods inherited from class simula.compiler.syntaxClass.statement.Statement
expectStatement
Methods inherited from class simula.compiler.syntaxClass.SyntaxClass
ASSERT_SEMANTICS_CHECKED, doDeclarationCoding, edIndent, edTreeIndent, IS_SEMANTICS_CHECKED, SET_SEMANTICS_CHECKED, toJavaCode
-
Field Details
-
lowKey
The low key. -
hiKey
The high key -
switchKey
The switchKey -
switchCases
The list of When parts
-
-
Constructor Details
-
SwitchStatement
SwitchStatement(int line) Create a new SwitchStatement.- Parameters:
line
- the source line number
-
-
Method Details
-
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 classSyntaxClass
-
doJavaCoding
public void doJavaCoding()Description copied from class:SyntaxClass
Output Java code.- Overrides:
doJavaCoding
in classStatement
-
print
public void print(int indent) Description copied from class:SyntaxClass
Utility print method.- Overrides:
print
in classSyntaxClass
- 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 classSyntaxClass
- Parameters:
indent
- number of spaces leading the lines
-
toString
-