Languages and Compilers (SProg og Oversættere)

Slides:



Advertisements
Similar presentations
CS3012: Formal Languages and Compilers Static Analysis the last of the analysis phases of compilation type checking - is an operator applied to an incompatible.
Advertisements

CPSC 388 – Compiler Design and Construction
1 Languages and Compilers (SProg og Oversættere) Code Generation.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch. 3: Compilation Spring 2007 Marco Valtorta.
9/27/2006Prof. Hilfinger, Lecture 141 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik)
1 Languages and Compilers (SProg og Oversættere) Lecture 2 Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 531 Compiler Construction Ch. 3: Compilation Spring 2008 Marco Valtorta.
Chapter 2 A Simple Compiler
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Compilation (Chapter 3) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
Syntax Analysis (Chapter 4) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
COP4020 Programming Languages
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.
CSC 338: Compiler design and implementation
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
5-1 5 Compilation  Overview  Compilation phases –syntactic analysis –contextual analysis –code generation  Abstract syntax trees  Case study: Fun language.
1 Compiler 3.2 A Level computing. 2 So, Sir what is a compiler?
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture.
1 Languages and Compilers (SProg og Oversættere) Lexical analysis.
CPS 506 Comparative Programming Languages Syntax Specification.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Contextual Analysis (Chapter 5) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
Review (Chapter 9) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Wei-Tek Tsai who’s.
 Fall Chart 2  Translators and Compilers  Textbook o Programming Language Processors in Java, Authors: David A. Watts & Deryck F. Brown, 2000,
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.
Language Implementation Overview John Keyser Spring 2016.
1 Languages and Compilers (SProg og Oversættere) Lecture 9 (1) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm.
CS412/413 Introduction to Compilers Radu Rugina Lecture 11: Symbol Tables 13 Feb 02.
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
©SoftMoore ConsultingSlide 1 Context-Free Grammars.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
1 Languages and Compilers (SProg og Oversættere) Semantic Analysis.
Programming Languages Meeting 3 September 9/10, 2014.
MiniJava Compiler A multi-back-end JIT compiler of Java.
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
Lecture 9 Symbol Table and Attributed Grammars
Chapter 3 – Describing Syntax
01 – Overview of Compilers
PRINCIPLES OF COMPILER DESIGN
Constructing Precedence Table
Course Overview PART I: overview material PART II: inside a compiler
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Enumeration Types In Triangle.
Semantic Analysis with Emphasis on Name Analysis
Overview of Compilation The Compiler BACK End
-by Nisarg Vasavada (Compiled*)
Ch. 4 – Semantic Analysis Errors can arise in syntax, static semantics, dynamic semantics Some PL features are impossible or infeasible to specify in grammar.
Compiler Lecture 1 CS510.
CS 536 / Fall 2017 Introduction to programming languages and compilers
Basic Program Analysis: AST
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Review: Compiler Phases:
Overview of Compilation The Compiler BACK End
DotnetConf 12/3/2018 1:48 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE.
Compilers B V Sai Aravind (11CS10008).
Lecture 4: Lexical Analysis & Chomsky Hierarchy
Compiler design.
Languages and Compilers (SProg og Oversættere)
CS 432: Compiler Construction Lecture 11
Course Overview PART I: overview material PART II: inside a compiler
Lesson Objectives Aims Understand Syntax Analysis.
Presentation transcript:

Languages and Compilers (SProg og Oversættere) Structure of the compiler

Structure of the compiler Describe the phases of the compiler and give an overall description of what the purpose of each phase is and how the phases interface

The “Phases” of a Compiler Source Program Syntax Analysis Error Reports Abstract Syntax Tree Contextual Analysis Error Reports Decorated Abstract Syntax Tree Code Generation Object Code

Single Pass Compiler A single pass compiler makes a single pass over the source text, parsing, analyzing and generating code all at once. Dependency diagram of a typical Single Pass Compiler: Compiler Driver calls Syntactic Analyzer calls calls Contextual Analyzer Code Generator

Multi Pass Compiler A multi pass compiler makes several passes over the program. The output of a preceding phase is stored in a data structure and used by subsequent phases. Dependency diagram of a typical Multi Pass Compiler: Compiler Driver calls calls calls Syntactic Analyzer Contextual Analyzer Code Generator input Source Text output AST Decorated AST Object Code

1) Syntax Analysis -> AST Program LetCommand SequentialCommand SequentialDeclaration AssignCommand AssignCommand BinaryExpr SimpleT VarDecl VarDecl Char.Expr VNameExp Int.Expr SimpleT SimpleV SimpleV Ident Ident Ident Ident Ident Char.Lit Ident Ident Op Int.Lit n Integer c Char c ‘&’ n n + 1

2) Contextual Analysis -> Decorated AST Abstract Syntax Tree Contextual Analysis Error Reports Decorated Abstract Syntax Tree Contextual analysis: Scope checking: verify that all applied occurrences of identifiers are declared Type checking: verify that all operations in the program are used according to their type rules. Annotate AST: Applied identifier occurrences => declaration Expressions => Type

2) Contextual Analysis -> Decorated AST Program LetCommand SequentialCommand SequentialDeclaration AssignCommand AssignCommand BinaryExpr :int SimpleT VarDecl VarDecl Char.Expr VNameExp Int.Expr :char :int :int SimpleT SimpleV SimpleV :char :int Ident Ident Ident Ident Ident Char.Lit Ident Ident Op Int.Lit n Integer c Char c ‘&’ n n + 1

Contextual Analysis Finds scope and type errors. Example 1: AssignCommand ***TYPE ERROR (incompatible types in assigncommand) :int :char Example 2: foo not found SimpleV ***SCOPE ERROR: undeclared variable foo Ident foo

Transforms source program into target code. 3) Code Generation Decorated Abstract Syntax Tree Code Generation Object Code Assumes that program has been thoroughly checked and is well formed (scope & type rules) Takes into account semantics of the source language as well as the target language. Transforms source program into target code.

3) Code Generation let var n: integer; var c: char in begin c := ‘&’; n := n+1 end PUSH 2 LOADL 38 STORE 1[SB] LOAD 0 LOADL 1 CALL add STORE 0[SB] POP 2 HALT SimpleT VarDecl address = 0[SB] Ident Ident n Integer

A somewhat more complex compiler