Class SwitchStatement
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
Nested ClassesModifier and TypeClassDescriptionprivate class
Utility class SwitchIntervalprivate class
Utility class SwitchWhenPart. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Label
The beginning of the default handler block.private Label
The end label.private boolean
Indicator: har NONE case.private Expression
The high keyprivate List
<SwitchCase> The lookupSwitc cases.private Expression
The low key.private final Vector
<SwitchStatement.SwitchWhenPart> The list of When partsprivate Expression
The switchKeyFields inherited from class simula.compiler.syntaxClass.SyntaxClass
CHECKED, lineNumber, OBJECT_SEQU
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Default constructor used by Attribute File I/O(package private)
SwitchStatement
(int line) Create a new SwitchStatement. -
Method Summary
Modifier and TypeMethodDescriptionvoid
buildByteCode
(CodeBuilder codeBuilder) Build Java ByteCode.private void
buildSwitchKeyTest
(CodeBuilder codeBuilder) ClassFile coding utility: buildSwitchKeyTest.void
Perform semantic checking.void
Output Java code.private SwitchStatement.SwitchInterval
Parse Utility: Expect case pair.void
print
(int indent) Utility print method.void
Utility print syntax tree method.static SwitchStatement
Read and return an object.toString()
void
Write a SyntaxClass object to a AttributeOutputStream.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, setLineNumber, toJavaCode
-
Field Details
-
lowKey
The low key. -
hiKey
The high key -
switchKey
The switchKey -
switchCases
The list of When parts -
lookupSwitchCases
The lookupSwitc cases. -
has_NONE_case
private boolean has_NONE_caseIndicator: har NONE case. -
defaultTarget
The beginning of the default handler block. -
endLabel
The end label.
-
-
Constructor Details
-
SwitchStatement
SwitchStatement(int line) Create a new SwitchStatement.- Parameters:
line
- the source line number
-
SwitchStatement
private SwitchStatement()Default constructor used by Attribute File I/O
-
-
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
-
buildByteCode
Description copied from class:Statement
Build Java ByteCode.- Overrides:
buildByteCode
in classStatement
- Parameters:
codeBuilder
- the codeBuilder to use.
-
buildSwitchKeyTest
ClassFile coding utility: buildSwitchKeyTest.- Parameters:
codeBuilder
- the codeBuilder to use.
-
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
Description copied from class:SyntaxClass
Utility print syntax tree method.- Overrides:
printTree
in classSyntaxClass
- Parameters:
indent
- number of spaces leading the lineshead
- the head of the tree.
-
toString
-
writeObject
Description copied from class:SyntaxClass
Write a SyntaxClass object to a AttributeOutputStream.- Overrides:
writeObject
in classSyntaxClass
- Parameters:
oupt
- the AttributeOutputStream to write to.- Throws:
IOException
- if something went wrong.
-
readObject
Read and return an object.- Parameters:
inpt
- the AttributeInputStream to read from- Returns:
- the object read from the stream.
- Throws:
IOException
- if something went wrong.
-