School of Computing and Engineering, University of Huddersfield LANGUAGE TRANSLATORS: WEEK 10 LECTURE: symbol tables TUTORIAL: Pen and paper exercises.

Slides:



Advertisements
Similar presentations
Symbol Table.
Advertisements

Introduction To Compilers And Phase 1 Inside a compiler. Inside a C-- compiler. The compilation process. Example C-- code. Extended Backus-Naur.
School of Computing and Mathematics, University of Huddersfield CAS810: WEEK 5 LECTURE: DENOTIONAL SEMANTICS OF A SIMPLE LANGUAGE : INTERPRETATION IN HASKELL.
Compilers and Language Translation
By Neng-Fa Zhou Compiler Construction CIS 707 Prof. Neng-Fa Zhou
School of Computing and Engineering, University of Huddersfield CHA2545: WEEK 14 - SYNTAX LECTURE: ABSTRACT SYNTAX SIMPLE EXAMPLE OF SEMANTICS DEFINITION.
Yu-Chen Kuo1 Chapter 1 Introduction to Compiling.
Environments and Evaluation
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
Compiler design Computer Science Rensselaer Polytechnic Lecture 1.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
ITEC 352 Lecture 11 ISA - CPU. ISA (2) Review Questions? HW 2 due on Friday ISA –Machine language –Buses –Memory.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
1 Week 4 Questions / Concerns Comments about Lab1 What’s due: Lab1 check off this week (see schedule) Homework #3 due Wednesday (Define grammar for your.
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.
LANGUAGE TRANSLATORS: WEEK 24 TRANSLATION TO ‘INTERMEDIATE’ CODE (overview) Labs this week: Tutorial Exercises on Code Generation.
CSC 338: Compiler design and implementation
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.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Basic Semantics Associating meaning with language entities.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
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.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
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.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Introduction to Code Generation and Intermediate Representations
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
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.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
Chapter 1 Introduction Major Data Structures in Compiler
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.
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.
 Fall Chart 2  Translators and Compilers  Textbook o Programming Language Processors in Java, Authors: David A. Watts & Deryck F. Brown, 2000,
1 Structure of Compilers Lexical Analyzer (scanner) Modified Source Program Parser Tokens Semantic Analysis Syntactic Structure Optimizer Code Generator.
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.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
CSC 4181 Compiler Construction
Language Implementation Overview John Keyser Spring 2016.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Programming Languages Meeting 3 September 9/10, 2014.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Lecture 9 Symbol Table and Attributed Grammars
Advanced Computer Systems
Names and Attributes Names are a key programming language feature
System Software Unit-1 (Language Processors) A TOY Compiler
Constructing Precedence Table
Introduction to Parsing
Compiler Construction (CS-636)
Review: Chapter 5: Syntax directed translation
-by Nisarg Vasavada (Compiled*)
Compiler Lecture 1 CS510.
Basic Program Analysis: AST
Mini Language Interpreter Programming Languages (CS 550)
Syntax-Directed Translation
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Presentation transcript:

School of Computing and Engineering, University of Huddersfield LANGUAGE TRANSLATORS: WEEK 10 LECTURE: symbol tables TUTORIAL: Pen and paper exercises with algebraic symbol tables

School of Computing and Engineering, University of Huddersfield Interpreters Input program -> create token sequence ** check syntax of names ** create Parse Tree ** check syntax structure ** then interpret/execute program on input data

School of Computing and Engineering, University of Huddersfield Compilers - in brief Input program -> create token sequence ** check syntax of names ** create Parse Tree ** check syntax structure ** create SYMBOL TABLE ** type checking **.. then onto code generation and optimisation

School of Computing and Engineering, University of Huddersfield Scope of a User - defined Name The Scope of a name is the textual area of the program in which a name is meaningful. Program Languages may have different scope rules.. EXAMPLE PIECE OF ‘C/Java’ - like CODE: int fred{ int x = 3; /* name y is NOT in scope */ bool z(int y){ bool x = true; /* name y is in scope */ if (y > 0)... } int y = 0; /* name y is in scope */ …}/* but its NOT the same y..*/

School of Computing and Engineering, University of Huddersfield Symbol tables.. THEIR PURPOSE IN A COMPILER IS TO RECORD: - WHAT IDENTIFIERS ARE IN SCOPE - INFO ABOUT THE IDENTIFIERS IN SCOPE IN EACH PART OF THE INPUT PROGRAM THEIR USE IN A COMPILER IS TO HELP IN: - TYPE CHECKING - GENERATING (ABSTRACT) MACHINE CODE

School of Computing and Engineering, University of Huddersfield The symbol table is dynamic.. n The parse tree of an input program records its syntactic structure. It is an important STATIC data structure in compilation. n The symbol table records the meaning of each of the names that appears in the input program. It is a DYNAMIC data structure because what names are in SCOPE varies, and the symbol table changes through the textual extent of a program.

School of Computing and Engineering, University of Huddersfield Info in a symbol table Generally, but not always, we want to store the ‘class’ of a name (whether it is a variable, a constant, a function..) its type, and its virtual address in some abstract machine. Example symbol table: NAME CLASSTYPE MACHINE-ADDRESS x variablebool z functionbool y formal param.integer Q. which point in our example program does this refer to???? NB: This does not record that x is declared in an outer block

School of Computing and Engineering, University of Huddersfield Our Angle: Instance of a Symbol Table = Value of an Abstract Data Type Rather than look at implementations of the symbol table, we’ll look at a Table as an Abstract Data Type. An ADT is a data type defined via its operations (suppressing the details of implementation)

School of Computing and Engineering, University of Huddersfield Symbol table operations Init : -> Symbol-table Enter-block : Symbol-table -> Symbol-table Leave-block : Symbol-table -> Symbol-table Add : Symbol-table Identifier Attributes -> Symbol-table Retrieve : Symbol-table Identifier -> Attributes Is-in-block? : Symbol-table Identifier -> Bool use first letter shorthand, the Symbol Table at point 1 (see handout) is: A( E(I),x,[int,var]) use first letter shorthand, the Symbol Table at point 2 (see handout) is: A( A( E( A( A( E(I),x,[int,var]),z,[bool,func])),y,[int,var]), x,[bool,var]) Is-in-block?, Leaveblock and Retrieve can be used to destruct/select things from the data structure

School of Computing and Engineering, University of Huddersfield Summary n Symbols tables are built up in the analysis phase of compilation n They record information about user-defined names. n They are used in type checking and memory allocation n Studying a Symbol Table as an ADT is a very abstract/efficient way to understand them Read through the handout in the TUTORIAL and do the exercises