CSc 520 - Principles of Programming Languages
26 : Control Structures -- Introduction

Christian Collberg

Department of Computer Science

University of Arizona

1 Control Flow

2 Control Flow -- Paradigms


Operators


3 Prefix, Infix, Postfix

4 Smalltalk -- Binary Messages

5 Smalltalk -- Keyword Messages

6 Operator Precedence

7 Operator Associativity

8 Case Study -- C

9 Case Study -- C...

 
  OPERATOR KIND PREC ASSOC
  a[k] Primary 16
  f(23#23) Primary 16
  . Primary 16
  -> Primary 16
  a++, a-- Postfix 15
  ++a, --a Unary 14
  ~ Unary 14
  ! Unary 14
  - Unary 14
  & Unary 14
  * Unary 14
  OPERATOR KIND PREC ASSOC
  *, /, % Binary 13 Left
  +, - Binary 12 Left
  <<, >> Binary 11 Left
  <, >, <=, >= Binary 10 Left
  == != Binary 9 Left
  & Binary 8 Left
  ^ Binary 7 Left
  | Binary 6 Left
  && Binary 5 Left
  || Binary 4 Left
  ? : Ternary 3 Right
  =, +=, -=, *=, /=, %=, <<=, >>=, &=, ^=, |= Binary 2 Right
  , Binary 1 Left


Variables


10 Value vs. Reference Model

11 Value vs. Reference Model...


Expressions


12 Order of Evaluation

13 Order of Evaluation...

14 Case Study -- Pascal


Control-Flow Statements


15 Statement vs. Expression Orientation

16 Unstructured Control-Flow

17 Case Study -- Pascal: goto

 
24#24

25#25


Statements -- Selection


18 Case Study -- Pascal: if


26#26

19 Case Study -- Modula-2: if


27#27

20 Case Study -- Pascal: case


28#28

21 Case Study -- C: case


29#29

22 Case Study -- FORTRAN: goto


Statements -- Iteration


23 Case Study -- Pascal: for


30#30

24 Case Study -- Modula-2: FOR

25 Case Study -- Modula-3: FOR

26 Case Study -- Modula-3: FOR


33#33

27 Case Study -- Modula-3: FOR...


34#34

28 Case Study -- Pascal: loops


35#35

29 Case Study -- Modula-2: loops

30 Case Study -- Algol 60

31 Case Study -- Algol 60...


Recursion


32 Tail Recursion

33 Tail Recursion...


38#38

34 Tail Recursion...

35 Tail Recursion...

(define (fact n) 
 (if (= n 1)
     1
     (* n (fact (- n 1)))))

(define (fact-cps n C)
  (if (= n 1)
      (C 1)
      (fact-cps (- n 1) (
           lambda(v) (C (* n v))))))

(fact-cps 5 (lambda(v) (display v)))

36 Readings and References



Christian Collberg 2008-03-26