Level 6 Features

The theme of Level 6 is “dynamic semantics of BabyCobol”, so focus mostly on:

  • blending the compiler and the runtime if you are building a compiler
  • blending the interpreter internals and the execution environment if you have an interpreter

Features:

  • (6XP): computable GO TO
    • You probably already have a "GO TO <label>" from level 4.
    • Now let's implement "GO TO <field>".
    • This variant accepts an identifier as a target of a GO TO, and the actual control flow depends on the runtime value of this named field.
    • If there is no paragraph with the name corresponding to the current value of the field, a runtime error occurs.
  • (6XP): ALTER
    • If there is a paragraph named X, which contains a single sentence with a single statement GO TO Y, then it is possible to alter the target of that statement to Z, by writing ALTER X TO PROCEED TO Z.
    • GO TO statements that are not single statements in their paragraph, cannot be ALTERed.
    • ALTERed computable GO TO becomes a normal GO TO after alteration.
    • The new target must be a valid paragraph name.
    • Any acceptable GO TO statement can be ALTERed any number of times, and each change is "permanent" until another change happens.
  • (6XP): SIGNAL
    • This statement can be used for global exception handling: if a paragraph name is specified (e.g., SIGNAL X ON ERROR), then from that point on, any fatal error (division by zero, aborted input, wrong computable GO TO, anything) causes the transfer of control to the designated paragraph X instead of program termination.
    • Activation of a SIGNAL paragraph acts more like a GO TO than a PERFORM, so it terminates any ongoing LOOPs and PERFORMs, and does not return automatically to the point of failure.
    • If another fatal error happens during the execution of the SIGNAL paragraph, it causes abnormal termination normally.
    • If execution continues beyond the SIGNAL paragraph, any fatal errors trigger another execution of the SIGNAL paragraph.
    • Normal error handling by program termination can be resumed with SIGNAL OFF ON ERROR