Interface Program

All Superinterfaces:
ProgramKernel, Standard<Program>
All Known Implementing Classes:
Program1, ProgramSecondary

public interface Program extends ProgramKernel
ProgramKernel enhanced with secondary methods.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    BugsWorld virtual machine instructions and "byte codes".
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    A constant, with value 4, holding the number of spaces added for each indentation level when pretty printing a Program object.
  • Method Summary

    Modifier and Type
    Method
    Description
    Generates and returns the sequence of virtual machine instructions ( "byte codes") corresponding to this.
    void
    parse(Queue<String> tokens)
    Parses a BL program from tokens into this.
    void
    Parses a BL program from in into this.
    void
    Pretty prints this to the given stream out using INDENT_SIZE spaces for each indentation level.

    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

      static final int INDENT_SIZE
      A constant, with value 4, holding the number of spaces added for each indentation level when pretty printing a Program object.
      See Also:
  • Method Details

    • prettyPrint

      Pretty prints this to the given stream out using INDENT_SIZE spaces for each indentation level.
      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

      void parse(SimpleReader in)
      Parses a BL program from in into this.
      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

      void parse(Queue<String> tokens)
      Parses a BL program from tokens into this.
      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 to this.
      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]