Chapter 1 Introduction Major Data Structures in Compiler

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

Symbol Table.
Programming Languages Third Edition Chapter 6 Syntax.
Compilers and Language Translation
Yu-Chen Kuo1 Chapter 1 Introduction to Compiling.
Chapter3: Language Translation issues
Compiler design Computer Science Rensselaer Polytechnic Lecture 1.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Invitation to Computer Science 5th Edition
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.
Parser-Driven Games Tool programming © Allan C. Milne Abertay University v
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
CSC 338: Compiler design and implementation
The TINY sample language and it’s compiler
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
COMPILERS Symbol Tables hussein suleman uct csc3003s 2007.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
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.
Review: Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Intermediate code generator Code optimizer Code generator Symbol.
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.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
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
Introduction CPSC 388 Ellen Walker Hiram College.
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.
Chapter 1 Introduction. Chapter 1 -- Introduction2  Def: Compiler --  a program that translates a program written in a language like Pascal, C, PL/I,
Chapter 1: Introduction 1 Compiler Designs and Constructions Chapter 1: Introduction Objectives: Course Objectives Introduction Dr. Mohsen Chitsaz.
Compilers I CNS History Wires Wires Machine Language Machine Language FFBA FFBA No Translation necessary No Translation necessary Assembly Language.
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
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.
1 Structure of a Compiler Source Language Target Language Semantic Analyzer Syntax Analyzer Lexical Analyzer Front End Code Optimizer Target Code Generator.
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.
©SoftMoore ConsultingSlide 1 Structure of Compilers.
CSC 8505 Compiler Construction
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Sung-Dong Kim Dept. of Computer Engineering, Hansung University
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University.
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
Lecture 9 Symbol Table and Attributed Grammars
System Software Theory (5KS03).
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
Introduction Chapter : Introduction.
PRINCIPLES OF COMPILER DESIGN
Introduction to Compiler Construction
Compiler Construction (CS-636)
Introduction.
-by Nisarg Vasavada (Compiled*)
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
Compilers B V Sai Aravind (11CS10008).
CMPE 152: Compiler Design August 21/23 Lab
Chapter 1 Introduction.
Chapter 10: Compilers and Language Translation
Introduction Chapter : Introduction.
Presentation transcript:

Chapter 1 Introduction Major Data Structures in Compiler Gang S. Liu College of Computer Science & Technology Harbin Engineering University

Major Data Structures in Compiler There is a strong interaction between the algorithms used by the phases of a compiler and the data structures that support these phases. Algorithms need to be implemented in efficient manner. The choice of data structures is important Compiler Samuel2005@126.com

Tokens When a scanner collects characters into a token, it represents the token symbolically as a value of an enumerated data type representing a set of tokens of the source language Sometimes, it is necessary to preserve the character string itself or other information derived from it The name associated with an identifier token The value of a number token In most languages the scanner needs to generate one token at a time (single symbol lookahead) A single global variable can be used to hold the token information. Compiler Samuel2005@126.com

The Syntax Tree The syntax tree is constructed as a standard pointer-based structure that is dynamically allocated as parsing proceeds. The tree can be kept as a single variable pointing to the root node. Each node is a record. Its fields represent the information collected by the parser and the semantic analyzer. Sometimes these fields are dynamically allocated Compiler Samuel2005@126.com

The Symbol Table This data structure keeps information associated with identifiers, functions, variables, constants, and data types. The symbol table interacts with almost every phase of the compiler. The insertion, deletion access operations need to be efficient. A standard data type for this purpose is the hash table. Compiler Samuel2005@126.com

The Literal Table Stores constants and strings used in the program. Quick insertion and lookup are essential. Need not allow deletions. Compiler Samuel2005@126.com

Intermediate Code Depending on the kind of intermediate code, it may be kept as An array of text strings A temporary text file Linked list of structures Compiler Samuel2005@126.com

Temporary Files Computers did not possess enough memory for an entire program to be kept in memory during compilation. This was solved by using temporary files to hold the products of intermediate steps. Memory constrains are now much smaller problem. Occasionally, compilers generate intermediate files during some of the steps. Compiler Samuel2005@126.com

Other Issues in Compiler Structure Passes Language Definition Error Handling Compiler Samuel2005@126.com

Passes A compiler often processed the entire source program several times before generating code. These repetitions are referred as passes. Passes may or may not correspond to phases. Depending on the language, a compiler may be one pass. Efficient compilation, but not efficient target code. Examples: Pascal and C. Most compilers with optimizations use more than one pass: Scanning and parsing Semantic analysis and source-level optimization Code generation and target code optimization Compiler Samuel2005@126.com

Language Definition The description of the lexical, syntactic, and semantics of a programming language is collected in a language reference manual, or language definition. With a new language, a language definition and compiler are often developed together. More common situation is when a compiler is written for well-known language which has an existing language definition. Compiler Samuel2005@126.com

Error Handling One of the most important functions of a compiler. Errors can be detected during almost every phase of compilation. Error reported by a compiler are static (or compile-time) errors. It is important to generate meaningful error messages. Error handler contains different operations for a specific compiler phase and situation Compiler Samuel2005@126.com