DSL Design
- Control flow in DSLs
- We will study a number of alternatives
− traditional sequencers:
− sequential q − conditional − iterative
− jumps, low-level sequencers to transfer control − escapes, sequencers to transfer control out of commands and procedures − exceptions, sequencers to signal abnormal situations
/ Faculteit Wiskunde en Informatica
PAGE 0 3-1-2011
DSL Design
- Jumps/GOTOs
A j f l ifi d i
- A jump transfers control to a specified program point
- A jump has typical the form goto L; and transfer the control
to program point L, which is a label
if (E1) C1 else { C2 goto X; } C3; while (E2) { C4; C4; X: C5 }
/ Faculteit Wiskunde en Informatica
PAGE 1 3-1-2011
DSL Design
- Unrestricted jumps lead to spaghetti code, thus hard to
nderstand see understand, see http://www.cs.utexas.edu/users/EWD/ewd02xx/EWD215.PDF
- Most (programming) languages support gotos
- Most (programming) languages support gotos
- Some languages have restrictions:
- the jump goto L; is legal only within the scope of L
- the jump goto L; is legal only within the scope of L
− jumps within a block − jumps from a block to an enclosing one − jumps into a block from outside is not allowed
/ Faculteit Wiskunde en Informatica
PAGE 2 3-1-2011
DSL Design
- A jump out of a block must destroy the local
j y variables
- Jumps out of a procedure should lead to destroying
local variables and termination of procedure local variables and termination of procedure activation
- jumps out of a recursive procedure is semantically
even more complicated
Jumps introduce unwanted complexity in the
- Jumps introduce unwanted complexity in the
semantics of languages
/ Faculteit Wiskunde en Informatica
PAGE 3 3-1-2011