CS 3304 Comparative Languages

Slides:



Advertisements
Similar presentations
Copyright © 2005 Elsevier Imperative languages Group languages as –imperative von Neumann(Fortran, Pascal, Basic, C) object-oriented(Smalltalk, Eiffel,
Advertisements

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.
CPSC Compiler Tutorial 9 Review of Compiler.
Reference Book: Modern Compiler Design by Grune, Bal, Jacobs and Langendoen Wiley 2000.
Compiler Construction
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
COP4020 Programming Languages
1 Programming Languages Tevfik Koşar Lecture - II January 19 th, 2006.
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.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
Compiler design Lecture 1: Compiler Overview Sulaimany University 2 Oct
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
Introduction to Compiling
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
1 Compiler Construction Vana Doufexi office CS dept.
Presented by : A best website designer company. Chapter 1 Introduction Prof Chung. 1.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
CS510 Compiler Lecture 1. Sources Lecture Notes Book 1 : “Compiler construction principles and practice”, Kenneth C. Louden. Book 2 : “Compilers Principles,
Chapter 1 :: Introduction Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright © 2016 Elsevier.
Chapter 1. Introduction.
Advanced Computer Systems
Intro to compilers Based on end of Ch. 1 and start of Ch. 2 of textbook, plus a few additional references.
Compiler Design (40-414) Main Text Book:
Introduction Chapter : Introduction.
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
CS510 Compiler Lecture 1.
CS 3304 Comparative Languages
Introduction to Compiler Construction
CS 326 Programming Languages, Concepts and Implementation
A Simple Syntax-Directed Translator
Chapter 2 :: Programming Language Syntax
Compiler Construction (CS-636)
Introduction.
CS 363 – Chapter 1 What is a programming language? Kinds of languages
Chapter 1 Introduction.
PROGRAMMING LANGUAGES
课程名 编译原理 Compiling Techniques
Compiler Lecture 1 CS510.
CS416 Compiler Design lec00-outline September 19, 2018
Course supervisor: Lubna Siddiqui
Introduction CI612 Compiler Design CI612 Compiler Design.
CPSC 388 – Compiler Design and Construction
CSE401 Introduction to Compiler Construction
Compilers B V Sai Aravind (11CS10008).
COP4020 Programming Languages
CS 3304 Comparative Languages
CS 3304 Comparative Languages
Compiler design.
CS416 Compiler Design lec00-outline February 23, 2019
Chapter 2 :: Programming Language Syntax
Chapter 2 :: Programming Language Syntax
Compiler Construction
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Introduction Chapter : Introduction.
Lecture 5 Scanning.
Intro to compilers Based on end of Ch. 1 and start of Ch. 2 of textbook, plus a few additional references.
Presentation transcript:

CS 3304 Comparative Languages Compilation and Interpretation

The von Neumann Architecture Fetch-execute-cycle (on a von Neumann architecture computer) initialize the program counter repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat

Compilation vs. Interpretation Not opposites. Not a clear-cut distinction. Interpretation: Greater flexibility. Better diagnostics (error messages). Compilation: Better performance.

Pure Compilation The compiler translates the high-level source program into an equivalent target program (typically in machine language), and then goes away.

Pure Interpretation Interpreter stays around for the execution of the program. Interpreter is the locus of control during execution.

Hybrid Common case is compilation or simple pre-processing, followed by interpretation. Most language implementations include a mixture of both compilation and interpretation.

Compilation Phases

Scanning Divides the program into "tokens", which are the smallest meaningful units; this saves time, since character-by- character processing is slow. We can tune the scanner better if its job is simple; it also saves complexity (lots of it) for later stages. You can design a parser to take characters instead of tokens as input, but it isn't pretty. Scanning is recognition of a regular language, e.g., via deterministic finite automaton (DFA).

Parsing Parsing is recognition of a context-free language, e.g., via push-down automaton (PDA). Parsing discovers the "context free" structure of the program Informally, it finds the structure you can describe with syntax diagrams (the "circles and arrows" in a Pascal manual).

Semantic Analysis Semantic analysis is the discovery of meaning in the program The compiler actually does what is called STATIC semantic analysis. That's the meaning that can be figured out at compile time. Some things (e.g., array subscript out of bounds) can't be figured out until run time. Things like that are part of the program's DYNAMIC semantics.

Intermediate Form Intermediate form (IF) done after semantic analysis (if the program passes all checks). IFs are often chosen for machine independence, ease of optimization, or compactness (these are somewhat contradictory). They often resemble machine code for some imaginary idealized machine; e.g. a stack machine, or a machine with arbitrarily many registers. Many compilers actually move the code through more than one IF.

Other Phases Optimization takes an intermediate-code program and produces another one that does the same thing faster, or in less space: The term is a misnomer; we just improve code. The optimization phase is optional. Code generation phase produces assembly language or (sometime) relocatable machine language. Certain machine-specific optimizations (use of special instructions or addressing modes, etc.) may be performed during or after target code generation.

Symbol Table All phases rely on a symbol table that keeps track of all the identifiers in the program and what the compiler knows about them. This symbol table may be retained (in some form) for use by a debugger, even after compilation has completed.

Example: GCD Program in C int main() { int i = getint(), j = getint(); while (i != j) { if (i > j) i = i - j; else j = j - i; } putint(i);

GCD Program Tokens Lexical and Syntax Analysis: Scanning (lexical analysis) and parsing recognize the structure of the program, groups characters into tokens, the smallest meaningful units of the program. int main ( ) { int i = getint ( ) , j = getint ( ) ; while ( i != j ) { if ( i > j ) i = i - j ; else j = j - i ; } putint ( i ) ;

Context-Free Grammar and Parsing Parsing organizes tokens into a parse tree that represents higher- level constructs in terms of their constituents. Potentially recursive rules known as context-free grammar define the ways in which these constituents combine. Example: while loop in C iteration-statement → while ( expression ) statement statement, in turn, is often a list enclosed in braces: statement → compound-statement compound-statement → { block-item-list opt } where block-item-list opt → block-item-list or block-item-list opt → ϵ and block-item-list → block-item block-item-list → block-item-list block-item block-item → declaration block-item → statement