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:
-
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.
-
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.
-
"procedure name"("list of arguments separated by commas");
-
"function name"("list of arguments separated by commas"); Somewhere in the
body of the function there must be a return statement.
-
Sequences of statements: Separate by with semicolons and group using
curly brackets, { }, when needed.
-
Conditionals: if "condition" then "statement" or if "condition" then
"statement1" else "statement2".
-
While loop: while "condition" do "statement".
-
Repeat loop: repeat "statement" until "condition".
-
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".
-
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.
-
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.
-
Arrays: to obtain the i-th item from array A, simply write A[i].
-
Assignment: use :=
-
Boolean operators: use and, or, not, implies
-
Equals operator: use = for any simple objects such as pointers and integers.
-
Arithmetic operators: use +, -, *, ^, /, mod for integer addition, subtraction,
multiplication, exponetiation, division (yields the quotient), and division
(yields the remainder).
- (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.
- (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)