# Chapter 7 Expressions and Assignment statements

Size: px
Start display at page:

## Transcription

1 Chapter 7 Expressions and Assignment statements 1

2 7.1 Introduction Expressions are the fundamental means of specifying computations in a programming language Semantics of expressions are discussed in this Chapter To understand the expression evaluation, it is necessary to be familiar with the orders of operator and operand evaluation The essence of the imperative programming languages is the dominant role of assignment statements 2

3 7.2 Arithmetic Expressions Automatic evaluation of arithmetic expressions similar to those found in mathematics, science, and engineering was one of the primary goals of the first highlevel programming language. Arithmetic expressions consist of Operator, operands, parentheses, and function calls 3

4 7.2 Arithmetic Expressions Design issues for arithmetic expressions Operator precedence rules? Operator associativity rules? Order of operand evaluation? Operand evaluation side effects? Operator overloading? Type mixing in expressions? 4

5 7.2.1 Operator Evaluation Order The operator precedence rules for expression evaluation define the order in which adjacent operators of different precedence levels are evaluated Typical precedence levels parentheses unary operators ** (if the language supports it) *, / +, - 5

6 7.2.1 Operator Evaluation Order (Cont d) The operator associativity rules for expression evaluation define the order in which adjacent operators with the same precedence level are evaluated Typical associativity rules Left to right, except **, which is right to left Sometimes unary operators associate right to left (e.g., in FORTRAN) APL is different; all operators have equal precedence and all operators associate right to left Precedence and associativity rules can be overridden with parentheses 6

7 Conditional Expressions Conditional Expressions C-based languages (e.g., C, C++) An example: average = (count == 0)? 0 : sum / count Evaluates as if written as follows: if (count == 0) else average = 0 average = sum /count 7

8 7.2.2 Operand Evaluation Order Variables Fetch the value from memory Constants: Sometimes a fetch from memory; sometimes the constant is in the machine language instruction Parenthesized expressions: evaluate all operands and operators first The most interesting case is when an operand is a function call 8

9 Side Effects A side effect of a function occurs when the function changes either one of its parameters or a global variable 9

10 Side Effects (Cont d) Problem with functional side effects: When a function referenced in an expression alters another operand of the expression; e.g., for a parameter change: a = 10; /* assume that fun changes its parameter */ b = a + fun(&a); 10

11 The following program compiled with gcc version (Ubuntu/Linaro ubuntu4). The execution result is a=20. int a=5; int fun1() { a=17; return 3; } void main() { a=a+fun1(); printf( a=%d\n,a); } 11

12 Side Effects (Cont d) Note that functions in mathematics do not have side effects, because there is no notion of variables in mathematics. 12

13 Side Effects (Cont d) Two possible solutions to the problem 1. Write the language definition to disallow functional side effects No two-way parameters in functions No non-local references in functions Advantage: it works! Disadvantage: inflexibility of one-way parameters and lack of non-local references 2. Write the language definition to demand that operand evaluation order be fixed Disadvantage: limits some compiler optimizations Java requires that operands appear to be evaluated in left-to-right order 13

14 Referential Transparency and Side Effects A program has the property of referential transparency if any two expressions in the program that have the same value can be substituted for one another anywhere in the program, without affecting the action of the program result1 = (fun(a) + b) / (fun(a) c); temp = fun(a); result2 = (temp + b) / (temp c); If fun has no side effects, result1 = result2 Otherwise, not, and referential transparency is violated 14

15 Referential Transparency and Side Effects Advantage of referential transparency Semantics of a program is much easier to understand if it has referential transparency Because they do not have variables, programs in pure functional languages are referentially transparent Functions cannot have state, which would be stored in local variables If a function uses an outside value, it must be a constant (there are no variables). So, the value of a function depends only on its parameters 15

16 7.3 Overloaded Operators Use of an operator for more than one purpose is called operator overloading Some are common (e.g., + for int and float) It is generally thought to be acceptable, as long as neither readability nor reliability suffers 16

17 7.3 Overloaded Operators (Cont d) Some are potential trouble E.g. * in C and C++ x=&y; c=a&b; Loss of compiler error detection (omission of an operand should be a detectable error) Some loss of readability 17

18 7.3 Overloaded Operators (Cont d) Some languages that support abstract data types, for example, C++, C#, and F#, allow the programmer to further overload operation symbols See next slice C++ has a few operators that cannot be overloaded. Structure member operator (.) and scope resolution operation (::) Interestingly, operator overloading was one of the C++ features that was not copied in to Java However, it did reappear in C# 18

19 #include <iostream.h> class Complex { public: Complex(double=0.0,double=0.0); Complex operator +(Complex); Complex add(complex); void Print(); private: double Real; }; double Imag; //Constructor Complex::Complex(double r, double i) { Real = r; Imag = i; } // implementation of addition operator Complex Complex::operator +(Complex CNum) { Complex C; C.Real = Real + CNum.Real; C.Imag = Imag + CNum.Imag; return C; } Complex Complex::add(Complex CNum) { Complex C; C.Real = Real + CNum.Real; C.Imag = Imag + CNum.Imag; return C; } // implementation of print function // void Complex::Print() { cout << "Complex Number= "<<Real<<"+i"<<Imag<<endl; } // simple main program // int main() { // Declare objects of complex class Complex x(22,2), y(11,3),z; } z=x+y; 19

20 7.4 Type Conversions Type conversions are either narrowing or widening A narrowing conversion is one that converts an object to a type that cannot include all of the values of the original type e.g., float to int A widening conversion is one in which an object is converted to a type that can include at least approximations to all of the values of the original type e.g., int to float 20

21 7.4 Type Conversions (Cont d) Widening conversions are nearly always safe, meaning that the magnitude of the converted value is maintain It can result in reduced accuracy 32-bit integer allows at least nine decimal digits of precision 32-bit float-point values are with only about seven decimal digits of precision 21

22 7.4.1 Coercion in Expressions One of the design decisions concerning arithmetic expressions is whether an operator can have operands of different types Mixed-mode expression Must define conversions for implicit operand type conversions Because computers do not have binary operations that take operands of different types 22

23 7.4.1 Coercion in Expressions (Cont d) Mixed-mode expression For overloaded operators in a language that uses static type binding, the compiler chooses the correct type of operation on the basis of the types of the operands Language designers are not in agreement on the issue of coercions in arithmetic expressions. Reduce the benefits of type checking 23

24 7.4.1 Coercion in Expressions (Cont d) int a; float b, c, d; d=b*a; //a is a keying error Because mixed-mode expressions are legal in Java, the compiler would not detect this as an error F# and ML do not allow 24

25 7.4.2 Explicit Type Conversion Most languages provide some capabiity for doing explicit conversions, Widening and narrowing Warning messages may be produced Called casting in C-based languages Examples C: (int)angle F#: float(sum) 25

26 7.4.3 Errors in Expressions If the language requires type checking, then operand type errors cannot occur Other kinds of errors: Inherent limitations of arithmetic e.g., division by zero Limitations of computer arithmetic e.g. overflow Often ignored by the run-time system 26

27 7.6 Short-Circuit Evaluation A short-circuit evaluation of an expression is one in which the result is determined without evaluating all of the operands and/or operators Example: (13 * a) * (b / 13 1) If a is zero, there is no need to evaluate (b/13-1) However, in arithmetic expressions, this shortcut is not easily detected, so it is never taken 27

28 7.6 Short-Circuit Evaluation (Cont d) Unlike the case of arithmetic expressions, the shortcut of Boolean expression can be easily discovered. (a>=0) && (b<10) 28

29 7.6 Short-Circuit Evaluation (Cont d) Problem with non-short-circuit evaluation SCE and non-sce are with different execution results index = 0; while ((index<=listlen) && (list[index]!= key) index=index+1; A language that provides SCEs of Boolean expressions and also has side effects in expressions allows subtle errors to occur (a>b) ((b++)/3) 29

30 7.6 Short-Circuit Evaluation (Cont d) Ada solution: by using two-word operations to activate SCE (The best solution) and then, or else In C-based language, the usual AND and OR operations, && and, respectively, are short-circuit. 30

31 7.7 Assignment Statements The general syntax <target_var> <assign_operator> <expression> The assignment operator = Fortran, BASIC, the C-based languages := Ada, Pascal = can be bad when it is overloaded for the relational operator for equality (that s why the C- based languages use == as the relational operator) 31

32 7.7.2 Conditional Targets Conditional targets (Perl) (\$flag? \$total : \$subtotal) = 0 Which is equivalent to if (\$flag){ \$total = 0 } else { } \$subtotal = 0 32

33 7.7.3 Compound Assignment Operators A shorthand method of specifying a commonly needed form of assignment Introduced in ALGOL; adopted by C and the C- based languaes Example a = a + b can be written as a += b 33

34 7.7.4 Unary Assignment Operators Unary assignment operators in C-based languages combine increment and decrement operations with assignment Examples sum = ++count (count incremented, then assigned to sum) sum = count++ (count assigned to sum, then incremented count++ (count incremented) -count++ (count incremented then negated) 34

35 7.7.5 Assignment as an Expression In the C-based languages, Perl, and JavaScript, the assignment statement produces a result and can be used as an operand while ((ch = getchar())!= EOF){ } ch = getchar() is carried out; the result (assigned to ch) is used as a conditional value for the while statement Disadvantage: another kind of expression side effect 35

36 7.7.6 Multiple Assignments Perl, Ruby, and Lua allow multiple-target multiple-source assignments (\$first, \$second, \$third)=(20, 30, 40); Also, the following is legal and performs an interchange: (\$first, \$second)=(\$second, \$first); 36

37 7.8 Mixed-Mode Assignment Assignment statements can also be mixedmode In Fortran, C, Perl, and C++, any numeric type value can be assigned to any numeric type variable In Java and C#, only widening assignment coercions are done In Ada, there is no assignment coercion 37

38 Summary Expressions Operator precedence and associativity Operator overloading Mixed-type expressions Various forms of assignment 38

### Software II: Principles of Programming Languages. Why Expressions?

Software II: Principles of Programming Languages Lecture 7 Expressions and Assignment Statements Why Expressions? Expressions are the fundamental means of specifying computations in a programming language

### Chapter 7. Expressions and Assignment Statements

Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

### Chapter 7. Expressions and Assignment Statements ISBN

Chapter 7 Expressions and Assignment Statements ISBN 0-321-49362-1 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit

### Chapter 7. Expressions and Assignment Statements (updated edition 11) ISBN

Chapter 7 Expressions and Assignment Statements (updated edition 11) ISBN 0-321-49362-1 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean

### Chapter 7. Expressions and Assignment Statements

Chapter 7 Expressions and Assignment Statements Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

### Expressions and Assignment Statements

Expressions and Assignment Statements Introduction Expressions are the fundamental means of specifying computations in a programming language To understand expression evaluation, need to be familiar with

### Chapter 7. Expressions and Assignment Statements ISBN

Chapter 7 Expressions and Assignment Statements ISBN 0-321-33025-0 Chapter 7 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit

### Expressions & Assignment Statements

Expressions & Assignment Statements 1 Topics Introduction Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment Statements

### Concepts of Programming Languages

Concepts of Programming Languages COMP322 Fall 2012/2013 1-1 Textbook ISBN 0-321-49362-1 Chapter 1 Preliminaries ISBN 0-321-49362-1 Chapter 1 Topics Reasons for Studying Concepts of Programming Languages

### CSE 452: Programming Languages. Outline of Today s Lecture. Expressions. Expressions and Control Flow

CSE 452: Programming Languages Expressions and Control Flow Outline of Today s Lecture Expressions and Assignment Statements Arithmetic Expressions Overloaded Operators Type Conversions Relational and

### Chapter7 Expression and Assignment Statement. Introduction

Chapter7 Expression and Assignment Statement Arithmetic Expressions Overloaded Operators Boolean Expressions Short-Circuit Evaluation Assignment Statements Mixed-Mode Assignment Introduction Fundamental

### Expression Evaluation and Control Flow. Outline

Expression Evaluation and Control Flow In Text: Chapter 6 Outline Notation Operator Evaluation Order Operand Evaluation Order Overloaded operators Type conversions Short-circuit evaluation of conditions

### Relational Expressions. Boolean Expressions. Boolean Expressions. ICOM 4036 Programming Languages. Boolean Expressions

ICOM 4036 Programming Languages Ch7. Expressions & Assignment Statements Arithmetic Expressions Overloaded Operators Type Conversions Relational and Boolean Expressions Short-Circuit Evaluation Assignment

### 9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

Outline Expression Evaluation and Control Flow In Text: Chapter 6 Notation Operator evaluation order Operand evaluation order Overloaded operators Type conversions Short-circuit evaluation of conditions

### Expressions and Assignment

Expressions and Assignment COS 301: Programming Languages Outline Other assignment mechanisms Introduction Expressions: fundamental means of specifying computations Imperative languages: usually RHS of

### Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1 Topics 1. Expressions 2. Operator precedence 3. Shorthand operators 4. Data/Type Conversion 1/15/19 CSE 1321 MODULE 2 2 Expressions

### Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

### Programming Languages, Summary CSC419; Odelia Schwartz

Programming Languages, Summary CSC419; Odelia Schwartz Chapter 1 Topics Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation Criteria Influences on Language Design

### Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### G Programming Languages - Fall 2012

G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing

### Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

### Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

### UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . \$, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

### Operators. Java operators are classified into three categories:

Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

Lecture Set 4: More About Methods and More About Operators Methods Definitions Invocations More arithmetic operators Operator Side effects Operator Precedence Short-circuiting main method public static

### 9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Outline Name, Scope and Binding In Text: Chapter 5 Names Variable Binding Type bindings, type conversion Storage bindings and lifetime Scope Lifetime vs. Scope Referencing Environments N. Meng, S. Arthur

### More Programming Constructs -- Introduction

More Programming Constructs -- Introduction We can now examine some additional programming concepts and constructs Chapter 5 focuses on: internal data representation conversions between one data type and

### Java Primer 1: Types, Classes and Operators

Java Primer 1 3/18/14 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M. H. Goldwasser, Wiley, 2014 Java Primer 1: Types,

### Full file at

Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

### Chapter 4: Basic C Operators

Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional

### Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Expressions 1 Expressions n Variables and constants linked with operators Arithmetic expressions n Uses arithmetic operators n Can evaluate to any value Logical expressions n Uses relational and logical

### CSC 533: Organization of Programming Languages. Spring 2005

CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms

### Arithmetic Operators. Portability: Printing Numbers

Arithmetic Operators Normal binary arithmetic operators: + - * / Modulus or remainder operator: % x%y is the remainder when x is divided by y well defined only when x > 0 and y > 0 Unary operators: - +

### Chapter 9 Subprograms

Chapter 9 Subprograms We now explore the design of subprograms, including parameter-passing methods, local referencing environment, overloaded subprograms, generic subprograms, and the aliasing and problematic

### CHAPTER 3 Expressions, Functions, Output

CHAPTER 3 Expressions, Functions, Output More Data Types: Integral Number Types short, long, int (all represent integer values with no fractional part). Computer Representation of integer numbers - Number

### Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

### Operators and Expressions

Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

### LECTURE 3 C++ Basics Part 2

LECTURE 3 C++ Basics Part 2 OVERVIEW Operators Type Conversions OPERATORS Operators are special built-in symbols that have functionality, and work on operands. Operators are actually functions that use

### Zheng-Liang Lu Java Programming 45 / 79

1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

### Chapter 3: Operators, Expressions and Type Conversion

101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To

### Programming for Engineers Iteration

Programming for Engineers Iteration ICEN 200 Spring 2018 Prof. Dola Saha 1 Data type conversions Grade average example,-./0 class average = 23450-67 893/0298 Grade and number of students can be integers

### LECTURE 17. Expressions and Assignment

LECTURE 17 Expressions and Assignment EXPRESSION SYNTAX An expression consists of An atomic object, e.g. number or variable. An operator (or function) applied to a collection of operands (or arguments)

### Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

Class #07: Java Primitives Software Design I (CS 120): M. Allen, 13 Sep. 2018 Two Types of Types So far, we have mainly been dealing with objects, like DrawingGizmo, Window, Triangle, that are: 1. Specified

### Organization of Programming Languages CS 3200/5200N. Lecture 09

Organization of Programming Languages CS 3200/5200N Razvan C. Bunescu School of Electrical Engineering and Computer Science bunescu@ohio.edu Control Flow Control flow = the flow of control, or execution

### Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

### Operators. Lecture 3 COP 3014 Spring January 16, 2018

Operators Lecture 3 COP 3014 Spring 2018 January 16, 2018 Operators Special built-in symbols that have functionality, and work on operands operand an input to an operator Arity - how many operands an operator

### Operators and Expressions:

Operators and Expressions: Operators and expression using numeric and relational operators, mixed operands, type conversion, logical operators, bit operations, assignment operator, operator precedence

### Outline. Performing Computations. Outline (cont) Expressions in C. Some Expression Formats. Types for Operands

Performing Computations C provides operators that can be applied to calculate expressions: tax is 8.5% of the total sale expression: tax = 0.085 * totalsale Need to specify what operations are legal, how

### Motivation for typed languages

Motivation for typed languages Untyped Languages: perform any operation on any data. Example: Assembly movi 5 r0 // Move integer 5 (some representation) to r0 addf 3.6 r0 // Treat bit representation in

### 22c:111 Programming Language Concepts. Fall Types I

22c:111 Programming Language Concepts Fall 2008 Types I Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified

### St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad-00 014 Subject: PPL Class : CSE III 1 P a g e DEPARTMENT COMPUTER SCIENCE AND ENGINEERING S No QUESTION Blooms Course taxonomy level Outcomes UNIT-I

### Type Bindings. Static Type Binding

Type Bindings Two key issues in binding (or associating) a type to an identifier: How is type binding specified? When does the type binding take place? N. Meng, S. Arthur 1 Static Type Binding An explicit

### Reserved Words and Identifiers

1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

### C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

### Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00

### Chapter 5 Names, Binding, Type Checking and Scopes

Chapter 5 Names, Binding, Type Checking and Scopes Names - We discuss all user-defined names here - Design issues for names: -Maximum length? - Are connector characters allowed? - Are names case sensitive?

### Primitive Data Types: Intro

Primitive Data Types: Intro Primitive data types represent single values and are built into a language Java primitive numeric data types: 1. Integral types (a) byte (b) int (c) short (d) long 2. Real types

### Unit 3. Operators. School of Science and Technology INTRODUCTION

INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

### Operators & Expressions

Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.

### Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes 長庚大學資訊工程學系 陳仁暉 助理教授 Tel: (03) 211-8800 Ext: 5990 E-mail: jhchen@mail.cgu.edu.tw URL: http://www.csie.cgu.edu.tw/jhchen All rights reserved. No part

Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

### ISA 563 : Fundamentals of Systems Programming

ISA 563 : Fundamentals of Systems Programming Variables, Primitive Types, Operators, and Expressions September 4 th 2008 Outline Define Expressions Discuss how to represent data in a program variable name

### Programming in C++ 6. Floating point data types

Programming in C++ 6. Floating point data types! Introduction! Type double! Type float! Changing types! Type promotion & conversion! Casts! Initialization! Assignment operators! Summary 1 Introduction

### Computers Programming Course 6. Iulian Năstac

Computers Programming Course 6 Iulian Năstac Recap from previous course Data types four basic arithmetic type specifiers: char int float double void optional specifiers: signed, unsigned short long 2 Recap

### Values and Variables 1 / 30

Values and Variables 1 / 30 Values 2 / 30 Computing Computing is any purposeful activity that marries the representation of some dynamic domain with the representation of some dynamic machine that provides

### Binding and Variables

Binding and Variables 1. DEFINITIONS... 2 2. VARIABLES... 3 3. TYPE... 4 4. SCOPE... 4 5. REFERENCES... 7 6. ROUTINES... 9 7. ALIASING AND OVERLOADING... 10 8. GENERICS AND TEMPLATES... 12 A. Bellaachia

### Chapter 2: Using Data

Chapter 2: Using Data Declaring Variables Constant Cannot be changed after a program is compiled Variable A named location in computer memory that can hold different values at different points in time

### Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types. Record Types. Pointer and Reference Types

Chapter 6 Topics WEEK E FOUR Data Types Introduction Primitive Data Types Character String Types User-Defined Ordinal Types Array Types Associative Arrays Record Types Union Types Pointer and Reference

Subprograms Introduction Fundamentals of Subprograms Design Issues for Subprograms Local Referencing Environments Parameter-Passing Methods Parameters That Are Subprograms Calling Subprograms Indirectly

### Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur

Operators and Expressions in C & C++ Mahesh Jangid Assistant Professor Manipal University, Jaipur Operators and Expressions 8/24/2012 Dept of CS&E 2 Arithmetic operators Relational operators Logical operators

### Principles of Programming Languages. Lecture Outline

Principles of Programming Languages CS 492 Lecture 1 Based on Notes by William Albritton 1 Lecture Outline Reasons for studying concepts of programming languages Programming domains Language evaluation

### The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Op. Use Description + x + y adds x and y x y

### A First Look At Java. Didactic Module 13 Programming Languages - EEL670 1

A First Look At Java Didactic Module 13 Programming Languages - EEL670 1 Outline Thinking about objects Simple expressions and statements Class definitions About references and pointers Getting started

### The Arithmetic Operators

The Arithmetic Operators The arithmetic operators refer to the standard mathematical operators: addition, subtraction, multiplication, division and modulus. Examples: Op. Use Description + x + y adds x

### Java enum, casts, and others (Select portions of Chapters 4 & 5)

Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The

### Chapter 5. Names, Bindings, and Scopes

Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative

### Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

Course Name: Advanced Java Lecture 2 Topics to be covered Variables Operators Variables -Introduction A variables can be considered as a name given to the location in memory where values are stored. One

### Overview (4) CPE 101 mod/reusing slides from a UW course. Assignment Statement: Review. Why Study Expressions? D-1

CPE 101 mod/reusing slides from a UW course Overview (4) Lecture 4: Arithmetic Expressions Arithmetic expressions Integer and floating-point (double) types Unary and binary operators Precedence Associativity

### CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values

### Information Science 1

Information Science 1 Simple Calcula,ons Week 09 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 8 l Simple calculations Documenting

### 3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

3.Constructors and Destructors Develop cpp program to implement constructor and destructor. Constructors A constructor is a special member function whose task is to initialize the objects of its class.

### HANDLING NONLOCAL REFERENCES

SYMBOL TABLE A symbol table is a data structure kept by a translator that allows it to keep track of each declared name and its binding. Assume for now that each name is unique within its local scope.

### The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees

### CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CS 0 Lecture 8 Chapter 5 Louden Outline The symbol table Static scoping vs dynamic scoping Symbol table Dictionary associates names to attributes In general: hash tables, tree and lists (assignment ) can

### CS16 Week 2 Part 2. Kyle Dewey. Thursday, July 5, 12

CS16 Week 2 Part 2 Kyle Dewey Overview Type coercion and casting More on assignment Pre/post increment/decrement scanf Constants Math library Errors Type Coercion / Casting Last time... Data is internally

### Absolute C++ Walter Savitch

Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

### Chapter 8. Fundamental Characteristics of Subprograms. 1. A subprogram has a single entry point

Fundamental Characteristics of Subprograms 1. A subprogram has a single entry point 2. The caller is suspended during execution of the called subprogram 3. Control always returns to the caller when the

### 9. Subprograms. 9.2 Fundamentals of Subprograms

9. Subprograms 9.2 Fundamentals of Subprograms General characteristics of subprograms A subprogram has a single entry point The caller is suspended during execution of the called subprogram Control always

### CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions

### CS 345. Functions. Vitaly Shmatikov. slide 1

CS 345 Functions Vitaly Shmatikov slide 1 Reading Assignment Mitchell, Chapter 7 C Reference Manual, Chapters 4 and 9 slide 2 Procedural Abstraction Can be overloaded (e.g., binary +) Procedure is a named

### Objectives. In this chapter, you will:

Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

### C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 1 (Minor modifications by the instructor) References C for Python Programmers, by Carl Burch, 2011. http://www.toves.org/books/cpy/ The C Programming Language. 2nd ed., Kernighan, Brian,

### Chapter 7. Basic Types

Chapter 7 Basic Types Dr. D. J. Jackson Lecture 7-1 Basic Types C s basic (built-in) types: Integer types, including long integers, short integers, and unsigned integers Floating types (float, double,

### Review of the C Programming Language

Review of the C Programming Language Prof. James L. Frankel Harvard University Version of 11:55 AM 22-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Reference Manual for the

### CSCI 171 Chapter Outlines

Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures