Skip to content

Pseudocode Format

Luke Ceddia edited this page Nov 2, 2020 · 8 revisions

The REAL pseudocode format

The Refinement Explanation Animation Language (REAL) is used internally to specify the pseudocode that is displayed to the user. It consists of lines of arbitrary human-readable pseudocode with machine-interpreted tags.

Examples

See src/algorithms/pseudocode for examples of REAL files.

The tags

All tags begin with a backslash (\), but because they are used in JavaScript strings you effectively need to use double backslash (\\).

The full list of tags:

  • \Note{ Start of a note for developers and programmers. A note is not displayed in AIA.
  • \Note} End of a note. All text between the start of the note and the end of the note, plus any trailing newline, is ignored for the purposes of display.
  • \Code{ Start of a pseudocode code block, that is, a chunk of pseudocode. The rst line of a block is a label that uniquely refers to that block, and is not displayed. The label for the top level code block is always Main. Other code blocks are refinements, that is expansions, of lines of code that appear elsewhere. The block label links the block with the line of code it is expanding, see \Ref below. Subsequent lines of a block, after the identifier, are the pseudocode, plus the relevant explanations or other directives.
  • \Code} End of a code block.
  • \Ref A line of code may end in \Ref, followed by a label that names another code block. The \Ref directive shows that the line of pseudocode is expandable: the user can perform an action, such as a mouse click, to replace the line by the code block of the name specified by \Ref. Similarly, the code block specified by \Ref can be condensed, to show, once again, the original line of pseudocode.
  • \BA line of code may end inB`, followed by a label. These are bookmarks, and are referenced by the actual algorithm implementation for the purposes of synchronising the animation and pseudocode.
  • \Expl{ Start of an explanation. This directive appears after a line of pseudocode (usually on the next line), and is a plain language explanation of the preceding pseudocode. The explanation is shown in the explanation display (not directly in the pseudocode) when requested by the user by clicking on the explanation icon.
  • \Expl} End of an explanation. All text between the start and end of the explanation is shown only in the explanation panel.
  • \In{ Used within code blocks to specify deeper indentation. The lines of pseudocode between \In{ and \In} will be indented one level more than the current indentation level.
  • \In} End an indentation block.

Usage notes

  • Each line of pseudocode should either have a \Ref, meaning in can be expanded, or \B. A line without either Ref or B cannot be stopped on by the step-by-step execution, and cannot have any associated animation.
  • All \B labels and \Ref labels must be unique.
Clone this wiki locally