Package components.program
Interface Program
- All Superinterfaces:
ProgramKernel
,Standard<Program>
- All Known Implementing Classes:
Program1
,ProgramSecondary
ProgramKernel
enhanced with secondary methods.-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic enum
BugsWorld virtual machine instructions and "byte codes". -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
A constant, with value 4, holding the number of spaces added for each indentation level when pretty printing aProgram
object. -
Method Summary
Modifier and TypeMethodDescriptionGenerates and returns the sequence of virtual machine instructions ( "byte codes") corresponding tothis
.void
Parses a BL program fromtokens
intothis
.void
parse
(SimpleReader in) Parses a BL program fromin
intothis
.void
prettyPrint
(SimpleWriter out) Methods inherited from interface components.program.ProgramKernel
name, newBody, newContext, setName, swapBody, swapContext
Methods inherited from interface components.standard.Standard
clear, newInstance, transferFrom
-
Field Details
-
INDENT_SIZE
A constant, with value 4, holding the number of spaces added for each indentation level when pretty printing aProgram
object.- See Also:
-
-
Method Details
-
prettyPrint
- Parameters:
out
- the output stream- Updates:
out.content
- Requires:
out.is_open
- Ensures:
out.content = #out.content * [this pretty printed using INDENT_SIZE spaces for indentation]
-
parse
Parses a BL program fromin
intothis
.- Parameters:
in
- the input stream- Updates:
in.content
- Replaces:
this
- Requires:
in.is_open
- Ensures:
if #in.content = [a program string] and [the last token of #in.content equals the name of the program supplied near the beginning] and [the beginning name of each new instruction equals its ending name] and [none of the names of the new instructions equals the name of a primitive instruction in the BL language or the name of any other new instruction] then this = [Program corresponding to program string #in.content] and in.content = <> else [reports an appropriate error message to the console and terminates client]
-
parse
Parses a BL program fromtokens
intothis
.- Parameters:
tokens
- the input tokens- Updates:
tokens
- Replaces:
this
- Requires:
[<Tokenizer.END_OF_INPUT> is a suffix of tokens]
- Ensures:
if #tokens = [a program string] * <Tokenizer.END_OF_INPUT> and [the penultimate token of #tokens equals the name of the program supplied near the beginning] and [the beginning name of each new instruction equals its ending name] and [none of the names of the new instructions equals the name of a primitive instruction in the BL language or the name of any other new instruction] then this = [Program corresponding to program string at start of #tokens] and tokens = <Tokenizer.END_OF_INPUT> else [reports an appropriate error message to the console and terminates client]
-
generatedCode
Generates and returns the sequence of virtual machine instructions ( "byte codes") corresponding tothis
.- Returns:
- the compiled program
- Ensures:
if [all instructions called in this are either primitive or defined in this.context] and [this does not include any calling cycles, i.e., recursion] then generatedCode = [the sequence of virtual machine "byte codes" corresponding to this] else [reports an appropriate error message to the console and terminates client]
-