Type Checking. Roadmap (Where are we?) Last lecture Context-sensitive analysis. This lecture Type checking. Symbol tables

Similar documents
Compilers. Topic 4. The Symbol Table and Block Structure PART II. Mick O Donnell: Alfonso Ortega:

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

CS553 Lecture Introduction to Data-flow Analysis 1

CS453 INTRODUCTION TO DATAFLOW ANALYSIS

CMPUT101 Introduction to Computing - Summer 2002

CS 241 Week 4 Tutorial Solutions

Paradigm 5. Data Structure. Suffix trees. What is a suffix tree? Suffix tree. Simple applications. Simple applications. Algorithms

Distributed Systems Principles and Paradigms. Chapter 11: Distributed File Systems

Class Overview. Database Design. Database Design Process. Database Design. Introduction to Data Management CSE 414

Pattern Matching. Pattern Matching. Pattern Matching. Review of Regular Expressions

Parallelization Optimization of System-Level Specification

Midterm Exam CSC October 2001

Distributed Systems Principles and Paradigms

Advanced Programming Handout 5. Enter Okasaki. Persistent vs. Ephemeral. Functional Queues. Simple Example. Persistent vs.

COMP108 Algorithmic Foundations

Problem Final Exam Set 2 Solutions

Fig.25: the Role of LEX

this grammar generates the following language: Because this symbol will also be used in a later step, it receives the

From Dependencies to Evaluation Strategies

V = set of vertices (vertex / node) E = set of edges (v, w) (v, w in V)

Error Numbers of the Standard Function Block

Symbol Table management

CS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

Lecture 13: Graphs I: Breadth First Search

Lesson 4.4. Euler Circuits and Paths. Explore This

CSE 401 Compilers. Agenda. Lecture 4: Implemen:ng Scanners Michael Ringenburg Winter 2013

CSc 453 Compilers and Systems Software. 6 : Top-Down Parsing I

Java CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications

INTEGRATED WORKFLOW ART DIRECTOR

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

Stack Manipulation. Other Issues. How about larger constants? Frame Pointer. PowerPC. Alternative Architectures

Operator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or

Review from Thursday. Computer Animation II. Grid acceleration. Debugging. Computer-Assisted Animation. Final project

Containers: Queue and List

Course Administration

c s ha2 c s Half Adder Figure 2: Full Adder Block Diagram

Minimal Memory Abstractions

Lexical Analysis. Amitabha Sanyal. ( as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

McAfee Web Gateway

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

CS201 Discussion 10 DRAWTREE + TRIES

Troubleshooting. Verify the Cisco Prime Collaboration Provisioning Installation (for Advanced or Standard Mode), page

Lecture 8: Graph-theoretic problems (again)

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009

What are suffix trees?

CMPSC 470: Compiler Construction

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011

Doubts about how to use azimuth values from a Coordinate Object. Juan Antonio Breña Moral

Lexical Analysis: Constructing a Scanner from Regular Expressions

CS 551 Computer Graphics. Hidden Surface Elimination. Z-Buffering. Basic idea: Hidden Surface Removal

COMPUTER EDUCATION TECHNIQUES, INC. (WEBLOGIC_SVR_ADM ) SA:

Lexical analysis, scanners. Construction of a scanner

Computational geometry

Distributed Systems Principles and Paradigms

10/9/2012. Operator is an operation performed over data at runtime. Arithmetic, Logical, Comparison, Assignment, Etc. Operators have precedence

Some Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing

Introduction to Algebra

MITSUBISHI ELECTRIC RESEARCH LABORATORIES Cambridge, Massachusetts. Introduction to Matroids and Applications. Srikumar Ramalingam

1 Which of the following keyword can not be appeared inside the class? a)virtual b)static c)template d)friend c

Computer Arithmetic Logical, Integer Addition & Subtraction Chapter

Pointers and Arrays. More Pointer Examples. Pointers CS 217

Reducing a DFA to a Minimal DFA

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

1. Be able to do System Level Designs by: 2. Become proficient in a hardware-description language (HDL)

Functor (1A) Young Won Lim 8/2/17

CS 430 Spring Mike Lam, Professor. Parsing

PARALLEL AND DISTRIBUTED COMPUTING

Final Exam Review F 06 M 236 Be sure to look over all of your tests, as well as over the activities you did in the activity book

XML and Databases. Outline. XPath. Outline - Lectures. XPath Data Model. Outline - Assignments. XPath. Sebastian Maneth NICTA and UNSW

Functor (1A) Young Won Lim 10/5/17

Enterprise Digital Signage Create a New Sign

Internet Routing. IP Packet Format. IP Fragmentation & Reassembly. Principles of Internet Routing. Computer Networks 9/29/2014.

Convex Hull Algorithms. Convex hull: basic facts

Robust Boolean Reasoning for Equivalence Checking and Functional Property Verification

ECE 468/573 Midterm 1 September 28, 2012

Class 04 MUX / DMUX and Full Adder

Calculus Differentiation

Systems I. Logic Design I. Topics Digital logic Logic gates Simple combinational logic circuits

Architecture and Data Flows Reference Guide

Duality in linear interval equations

Selecting the Most Highly Correlated Pairs within a Large Vocabulary

WORKSHOP 9 HEX MESH USING SWEEP VECTOR

EECS150 - Digital Design Lecture 23 - High-level Design and Optimization 3, Parallelism and Pipelining

Agenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays

Efficient Subscription Management in Content-based Networks

Lecture 12 : Topological Spaces

Lecture 10 Evolutionary Computation: Evolution strategies and genetic programming

Languages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) *

A Tautology Checker loosely related to Stålmarck s Algorithm by Martin Richards

To access your mailbox from inside your organization. For assistance, call:

COMBINATORIAL PATTERN MATCHING

box Boxes and Arrows 3 true 7.59 'X' An object is drawn as a box that contains its data members, for example:

6.045J/18.400J: Automata, Computability and Complexity. Quiz 2: Solutions. Please write your name in the upper corner of each page.

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)

Don Thomas, 1998, Page 1

COMPUTER EDUCATION TECHNIQUES, INC. (XML ) SA:

Triple/Quadruple Patterning Layout Decomposition via Novel Linear Programming and Iterative Rounding

2 Computing all Intersections of a Set of Segments Line Segment Intersection

Transcription:

Type Cheking Rodmp (Where re we?) Lst leture Contet-sensitie nlysis Motition Attriute grmmrs Ad ho Synt-direted trnsltion This leture Type heking Type systems Using synt direted trnsltion Symol tles Leil soping Implementtion Stk Threded stk 2 1

Types Type: A set of lues nd meningful opertions on them Types proide semnti snity heks (onsisteny heks) nd determine effiient implementtions for dt ojets Types help identify errors, if n opertor is pplied to n inomptile opernd dereferening of non-pointer dding funtion to something inorret numer of prmeters to proedure whih opertion to use for oerloded nmes nd opertors, or wht type oerion to use (e.g.: 3.0 + 1) identifition of polymorphi funtions 3 Type Systems Type system: Eh lnguge onstrut (opertor, epression, sttement, ) is ssoited with type epression. The type system is olletion of rules for ssigning type epressions to these onstruts. Type epressions for si types integer, hr, rel, oolen, typeerror onstruted types // T is type epression rry(lu, T) // rry of T pointer(t) // pointer to T T1 X T2 // tuple of T1, T2 T1 T2 // funtion w/ rg T1 returning T2 4 2

Type System Properties Progress Gien epression e, either e is lue with some type T e -> e (e n e eluted to produe epression e ) I.e., preent epressions suh s (2 3) tht nnot e eluted Presertion Gien epression e with type T If e -> e then e must lso he type T I.e., preents type of epression e from hnging t run time Soundness If type system supports progress & presertion, then Gien epression e, e ->* (for some lue ) or e dierges I.e., well-typed progrms don t go wrong 5 Type Cheker A type heker implements type system. It omputes or onstruts type epressions for eh lnguge onstrut Stti type heking Detets type errors t ompile time No run time oerhed Not lwys possile (e.g., A[i]) Dynmi type heking Performed t run time More fleile, llows prototyping Run-time oerhed to mintin & hek tgs 6 3

Type Inferene (for Epressions) Speifies the type of n epression Emple If opernds of ddition re of type integer, result is of type integer Result of unry & opertor is pointer to type of opernd Denottionl semntis of type inferene rule E e 1 : integer E e 2 : integer E (e 1 + e 2 ): integer where E is type enironment tht mps onstnts nd riles to their type epressions. Question How to speify rules tht llow type oerion (type widening) from integers to rels in rithmeti epressions? 3.0 + 1 or 1 + 3.0 7 Type Inferene (in Generl) Gol Gien epression with no type nnottions, reonstrut lid type for the epression, or determine there is no lid typing Approh Use type riles for unknown types Generte equlity onstrints mong types nd type riles Sole onstrints to determine lid typing (unifition) My require generl Constrint Logi Progrmming (CLP) 8 4

Type Equilene Struturl - type equilene: type nmes re epnded Nme - type equilene: type nmes re not epnded Emple: type A is rry(1..10) of integer; type B is rry(1..10) of integer; : A; : B;, d: rry(1..10) of integer; e: rry(1..10) of integer; Answer: struturl equilene: nme equilene: (,,, d, e) (), (), (, d, e) 9 Synt Direted Trnsltion Sheme (in CUP) Reisit our type inferene rule for +. ep ::= ep:e1 PLUS ep:e2 {: if (e1 == sym.int && e2 == sym.int ) RESULT = sym.int ; else { RESULT = typeerror; System.out.println( Error: illegl opernd types ); : The definition of type epression s J types (stti finl int fields in lss sym) should e done in my.up. The ssignment of type epression J types to terminls nd nonterminls of the grmmr is done in my.up. 10 5

Synt Direted Trnsltion Sheme (in Y) Reisit our type inferene rule for +. ep : ep + ep { if ($1 == integer && $3 == integer) $$ = integer; else { $$ = typeerror; printf( Error: illegl opernd types\n ); The definition of type epression s C types (struts) should e done in ttr.h. ttr. my ontin helper funtions. The ssignment of type epression C types to terminls nd nonterminls of the grmmr is done in prse.y. 11 Type Cheker Emple 12 6

Type Cheker Emple (ont.) Hndling delrtions 13 Type Cheker Emple (ont.) Hndling epressions 14 7

Type Cheker Emple (ont.) Hndling sttements 15 Type Cheker Emple (ont.) Hndling funtions 16 8

Symol Tles Symol tle Compile-time strutures for resoling referenes to nmes Will look t run-time strutures lter Cn lso ssoite ttriutes with nme Attriutes possily ssoited with nme Type Delring proedure Leil leel If rry, numer nd size of dimensions If funtion, numer nd type of prmeters 17 Leilly-soped Symol Tles 5.7 in EC The prolem The ompiler needs distint reord for eh delrtion Nested leil sopes dmit duplite delrtions The interfe insert(nme, leel ) retes reord for nme t leel lookup(nme, leel ) returns pointer or inde delete(leel ) remoes ll nmes delred t leel Mny implementtion shemes he een proposed We ll sty t the oneptul leel Hsh tle implementtion is triky, detiled, & fun (see B.4) 18 9

Emple proedure p { int,, proedure q { int,,, w proedure r { int, y, z. proedure s { int,, r s q B0: { int,, B1: { int,,, w B2: { int, y, z. B3: { int,, 19 Emple proedure p { int,, proedure q { int,,, w proedure r { int, y, z., w,, q proedure s { int,, r s B0: { int 0, 1, 2 B1: { int 3, 4, 5, w 6 B2: { int 7, y 8, z 9. B3: { int 10, 11, 12 11, 4, 2, 12, w 6,, 10, no y or z Pituring it s series of Algol-like proedures 20 10

Leilly-soped Symol Tles High-leel ide Crete new tle for eh sope Chin them together for lookup s q w... p... Chin of tles implementtion insert() my need to rete tle it lwys inserts t urrent leel lookup() wlks hin of tles & returns first ourrene of nme delete() throws wy tle for leel p, if it is top tle in the hin Indiidul tles n e hsh tles. 21 Leilly-soped Symol Tles High-leel ide Crete new tle for eh sope Chin them together for lookup s q w... p... Rememer 11, 4, 2, 12, w 6,, 10, no y or z the nmes isile in s If we dd the susripts, the reltionship etween the ode nd the tle eomes ler 22 11

Implementing Leilly Soped Symol Tles Stk orgniztion netfree s (leel 2) q (leel 1) p (leel 0) w growth Implementtion insert () retes new leel pointer if needed nd inserts t netfree lookup () serhes linerly from netfree 1 forwrd delete () sets netfree to the equl the strt lotion of the leel deleted. Adntge Uses muh less spe Disdntge Lookups n e epensie 23 Implementing Leilly Soped Symol Tles Stk orgniztion 11, 4, 2, 12, w 6,, 10, no y or z netfree s (leel 2) q (leel 1) p (leel 0) w growth 12 11 10 6 5 4 3 2 1 0 Implementtion insert () retes new leel pointer if needed nd inserts t netfree lookup () serhes linerly from netfree 1 forwrd delete () sets netfree to the equl the strt lotion of the leel deleted. Adntge Uses muh less spe Disdntge Lookups n e epensie 24 12

Implementing Leilly Soped Symol Tles Threded stk orgniztion h() w growth s q p Implementtion insert () puts new entry t the hed of the list for the nme lookup () goes diret to lotion delete () proesses eh element in leel eing deleted to remoe from hed of list Adntge lookup is fst Disdntge delete tkes time proportionl to numer of delred riles in leel 25 Implementing Leilly Soped Symol Tles Threded stk orgniztion 11, 4, 2, 12, w 6,, 10, no y or z h() w growth 12 11 10 6 5 4 3 2 1 0 s q p Implementtion insert () puts new entry t the hed of the list for the nme lookup () goes diret to lotion delete () proesses eh element in leel eing deleted to remoe from hed of list Adntge lookup is fst Disdntge delete tkes time proportionl to numer of delred riles in leel 26 13