Sequence Control Syntax and Semantics Jian Xu March 3, 2004 CS706, CAS McMaster.

Slides:



Advertisements
Similar presentations
ICE1341 Programming Languages Spring 2005 Lecture #13 Lecture #13 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Advertisements

Programming Languages and Paradigms
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
CSCI 330: Programming Language Concepts Instructor: Pranava K. Jha Control Flow-II: Execution Order.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Event structures Mauro Piccolo. Interleaving Models Trace Languages:  computation described through a non-deterministic choice between all sequential.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
(8.1) COEN Control Structures  Control structure general issues  Compound statements  Selectors (conditional structures) – single – two-way –
ISBN Chapter 3 Describing Syntax and Semantics.
DATAFLOW PROCESS NETWORKS Edward A. Lee Thomas M. Parks.
Programming Language Semantics Denotational Semantics Chapter 5 Based on a lecture by Martin Abadi.
ISBN Chapter 8 Statement-Level Control Structures.
ALGOL 60 Design by committee of computer scientists: Naur, Backus, Bauer, McCarthy, van Wijngaarden, Landin, etc. Design by committee of computer scientists:
PZ07B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ07B - Basic statements Programming Language Design.
Programming Language Semantics Denotational Semantics Chapter 5 Part II.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this.
ISBN Chapter 8 Statement-Level Control Structures.
Data Flow Analysis Compiler Design October 5, 2004 These slides live on the Web. I obtained them from Jeff Foster and he said that he obtained.
A Denotational Semantics For Dataflow with Firing Edward A. Lee Jike Chong Wei Zheng Paper Discussion for.
Data Flow Analysis Compiler Design Nov. 8, 2005.
Describing Syntax and Semantics
Programming Language Semantics Denotational Semantics Chapter 5 Part III Based on a lecture by Martin Abadi.
ISBN Lecture 08 Statement-Level Control Structures.
1 Program Analysis Mooly Sagiv Tel Aviv University Textbook: Principles of Program Analysis.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
COMP4730/2002/lec8/H.Melikian Statement-Level Control Structures Introduction Compound Statements Selection Statements Iterative Statements Unconditional.
Imperative Programming
Program Analysis and Verification
ดร.สุรศักดิ์ มังสิงห์ SPU, Computer Science Dept.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Control Structures Programs have 4 basic control structures:
CPS120: Introduction to Computer Science Decision Making in Programs.
Chapter 8 Chapter 8 Control Structures. Control Structures  A control structure is a control statement and the statements whose execution it controls.
ISBN Chapter 8 Statement-Level Control Structures.
1 CS Programming Languages Class 11 September 26, 2000.
第八章 敘述層級的控制結構 (Statement-Level Control Structures)
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
CSI 3120, Control, page 1 Control statements Simple statements Basic structured statements Sequence Selection Iteration The jump statement.
Control Structures CPS120: Introduction to Computer Science Lecture 5.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
8-1 Statement-Level Control Structures Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions.
Chapter 3 Part II Describing Syntax and Semantics.
Syntax and Semantics CIS 331 Syntax: the form or structure of the expressions, statements, and program units. Semantics: the meaning of the expressions,
April 16, ICE 1341 – Programming Languages (Lecture #14) In-Young Ko Programming Languages (ICE 1341) Lecture #14 Programming Languages (ICE 1341)
Copyright © 1998 by Addison Wesley Longman, Inc. 1 Chapter 7 Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program statements.
1 Iterative Statements Repeated execution of a (compound) statement by iteration or recursion –Iteration is statement level –Recursion is unit-level control.
CSI 3125, Subprograms, page 1 Subprograms General concepts Parameter passing Functions Subprograms as parameters.
Chapter 8 © 2002 by Addison Wesley Longman, Inc Introduction - Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program.
W E E K F I V E Statement-Level Control Structures.
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Functional Programming
Def: A control structure is a control statement and
8.1 Introduction - Levels of Control Flow: 1. Within expressions
Statement-Level Control Structures
Chapter 8: Control Structures
FORTRAN 04 February 1999; CS655.
Syntax Questions 6. Define a left recursive grammar rule.
Control statements Simple statements Basic structured statements
Control Structures In Text: Chapter 8.
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
Rosen 5th ed., §2.1 ~31 slides, ~1 lecture
Data Flow Analysis Compiler Design
Programming Languages 2nd edition Tucker and Noonan
Chapter 8: Statement Level Control Structures
Programming Languages
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Subprograms General concepts Parameter passing Functions
PZ07B - Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Presentation transcript:

Sequence Control Syntax and Semantics Jian Xu March 3, 2004 CS706, CAS McMaster

2 Imperative programming: describes computation in terms of program state and statements that change the state. Almost all hardware implementation is imperative. The program state is the contents of memory, and the statements are instructions. Higher-level imperative languages use variables and more complex statements. Support assignment, looping, conditional branching, and unconditional branching. FORTRAN, COBOL, Pascal, Ada

3 Unconditional branch FORTRAN –GOTO 21 –ASSIGN 21 to K; GOTO K –GOTO (n 1, n 2, …, n p ), I COBOL –GOTO L 1, L 2, …, L n DEPENDING ON, I. Pascal –GOTO statement labels Ada –GOTO statement –exit & exit LOOP-LABEL

4 Syntax - Conditional branch FORTRAN –IF expr n neg, n zero, n pos. –IF expr statement. –IF expr THEN statements ELSE IF expr THEN statements … ELSE statements END IF COBOL –IF expr statements ELSE statements Pascal –if expr then statement. Ada –if expr then statements elsif expr then statements … else statements end if;

5 Semantics – conditional branch Operational Denotational Axiomatic

6 Semantics – conditional branch Operational Denotational Axiomatic

7 Syntax - case Pascal case expr of const: statement; … const: statement end Ada case expr is when choice => statement; … when others => statement end

8 Semantics - case Operational Denotational Axiomatic

9 Semantics - case Operational Denotational Axiomatic

10 Syntax - loops FORTRAN Do label index = init-val, final-val, incr-val COBOL PERFORM L1 THRU Ln k TIMES PERFORM L1 THRU Ln UNTIL. Parcal for index := init-val to final-val do statement while expr do statement repeat statement until expr Ada loop statements end loop; for index in range loop statement end loop; while expr loop statement end loop;

11 Semantics – while loop Operational Denotational Axiomatic

12 Syntax - subprogram FORTRAN FUNCTION fun-nam (formal-par-lst) COBOL PERFORM L1 THRU Ln. Parcal function fun-name (var-lst:type): result-type; procedure proc-name (var-lst:type; var var-lst:type); Ada function fun-name (var-lst: in type): result-type is procedure proc-name (var-lst: in type; var-lst: out type; var-lst: in out type is

13 Semantics - subprogram Only 4 kinds of statement, namely assignment, sequential, conditional, and procedure call. All procedures are declared globally before use, formally, Procedure call do not allow argument passing mechanism. Recursive calls as well as mutual recursive calls are allowed.

14 Semantics -subprogram Operational Denotational Axiomatic

15 Concepts recall cpo is a partially ordered set satisfying (1) each chain has a least upper bound, (2) it has a bottom element. A function F: C 1 → C 2 is monotonic if,  x, y in C 1, if x  y, then F(x)  F(y). A function F: C 1 → C 2 is continuous if, for each chain x = x 1,x 2, … in C 1, F(  x) =  F(x i ). is a cpo, where StateTrans is the set all state transformations f: State → State. f 1  f 2 iff  σ f 1 (σ)  f 2 (σ)  and f 1 (σ)=f 2 (σ) If we understand function as set of mappings, then f 1  f 2 iff f 1 is a subset of f 2. The bottom is the totally undefined function or empty set. Thus, for a any chain f = f 1,f 2, …,  f is simply the union  f.

16 Semantics - subprogram First we need to show F 1, …, F n are continuous with respect to f 1, …, f n. This can be done by structure induction on statement S. Then we can define the least fix points as follows by generalized Tarski’s Theorem. We can prove the equivalence of these semantics by induction on the approximation steps k.

17 Remark - continuity If function f is continuous, we can approximate the function value of a least upper bound of a chain by the function values of all components of the chain. Say, π=  (3,3.1,3.14, …), f(π)=  (f(3),f(3.1),f(3.14), …). In λ calculus, we each expression denotes a function which can apply to any other. This imply that we need a so call reflexive domain, in the sense that the domain is isomorphic to its function space. The domain of continuous functions turns out to be a choice.