Expressions ธนวัฒน์ แซ่เอียบ. Historical remark FORTRAN was one of the first high-level programming languages Developed at the end of the 50´s Evolved.

Slides:



Advertisements
Similar presentations
Operators and Arithmetic Operations. Operators An operator is a symbol that instructs the code to perform some operations or actions on one or more operands.
Advertisements

Intermediate Code Generation
Stacks - 3 Nour El-Kadri CSI Evaluating arithmetic expressions Stack-based algorithms are used for syntactical analysis (parsing). For example.
COP4020 Programming Languages Expression and assignment Prof. Xin Yuan.
Arithmetic Expressions
CSE 425: Semantic Analysis Semantic Analysis Allows rigorous specification of a program’s meaning –Lets (parts of) programming languages be proven correct.
Compiler Construction
Intermediate Representation I High-Level to Low-Level IR Translation EECS 483 – Lecture 17 University of Michigan Monday, November 6, 2006.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3: Numeric Data *Variables *Numeric data.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.2 Expressions and Assignment Statement.
Chapter 3 Numerical Data. Topics Variables Numeric data types Assignment Expressions.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
JavaScript, Fourth Edition
Chapter 2 Data Types, Declarations, and Displays
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
CCSA 221 Programming in C CHAPTER 2 SOME FUNDAMENTALS 1 ALHANOUF ALAMR.
CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.
Objectives You should be able to describe: Data Types
Imperative Programming
Chapter 2 part #4 Operator
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
CHAPTER 2 PART #4 OPERATOR 2 nd semester King Saud University College of Applied studies and Community Service Csc 1101 By: Asma Alosaimi Edited.
Input, Output, and Processing
1 CS1110 Fall 2011 David Gries, Steve Marschner Reading for this lecture and previous lecture: Sections 1.1, 1.2, 1.3. Lab 1 will give you practice with.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 1 (Monday)
FORTRAN History. FORTRAN - Interesting Facts n FORTRAN is the oldest Language actively in use today. n FORTRAN is still used for new software development.
 Computer Languages Computer Languages  Machine Language Machine Language  Assembly Language Assembly Language  High Level Language High Level Language.
Sahar Mosleh California State University San MarcosPage 1 Assembly language and Digital Circuit By Sahar Mosleh California State University San Marcos.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages Chapter 3 : Describing Syntax and Semantics Denotational Semantics.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
 Most C programs perform calculations using the C arithmetic operators (Fig. 2.9).  Note the use of various special symbols not used in algebra.  The.
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
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.
Overloading C++ supports the concept of overloading Two main types
Topics Designing a Program Input, Processing, and Output
CSCI-235 Micro-Computer Applications
Expressions and Assignment
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
ITEC113 Algorithms and Programming Techniques
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Assignment and Arithmetic expressions
Dept of Computer Science
Arithmetic Operator Operation Example + addition x + y
Important Concepts from Clojure
Important Concepts from Clojure
Lecture 3 Expressions Richard Gesick.
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Expressions.
Chapter 3 Operators and Expressions
Topics Designing a Program Input, Processing, and Output
Important Concepts from Clojure
Compiler Construction
Topics Designing a Program Input, Processing, and Output
Chapter 4: Expression and Operator
Operator King Saud University
Compiler Construction
Data Types and Expressions
Algoritmos y Programacion
Data Types and Expressions
Presentation transcript:

Expressions ธนวัฒน์ แซ่เอียบ

Historical remark FORTRAN was one of the first high-level programming languages Developed at the end of the 50´s Evolved through multiple versions Still in wide-spread use today (in scientific applications) FORTRAN stands for FORmula TRANslater One of its most important contributions is that the programmer may write formulas (expressions) close to the way it is done in mathematics The programmer need not program formulas in terms of instructions written in an assembly language (LOAD, STORE, ADD, etc.) The compiler performs this translation

Levels of abstraction

Hardware architecture

Assembly program for an arithmetic expression

What is an expression? Expression A formula which is composed of operators and operands (and other parts, e.g., parentheses) and whose evaluation yields a value from a certain domain (e.g., an integer value, a real value, etc.) Examples a + b*2 14 – (5 – c) a + b = c – d 56 < 11 (a or b) and d

Parts of expressions

Types of expressions

Operations, operators, and functions An operation takes a sequence of arguments and returns a value The arity of an operation is the number of its arguments Unary operations: one argument Examples: fac, sin, cos Binary operations: two arguments Examples: +, *.... An operator is an operation which is denoted by one or more special characters Examples: +, *, <, <= A function is an operation which is denoted by an identifier Examples: fac, max

Application of functions

Application of operators

Composition and evaluation of expressions An expression may be An identifier A literal A function applied to its arguments An operator applied to its arguments An argument is a subexpression which is Smaller than its enclosing expression, but Obeys the same rules as its enclosing expression Expressions are composed recursively

Composition and evaluation of expressions An expression is evaluated as follows: For an identifier denoting a variable: take the value of that variable For a literal: take the value denoted by that literal For a function applied to its arguments: Evaluate the arguments Apply the function to its arguments Likewise for an operator applied to its arguments

Controlling the evaluation of expressions Priorities Operators of higher priority are applied before operators of lower priority Examples: Multiplication has a higher priority than addition Logical and has a higher priority than logical or Left-to-right evaluation Operators of the same priority are evaluated from left to right Example: 18 – 7 – 5 = (18 – 7) – 5 = 11 – 5 = 6 ≠ 18 – (7 – 5) = 18 – 2 = 16

Controlling the evaluation of expressions Parentheses An expression enclosed in parentheses is evaluated before being applied as an argument In combination with priorities and left-to-right- evaluation, parentheses are only needed where the standard evaluation order is not desired Example: 18 – (7 – 5) = 18 – 2 = 16

Adding parentheses to expressions We may add parentheses to expressions to make the evaluation order explicit The meaning (semantics) of expressions is not changed by this transformation if it conforms with priorities and left-to-right-evaluation Example: 17 – 4 – 5 * * 3 =

Priorities of operators * 3 < 18 * 5 and =

Expression trees The structure of an expression may be represented by an expression tree

Expression trees

Recursive algorithm of the factorial

Example

Stacks

Using the evaluation stack

Literature Bernhard Westfechtel : RWTH Aachen University A.V. Aho, R. Sethi, J.D. Ullman: Compilers: Principles, Techniques, and Tools, Chapter 2, Addison-Wesley, 1986