Control - Continuation and Exceptions Control flow in...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
cs3723 1 Continuation and Exceptions Control flow in sequential languages
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs3723 2 Topics Control flow --- ordering of sequential statements Structured Programming (Goto considered harmful) Exceptions --- dynamic jump to exit in unusual situations Structured goto that may return a value Dynamic scoping of exception handler Continuation --- dynamic re-enterable evaluation Function representing the rest of the expression In functional programming, the rest of program Include the enclosing environment as part of function closure Convert expressions/functions to statements/loops Manual control of evaluation order (force and delay) Use function definitions to put off computations Use function calls to force the evaluation of computations Details skipped
Background image of page 2
cs3723 3 Imperative programming Control Flow of Programs Structured control flow Sequence of statements { a:= b; b := c; } Conditional if (a < b) then c else d; switch(a){…} Loops for (…) {…}; while (…) {…}; Jumping out of a scope break, continue, return,… Non-structured control flow Goto, conditional jump Used to implement structured control flow in assembly
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs3723 4 Fortran Control Structure 10 IF (X .GT. 0.000001) GO TO 20 11 X = -X IF (X .LT. 0.000001) GO TO 50 20 IF (X*Y .LT. 0.00001) GO TO 30 X = X-Y-Y 30 X = X+Y ... 50 CONTINUE X = A Y = B-A GO TO 11 Similar structure may occur in assembly code
Background image of page 4
cs3723 5 Static and Dynamic Jumps Structured jumps among logical blocks if … then … else … end while … do … end for … { … } case … break continue Function calls and return Avoid non-structured jumps Explicit goto jumps into middle of block or function body Is the destination always known at compile-time? Static jumps: destination known before evaluating code If-then-else, while, for, break, goto, break, continue, calling a function by its static name Dynamic jumps:destination not know until runtime Calling a function pointer, function return Need to store the destination address in runtime stack
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
cs3723 6 Exception: A Structured Dynamic Jump A normal jump is a static “goto label” Label is defined statically as the destination of jump Label is defined in an enclosing scope of the jump Examples L:{ … continue… }: jump to start of current scope {…break…}L: jump to end of current scope {…return…}L: jump to end of current function An exception is a dynamic jump Don’t know where to resume execution until runtime Jump out of current block Look for a matching exception handler in enclosing scopes Use dynamic scoping rule instead of static scoping
Background image of page 6
cs3723 7 Exception: Alternative Way of Return In C: can we tell whether “x” is in “l”? struct IntList { int x; IntList* rest;}
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/13/2009 for the course CS 3773 taught by Professor Staff during the Spring '08 term at The University of Texas at San Antonio- San Antonio.

Page1 / 25

Control - Continuation and Exceptions Control flow in...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online