Control - Continuation and Exceptions Control flow in...

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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
Image of page 6
cs3723 7 Exception: Alternative Way of Return In C: can we tell whether “x” is in “l”?
Image of page 7

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern