Exam Delay Exam II will be held during the first fifty (50) minutes of class on 13 November 2003.

Slides:



Advertisements
Similar presentations
COMPILER CONSTRUCTION WEEK-2: LANGUAGE DESCRIPTION- SYNTACTIC STRUCTURE:
Advertisements

Introduction to C Programming
Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
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.
Intermediate Code Generation
Statement-Level Control Structures
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.
Expressions and Statements. 2 Contents Side effects: expressions and statements Expression notations Expression evaluation orders Conditional statements.
COP4020 Programming Languages Expression and assignment Prof. Xin Yuan.
(8.1) COEN Control Structures  Control structure general issues  Compound statements  Selectors (conditional structures) – single – two-way –
Abstract Data Types Data abstraction, or abstract data types, is a programming methodology where one defines not only the data structure to be used, but.
Gary MarsdenSlide 1University of Cape Town Statements & Expressions Gary Marsden Semester 2 – 2000.
Chapter 7Louden, Programming Languages1 Chapter 7 - Control I: Expressions and Statements "Control" is the general study of the semantics of execution.
Louden, Chapter 7 - Control I: Expressions and Statements Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
ISBN Chapter 8 Statement-Level Control Structures.
1 Chapter 7: Expressions Expressions are the fundamental means of specifying computations in a programming language To understand expression evaluation,
Selection Statements choice of one among several blocks of code Java supports 3 kinds of selection statements: if statement – selects one block or leaves.
ISBN Chapter 8 Statement-Level Control Structures.
Control Structures. Hierarchical Statement Structure Standard in imperative languages since Algol60. Exceptions: Early FORTRAN, COBOL, early BASIC, APL.
true (any other value but zero) false (zero) expression Statement 2
Chapter 8 . Sequence Control
TYPE EQUIVALENCE 1) Coercion 2) Casting 3) Conversion.
Stacks. 2 What is a stack? A stack is a Last In, First Out (LIFO) data structure Anything added to the stack goes on the “top” of the stack Anything removed.
Chapter 7 Expressions and Assignment Statements. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Arithmetic Expressions Arithmetic evaluation.
ISBN Lecture 08 Statement-Level Control Structures.
Chapter 7Louden, Programming Languages1 Chapter 7 - Control I: Expressions and Statements "Control" is the general study of the semantics of execution.
UNIT II Decision Making And Branching Decision Making And Looping
Expressions & Assignments One of the original intentions of computer programs was the evaluation of mathematical expressions –languages would inherit much.
Sequence Control Chapter 6. 2 l Control structures: the basic framework within which operations and data are combined into programs. Sequence control.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 Relational Expressions Relational expressions: –Expressions that compare operands –Sometimes called conditions –Evaluated to yield a result –Typically.
PLLab, NTHU,Cs2403 Programming Languages Expression and control structure Kun-Yuan Hsieh Programming Language Lab., NTHU.
1 Control Flow: Expressions, Sequencing & Selection (Section ) A compilation of material developed by Felix Hernandez-Campos and Michael Scott.
ISBN Chapter 8 Statement-Level Control Structures.
Expressions and Statements. Expressions Literals and identifiers are expressions More complex expressions are built from simple expressions by the application.
第八章 敘述層級的控制結構 (Statement-Level Control Structures)
CSI 3120, Control, page 1 Control statements Simple statements Basic structured statements Sequence Selection Iteration The jump statement.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
CSE 425: Control Flow I Categories of Control Flow Constructs Sequencing –order of expressions and statements Selection –if, else, switch Iteration –loops.
Expressions and Assignment Statements
8-1 Statement-Level Control Structures Introduction Selection Statements Iterative Statements Unconditional Branching Guarded Commands Conclusions.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.1.
1 Iterative Statements Repeated execution of a (compound) statement by iteration or recursion –Iteration is statement level –Recursion is unit-level control.
Semantics (1).
Statement Level Flow of Control GOTOs and Other Weirdness Copyright © by Curt Hill.
Chapter 8 © 2002 by Addison Wesley Longman, Inc Introduction - Levels of Control Flow: 1. Within expressions 2. Among program units 3. Among program.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
Copyright © 2009 Elsevier Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
Semantics(1). 2 Symantec(1)  To provide an authoritative definition of the meaning of all language constructs for: 1.Programmers 2.Compiler writers 3.Standards.
CSE 3302 Programming Languages Chengkai Li, Weimin He Spring 2008 Control I Expressions and Statements Lecture 9 – Control I, Spring CSE3302 Programming.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Expressions and Assignment
8.1 Introduction - Levels of Control Flow: 1. Within expressions
Dr. Vamsi Paruchuri University of Central Arkansas
Expressions and Control Flow in JavaScript
Assignments A sample main program for Project 2 phase 2 is contained in: It reads.
Control statements Simple statements Basic structured statements
CSCI 3328 Object Oriented Programming in C# Chapter 4: C# Control Statement – Part I – Exercises UTPA – Fall 2012 This set of slides is revised from lecture.
Chapter 3: Introduction to Problem Solving and Control Statements
CSE 3302 Programming Languages
Chapter8: Statement-Level Control Structures April 9, 2019
Chap 7. Advanced Control Statements in Java
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
Basic statements Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
CSE 3302 Programming Languages
Presentation transcript:

Exam Delay Exam II will be held during the first fifty (50) minutes of class on 13 November 2003.

Control 1: Expressions and Statements Purist view: – An expression yields (or produces) a new value and causes no other side-effect. –A statement yields no value and is executed specifically because of some side-effect that it produces. –These distinctions are blurred in many languages nowadays (C, Java, Perl, Ruby,...) in which expressions can have side effects, and can be treated as statements. In fact, in such languages, statements are often treated as a special case of expressions yielding null or void values.

Expressions Expressions are typically defined recursively to be: 1.primitive operands (such as literals and variable references) 2.operations or functions applied to expression arguments Operations are usually written using infix notation, but different languages have supported both prefix (lisp) and postfix (Forth) notation. Function call is expressed using prefix notation in most languages, but some languages use postfix. Language built-in operations are typically inserted into a precedence hierarchy and associativity (left or right). Nowadays the distinction between built-in operations and functions are somewhat blurred. In days gone by, compilers would almost always generate inline code for operations, but subprogram calls for functions.

Applicative vs. Normal Order Evaluation Applicative order evaluation is the typical order used in implementing programming languages. (Some refer to this as programming language order.) It requires that each operand be evaluated before its operator is applied. Although Louden refers to this as strict evaluation, his use of the term is somewhat loose. Strict evaluation refers to bottom- preserving evaluation of operations on a lattice (or complete partial order). This essentially means that if one component of an expression is undefined, the result of the expression will be undefined. Normal order evaluation is less common and is typically seen in functional languages. In normal order evaluation, no operation is evaluated unless its value is required in order to construct the result value for an expression. In fact, most languages mix the two orders. Think of && and || of C as well as and then and or else of Ada as being instances of normal order creeping into an otherwise applicative order language. In typical programming languages, control structures such as if-then- else introduce applicative rather than normal order evaluation.

Dijkstra’s Guarded if Extremely general and powerful construct: if B1 -> S1 | B2 -> S2... | Bn -> Sn fi If one of the guards Bi is true, execute Si. Otherwise, yield an error. If more than one guard is true, choose the one to execute nondeterministically. It is not specified whether or not all guards are to be evaluated.

If statements If appears in many closely related forms in various programming languages. It can be viewed as the following restriction on the guarded if: if B -> S1 | ~B -> S2 fi Dangling else problem. How is it solved? –bracketing keyword –most closely nested if Too many elses problem: –Add keyword elseif

Case/Switch Like guarded command of following sort: if x = v1 -> S1 | x = v2 -> S2... | x = vn -> Sn Problems: –C: fall-through to next case (avoided with break ) –C: labels are just labels. Misspelling default causes pain and suffering.