These are the (mostly) complete static and dynamic context conditions for SIMPLE; you have to enforce them in the assignment where you interpret SIMPLE programs. A subset of these already had to be enforced when we built the abstract syntax tree for expressions and instructions.
PROGRAMand the identifier after the corresponding
ENDmust be identical; that identifier is not added to the symbol table however.
Typeproduction (i.e. the first alternative) must denote a type; it is an error if that identifier denotes anything else (a constant or a variable).
ARRAYmust be constant (see above), of type integer, and greater than zero.
MODoperators must not evaluate to zero.
Factorproduction must denote a variable or a constant, i.e. it cannot denote a type.
Assignproduction must denote a variable. The type of the left-hand side must be compatible with the type of the right-hand side under occurrence equivalence (aka “name equivalence”), i.e. they must refer to the same type object in the symbol table. Note that you can assign arrays and records.
Conditionproduction must both be of type integer, i.e. you cannot compare arrays or records.
Writeproduction must be of type integer, i.e. you cannot output arrays or records.
Readproduction must denote a variable of type integer, i.e. you cannot input arrays or records.
stdinas part of a
READinstruction must denote an integer; the value of that integer must be within implementation-defined limits. (This should be handled the same way as integer literals in the scanner, except that a leading
-is now possible.)
Designatorproduction must denote a variable or a constant, i.e. it cannot denote a type.
” are only applicable to variables of array type; the type resulting from a single selector application is the element type of the array type; the type of each expression in the
ExpressionListmust be integer.
”) must evaluate to an integer between zero and one less than the length of the corresponding array type.
.” are only applicable to variables of record type; the type resulting from a single selector application is the field type of the denoted field.
The only things missing now are properties of the target architecture,
for example regarding the size of an