CSE 326, Spring 1995: Pseudocode Manual

This document contain the pseudocode syntax that we will be using in homeworks. This document will change over time as needed. The basic rules are:
  1. Do not bother with declarations unless really needed. Describing the various fields of a record type always helps. Similarly, the range of arrays always helps. Use indentation to improve clarity. All pseudocode will either be a procedure or function.
  2. Procedures and functions: Do not bother with indicating call by reference or value. We assume that all large objects such as arrays are passed by reference and small items such as integers are passed by value.
  3. Sequences of statements: Separate by with semicolons and group using curly brackets, { }, when needed.
  4. Conditionals: if "condition" then "statement" or if "condition" then "statement1" else "statement2".
  5. While loop: while "condition" do "statement".
  6. Repeat loop: repeat "statement" until "condition".
  7. for loop: for i = "start index" to "end index" do "statement". Occationally, there may be a need for stepping by more than 1, in which case, we have for i = "start index" to "end index" by "step" do "statement".
  8. Records and pointers: If p is a pointer to a record with field x, the field can be accessed using the notation p.x. Generally it will be clear from context what are pointers and what are not.
  9. Memory management: We assume a simple memory management scheme where an object of any type can be obtained by using the term "new", usually a pointer is returned. Don't bother to destroy objects unless it is required. We'll just assume an infinite amount of new memory.
  10. Arrays: to obtain the i-th item from array A, simply write A[i].
  11. Assignment: use :=
  12. Boolean operators: use and, or, not, implies
  13. Equals operator: use = for any simple objects such as pointers and integers.
  14. Arithmetic operators: use +, -, *, ^, /, mod for integer addition, subtraction, multiplication, exponetiation, division (yields the quotient), and division (yields the remainder).
  15. (4/3/95) Feel free to use a basic case control structure. I recommend "case" followed by a sequence of "condition": "statement". The semantics is that the statement following the first true condition is executed.
  16. (4/3/95) It is probably best to declare the local variables of a procedure or function by type. In addition, it is probably a good idea to list the paramenters by type and any return value by type.
ladner@cs.washington.edu (last update 4/3/95)