1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.

Slides:



Advertisements
Similar presentations
Compiler Construction by Muhammad Bilal Zafar (AP)
Advertisements

CPSC Compiler Tutorial 9 Review of Compiler.
Chapter 1: Preliminaries
Yu-Chen Kuo1 Chapter 1 Introduction to Compiling.
PLLab, NTHU Cs2403 Programming Languages Implementation Issues Cs2403 Programming Language Spring 2005 Kun-Yuan Hsieh.
ISBN Chapter 1 Preliminaries. Copyright © 2006 Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Reasons for Studying Concepts of.
Programming Languages Structure
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
CS 355 – Programming Languages
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
COP4020 Programming Languages
Chapter 1. Introduction.
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.
CSC 338: Compiler design and implementation
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
ISBN Chapter 1 Preliminaries. Copyright © 2009 Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Reasons for Studying Concepts of.
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.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
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.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
What is a compiler? –A program that reads a program written in one language (source language) and translates it into an equivalent program in another language.
Dr. Mohamed Ramadan Saady 314ALL CH1.1 Chapter 1: Introduction to Compiling.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
CSC 4181 Compiler Construction
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
Concepts of Programming Languages Lecturer: Dr. Emad Nabil Lecture # 2.
Chapter 1. Introduction.
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
Concepts of Programming Languages
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
Introduction to Compiler Construction
PROGRAMMING LANGUAGES
Compiler Construction (CS-636)
Chapter 1 Introduction.
-by Nisarg Vasavada (Compiled*)
课程名 编译原理 Compiling Techniques
Chapter 1 Preliminaries.
Chapter 1: Introduction to Compiling (Cont.)
Compiler Construction
Compilers B V Sai Aravind (11CS10008).
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Chapter 1 Preliminaries.
Chapter 1 Preliminaries.
Presentation transcript:

1.3 Executing Programs

How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems

Language Implementation Methods Compilation – Programs translated into machine language code that is directly executable Pure Interpretation – Programs are interpreted by an "interpreter" – Intermediate machine code is not produced. Hybrid Implementation Systems – A compromise between compilers and pure interpreters

Layered View of a Computer System (hardware and software) The operating system and language implementation are layered over the Machine interface of a computer © Addison-Wesley

Compiler Implementation Compiler - program that – Reads a program written in one language (the source language) – Translates it into an equivalent program in another language (the target language) Checks for the presence of errors in the source program source program compiler target program error messages

8 Phases of a Compiler 6 main phases 1.Lexical analyzer 2.Syntax analyzer 3.Semantic analyzer 4.Intermediate code generator 5.Code optimizer 6.Code generator Two more activities (in parallel with 6 phases above) A.Symbol table manager B.Error handler Source program Lexical analyzer Lexical units Syntax analyzer Parse trees Intermediat Code generator (and semantic analyzer) Optimization Symbol table Intermediate code Code generator Machine language Computer Results (optional) Input data

A. Symbol Table Manager Keeps track of the source program's identifiers and their attributes – Attributes: storage allocated, type, scope, arguments, return type, etc. – Uses a symbol table Data structure (array, linked list, hash table, etc.) with a record for each identifier where fields are the identifier's attributes

B. Error Detection and Reporting When an error is detected, the compiler must somehow deal with that error, then proceed to find more possible errors – Lexical analysis phase detects errors where the characters in the source file do not form any token of the language Example: s p a c es in var – Syntax analysis phase detects violations to the rules of the language Example: var1 = var2 + – Semantic analysis phase detects constructs that have no meaning Example: var1 = array1 + procedure1

1. Lexical (Linear) Analysis Lexical = of or relating to words or vocabulary of a language as distinguished from its grammar and construction Identifies tokens (keywords, identifier names, integers, etc.) of the programming language Token – sequences of characters that have a collective meaning

2. Syntax (Hierarchical) Analysis Syntax - the way linguistic elements (e.g. words) are put together to form constituents (e.g. sentence, phrase, clause) Also called "parsing" Groups tokens into grammatical phrases Usually the grammatical phrases are represented by a "parse tree"

3. Semantic Analysis Semantic - of or relating to meaning in language Checks for semantic errors – gathers type information for the subsequent code generation phase Uses hierarchical structure (determined by the parser) to identify the operators and operands of expressions and statements

4. Intermediate Code Generator Generates an intermediate representation of the source program Not all compilers perform this An intermediate representation can be thought of as a program for an abstract machine Should be – easy to produce – easy to translate into the target program

5. Code Optimization Improve the intermediate code to produce a faster running machine code in the final translation Optional - not all compilers include the code optimization step, which can be time (and space) intensive

6. Code Generation Generate the target code, usually relocatable machine code –Relocatable code can be loaded at any location R in memory –In other words, if the number R is added to all the addresses in the code, then all references will be the actual memory address The relocatable code is contained in the object file –.obj It contains machine language instructions – only bits – 1's and 0’s

Post-Compilation - Linking Linker (link-editor) connects: – Object files (.obj) from the program modules – Additional library files – Creates the executable (.exe file) program Usually uses relocatable addresses within the program – Allows the program to run in different memory locations – Allows time-sharing and virtual memory

Post-Compilation - Loading Loading the executable (.exe file) program Also called load module or executable image The loader – Identifies a memory location to load the program – Alters the relocatable machine code addresses to run in the designated memory location A program must be in (loaded) memory each time it executes

Implementation Methods - Interpretation Pure interpretation - high-level language statements are immediately decoded into machine code & executed – Fast to write, modify, experiment and try different solutions – Easy to debug – Decoding is slower than execution of compiled code, however the need to compile is eliminated – May require more space for symbol table & source program

Implementation Methods - Hybrid Hybrid – combination of compilers and interpreters – High-level language programs are translated to an intermediate language, which is easily interpreted E.g. Java – compiled and interpreted – Intermediate “byte code” is created by the compiler, – Then the byte code is interpreted Lisp – interpreted, or compiled, or both – Compilation not required - increases speed 10 X or more – Interpreted and compiled code can run together! – Saves compiling an entire project when only one or two files have been changed! – Can be compiled after debugging - make it work, then make it fast! Perl – seems interpreted – Partially compiled to detect errors, then interpreted

Hybrid Implementation System

Summary Programming language study is valuable – Adds problem-solving methods and paradigms – Increases capacity to use different features/tools in all languages – Ability to choose implementation languages intelligently to increase productivity – Makes learning new languages (thus new tools) easier Most important criteria for evaluating programming languages include: – Readability, writability, reliability, cost Major influences on language design have been machine architecture and software development methodologies The major methods of implementing programming languages are: compilation, pure interpretation, and hybrid implementation