Tag at C++ Compiler 2019.05.09 Kei Hasegawa.

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

Constructors and Destructors. Constructor Constructor—what’s this? Constructor—what’s this? method used for initializing objects (of certain class) method.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Slide: 1 Copyright © AdaCore Packages Presented by Quentin Ochem university.adacore.com.
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
Rossella Lau Lecture 8, DCO10105, Semester B, DCO10105 Object-Oriented Programming and Design  Lecture 8: Polymorphism & C++ pointer  Inheritance.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
Storage Classes.
The switch StatementtMyn1 The switch Statement Sometimes there can be a multiple-choice situation, in which you need to execute a particular set of statements.
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
Beginning C++ Through Game Programming, Second Edition by Michael Dawson.
CSCI 130 Scope of Variables Chapter 6. What is scope Parts of program which can access a variable –accessibility –visibility How long variable takes up.
C Functions Programmer-defined functions – Functions written by the programmer to define specific tasks. Functions are invoked by a function call. The.
Attribute Grammar Examples and Symbol Tables Compiler Design Lecture (02/23/98) Computer Science Rensselaer Polytechnic.
Names and Scope. Scope Suppose that a name is used many times for different entities in text of the program, or in the course of execution. When the name.
Chapter 14 Functions.
C# Classes and Inheritance CNS 3260 C#.NET Software Development.
Week 6: Functions - Part 2 BJ Furman 01OCT2012. The Plan for Today Comments on midterm exam (next week in lab!) Review of functions Scope of identifiers.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
Programming Perl in UNIX Course Number : CIT 370 Week 6 Prof. Daniel Chen.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 16: Introduction to C++
نظام المحاضرات الالكترونينظام المحاضرات الالكتروني Overloading operators C++ incorporates the option to use standard operators to perform operations with.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 5-1 Why Write Methods? Methods are commonly used to break a problem down.
 Static  Example for Static Field  Example for Static Method  Math class methods  Casting  Scope of Declaration  Method Overloading  Constructor.
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
4 Starting Tips to Keep Your Car in Top Condition
Lecture 9 Symbol Table and Attributed Grammars
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
Names and Attributes Names are a key programming language feature
Data types Data types Basic types
C Functions -Continue…-.
ㅎㅎ Fourth step for Learning C++ Programming Namespace Function
Default Constructors A default constructor is a constructor that takes no arguments. If you write a class with no constructor at all, C++ will write a.
CONSTRUCTORS & DESTRUCTORS
University of Central Florida COP 3330 Object Oriented Programming
Structs versus Classes
Prepared By: G.UshaRani B.Pranalini A.S.Lalitha
Introduction to C Programming Language
CSCE 210 Data Structures and Algorithms
11/10/2018.
Conditional Statements
Functions A function is a “pre-packaged” block of code written to perform a well-defined task Why? Code sharing and reusability Reduces errors Write and.
Local Variables, Global Variables and Variable Scope
PZ09A - Activation records
Storage class.
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Chapter 6 – Methods Topics are:
Not referenced literal
Symbol table lookup & install
Can you put the symbols in?
inline substitution algorithm
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
nested-name-specifier
C++ parse analysis Save and restore parser state
Storage classes in C In C language, each variable has a storage class which decides the following things: scope i.e where the value of the variable would.
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Activation records Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Programming in C# CHAPTER - 9
C++ Parse Analysis Introduction
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
Base lookup for member Kei Hasegawa.
Temporary type Kei Hasegawa
Default argument Kei Hasegawa.
Virtual base, constructor & destructor
Presentation transcript:

Tag at C++ Compiler 2019.05.09 Kei Hasegawa

scope : Symbol Table struct scope { }; scope* m_parent; vector<scope*> m_children; map<string, vector<usr*> > m_usrs; // Variable etc map<string, tag*> m_tags; // Structure etc ... virtual ~scope(); };

tag : expressing structure etc // C Compiler struct tag { // Scope where the structure is declared scope* m_scope; ... }; // C++ Compiler struct tag : scope { // scope::m_parent is correspond to m_scope of C Compiler ... };

Destroy symbol tables when finishing to compile a function definition // C Compiler void destroy_temporary() { ... // Simple! vector<scope*>& children = scope::root.m_children; for (auto p : children) delete p; children.clear(); }

Destroy symbol tables when finishing to compile a function definition(2) // C++ Compiler void destroy_temporary() { ... vector<scope*>& children = scope::root.m_children; for (IT p = begin(children) ; p != end(children) ; ) { switch ( (*p)->m_id) { case PARAM: case BLOCK: delete *p; p = children.erase(p); break; default: ++p; // Not delete structure or namespace }

scope::~scope() // C Compiler scope::~scope() { } for (auto p : m_children) delete p; ... for (auto& p : m_tags) p.second->m_scope = 0; // Not understandable. See C Compiler Temporary Type Document. }

scope::~scope() (2) // C++ Compiler scope::~scope() { for (auto p : m_children) { switch (p->m_id) { case PARAM: case BLOCK: delete p; break; default: p->m_parent = 0; // Break parent-child relation } // Nothing to be done for `m_tags’