140 likes | 334 Views
CHAPTER 8 SEQUENCE CONTROL. Hardware- Von Neumann architecture (sequence from incrementing program counter); loop and conditional from test and jump (branch) Control Abstraction includes intramodule, intermodule, and concurrent module control Implicit or explicit. Expressions.
E N D
CHAPTER 8 SEQUENCE CONTROL • Hardware- Von Neumann architecture (sequence from incrementing program counter); loop and conditional from test and jump (branch) • Control Abstraction includes intramodule, intermodule, and concurrent module control • Implicit or explicit
Expressions • Precedence rules (consider exponentiation) • Tree-structure • Execution time representation when operand values are determined • prefix; postfix to avoid ambiguity • Ex: Forth and Lisp • Side effects • X := A + fun (A) where fun (A) changes the value of A • What is the value of the expression? • What if A itself must be evaluated? Should A be fetched once or twice? (compiler optimization an issue) • Ada’s approach – allow side effects; but if different results occur they are erroneous
Error conditions (exceptions) • Divide by 0, overflow, underflow • In Ada, orthogonality combines all types of errors, such as input errors in Exception handling
Short-circuit boolean operators • In Ada, and .. then; or.. else • and / or are not short circuit • In C, C++, Java, && || are short circuit Optimization • Program structure if (x != 0 ) if (a/x > 5)
Intramodule Scalar (unstructured) statements Assignment Input Parameter passing Go to/ break/ (multiple) exit/multiple entries Composite Conditional Discuss case (switch) Discuss nested if Loop Perform 5 (times) Test at bottom of Fortran do loop Recursion Infinite (for servers, etc.)
Exceptions Program controlled termination on serious error COBOL – on size error (compiler supplied code), PL/1 Ada : user defined exceptions identical to system defined ones Constraint_Error, Storage_Error, Tasking_Error Exceptions propagate dynamic stack C++ assert Java – try
SNOBOL4 (from the textbook) * Output longest odd length bit string palindrome start grammar = 0 | 1 | 0 *grammar 0 | 1 *grammar 1 * add 00 and 11 to the above loop newline = TRIM (INPUT) : f(end) newline (POS (0) SPAN (“01”) RPOS(0)) : f(bad) sn = SIZE (newline) next newline POS(0) grammar . palindrome POS(sn) :s(match) f(not) match OUTPUT = “MATCH:” “ “ palindrome : loop not sn = sn – 1 : next bad OUTPUT = “improper input:” “ “ newline : loop end