Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.

Slides:



Advertisements
Similar presentations
CS 31003: Compilers Introduction to Phases of Compiler.
Advertisements

報告者:會計四 簡思佳 The process of converting a program written in a high-level language into a machine-executable form. language implementation Ex.C++
Compilers and Language Translation
 Lex helps to specify lexical analyzers by specifying regular expression  i/p notation for lex tool is lex language and the tool itself is refered to.
1 Pass Compiler 1. 1.Introduction 1.1 Types of compilers 2.Stages of 1 Pass Compiler 2.1 Lexical analysis 2.2. syntactical analyzer 2.3. Code generation.
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
CPSC Compiler Tutorial 9 Review of Compiler.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Yu-Chen Kuo1 Chapter 1 Introduction to Compiling.
Chapter 9 Compilers and Language Translation. The Compilation Process Phase I: Lexical analysis Phase I: Lexical analysis Phase II: Parsing Phase II:
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Invitation to Computer Science 5th Edition
Compiler1 Chapter V: Compiler Overview: r To study the design and operation of compiler for high-level programming languages. r Contents m Basic compiler.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
Chapter 6 Programming Languages. © 2005 Pearson Addison-Wesley. All rights reserved 6-2 Chapter 6: Programming Languages 6.1 Historical Perspective 6.2.
Lesson 3 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
Chapter 6 Programming Languages © 2007 Pearson Addison-Wesley. All rights reserved.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Lexical and Syntax Analysis
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Towards the better software metrics tool motivation and the first experiences Gordana Rakić Zoran Budimac.
CPS 506 Comparative Programming Languages Syntax Specification.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
IN LINE FUNCTION AND MACRO Macro is processed at precompilation time. An Inline function is processed at compilation time. Example : let us consider this.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Chapter 1 Introduction Major Data Structures in Compiler
Programming Languages
Winter Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
 Fall Chart 2  Translators and Compilers  Textbook o Programming Language Processors in Java, Authors: David A. Watts & Deryck F. Brown, 2000,
PZ03BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03BX –Recursive descent parsing Programming Language.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
1 February 23, February 23, 2016February 23, 2016February 23, 2016 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Comp 311 Principles of Programming Languages Lecture 2 Syntax Corky Cartwright August 26, 2009.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Programming Languages Salihu Ibrahim Dasuki (PhD) CSC102 INTRODUCTION TO COMPUTER SCIENCE.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Introduction Chapter : Introduction.
Introduction to Compiler Construction
Lexical and Syntax Analysis
Ch. 7 Programming Languages
-by Nisarg Vasavada (Compiled*)
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
CPSC 388 – Compiler Design and Construction
Compilers B V Sai Aravind (11CS10008).
R.Rajkumar Asst.Professor CSE
C H A P T E R T W O Syntax.
Chapter 6: Programming Languages
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Chapter 10: Compilers and Language Translation
Introduction Chapter : Introduction.
Lecture 18 Compilers and Language Translation (S&G, ch. 9)
Presentation transcript:

Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Outline  Historical Perspective(covered)  Traditional Programming Concepts(covered)  Procedural Units  Language Implementation  Object-Oriented Programming(skip)  Programming Concurrent Activities(skip)  Declarative Programming(skip)

Procedures  A ________ is a set of instructions for performing a task that can be used as an abstract tool by other program units  ________ is transferred to the procedure at the time its services are required  Control is returned to the original program unit after the procedure ________  A procedure can be regarded as a _________ program

Flow of Control

Variables and Parameters  Local variables  Variables declared ______ a procedure  ______ to that procedure only  Global variables  Variables not ________ to a particular part of a program  Accessible __________ the program  Parameters  Variables that are passed to ____________  Formal parameters and ______ parameters

Procedures: Example

Parameter Passing  Pass by ________  There are pros and cons with each

Pass By Value  A ____ of the data represented by the actual parameters is produced and given to the procedure  Any alterations to the data made by the procedure are reflected only in the _____ --- the data in the calling program unit are ______ changed  Therefore, this model is ____  If the parameters represent large blocks of data, this can be ___________

Pass By Value: Example

Pass By Reference  The ________ of the actual parameters is given to the procedure  The procedure has ____ access of the data represented by the actual parameters  This is more ________  This is however more _________

Pass By Reference: Example

Functions  There are two types of procedures  Those that DO NOT return a value (sometimes called __________)  Those that DO return a value (usually called __________)

Language Implementation  The process of converting a program from one language to another is called _________  The program in its original form is the _______ program; the translated version is the ________ program  Translation process

Lexical Analyzer  Reads the source program symbol by symbol, ________ which groups of symbols represent single units, and _________ those units (numeric values, words, …)  As each unit is classified, the lexical analyzer generates a bit pattern known as a ______  Therefore, the lexical analyzer converts the program (a stream of _______) into a stream of _______

Parser  Identifies the ___________ structure of the program and recognizes the ____ of each component  Based on a set of syntax rules (= __________) that define the syntax of the programming language  A ______ tree is used to show that a stream of tokens conforms to the grammar

Syntax Diagram: Example 1

Syntax Diagram: Example 2

Parse Tree for x + y x z

Ambiguity  A parse tree represents the parser’s _____________ of the program’s grammatical composition  The grammar is __________ if it is possible to have more than one parse tree for one string  Note that the following statement leads to ambiguity: if B1 then if B2 then S1 else S2 (________ Else)

Parse Tree 1 for Dangling Else

Parse Tree 2 for Dangling Else

Dangling Else Resolution  _________ close every if statement, or  Match every else with the ________ if

Code Generation  Constructs the ________-language instructions to implement the statements recognized by the parser  This process involves numerous issue, one being that of producing efficient code (code __________)  Some optimizations include  Reduce number of _____instructions_____  Remove _________ and/or useless instructions  Reduce number of __jumps______

Linking and Loading  When all steps of translation have been finished, we have a piece of ______ code  Object code may contain _________ to other object code  Thus, generally several pieces of object code need to be ______ together to form an executable program  In order for an executable program to be run, it needs to be loaded into memory by a program called a ______