Chapter 5 Syntax Directed Translation
|
|
- Christopher Harrison
- 6 years ago
- Views:
Transcription
1 Islamic University Gaza Engineering Faculty Department of Computer Engineering ECOM 5060: Compiler Design Discussion Chapter 5 Syntax Directed Translation Eng. Eman R. Habib May, 2014
2 2 Computer Architecture Discussion Exercise 1: Give an SDD to differentiate expressions such as x (3 x + x x) involving the operators + and, the variable x, and constants. Assume that no simplification occurs, so that, for example, 3 x will be translated into x E E 1 + T E.t = E 1.t + T.t E.d = E 1.d + T.d E E 1 - T E.t = E 1.t - T.t E.d = E 1.d - T.d E T E.t = T 1.t E.d = T 1.d T T 1 F T.t = T 1.t F.t T.d = T 1.t F.d + F.t T 1.d T T 1 / F T.t = T 1.t / F.t T.d = ( F.t T 1.d - T 1.t F.d ) / F.t F.t T F T.t = F.t T.d = F.d F (E) F.t = ( E.t ) F.d = ( E.d ) F digit F.t = digit.value F.d = 0 F id F.t = id.lexem F.d = 1 Exercise 2: Below is a grammar for expressions involving operator + and integer or floating-point operands. Floating-point numbers are distinguished by having a decimal point. E E + T T T num.num num a) Give an SDD to determine the type of each T and expression E. b) Extend your SDD of (a) to translate expressions into postfix notation. Use the unary operator inttofloat to turn an integer into an equivalent float. a) E E 1 + T E T T num.num T num if (E 1.type = int & T.type = int) then E.type = int else E.type = float E.type = T.type T.type = float T.type = int
3 3 Computer Architecture Discussion b) E E 1 + T E T T num 1.num 2 T num if (E 1.type = int & T.type = int) then E.type = int E.t = E 1.t T.t + else if E 1.type = int then E.type = float E.t = inttofloat(e 1.t) T.t + else if T.type = int then E.type = float E.t = E 1.t inttofloat (T.t) + else E.type = float E.t = E 1.t T.t + E.type = T.type E.t = T.t T.type = float T.t = num 1.value. num 2.value T.type = int T.t = num.value Exercise 3: Rewrite the underlying grammar in the syntax-directed definition of Example 5.10 so that type information can be propagated using synthesized attributes alone. D int A D float B A A, id A id B B, id B id addtype(id.entry, int) addtype(id.entry, int) addtype(id.entry, float) addtype(id.entry, float)
4 4 Computer Architecture Discussion Exercise 4: Suppose declarations are generated by the following grammar. D id L L, id L :T T int float Construt a translation scheme to enter the type of each identifier into the symbol table. D id L L, id L 1 L :T T int T float addtype(id.entry, L.type) L.type = L 1.type addtype(id.entry, L 1.type) L.type = T.type T.type = int T.type = float Exercise 5: Turn the L-attributed SDD of the following figure into an SDT. S L {B.ps = L.s} B {S.ht = B.ht} L ϵ {L.s = 10} B {B 1.ps = B.ps} B 1 {M.i = B.ps} M {B 2.ps = M.s} B 2 {B.ht = max(b 1.ht, B 2.ht)} B { B 1.ps = B.ps} B1 sub {N.i = B.ps} N { B 2.ps = N.s} B 2 {B.ht = disp(b 1.ht, B 2.ht)} B text {B.ht = text.h X B.ps} M ϵ {M.s = M.i} N ϵ {N.s = shrink(n.i)}
5 5 Computer Architecture Discussion Exercise 6: In this problem you are asked to develop a syntax-directed translation scheme to evaluate binary strings. First you are asked to develop the CFG and then the corresponding attribute grammar illustrating its operation via an example. a) Develop a context-free grammar (CFG) that describes all the binary strings (over the alphabet {0,1}) whose decimal values are multiples of 4. Assume that there can be leading 0s digits but any input sequence that corresponds to the decimal value zero is not in the language, i.e but is in the language. b) For the CFG developed above define the attributes for the non-terminal symbols and terminal symbols of the grammar and develop semantic rules that can be used to compute as the value of an attribute at the start symbol, the numeric decimal value of the input string. For instance for the string the decimal values of an attribute you need to defined and that is associated with the start symbol should be the value 4. c) Using the attribute grammar developed in b) show the annotated parse tree for the input illustrating the dependences between the evaluation of the attributes in this particular parse tree. S List 100 R List.pos = 3 S.value = (List.value + 4) * 2 R.Bits R R 1 0 R.Bits = R 1.Bits + 1 R Ԑ R.Bits = 0 List List 1 Bit List 1.pos = List.pos + 1 Bit.pos = List.pos List.value = List 1.value + Bit.value List Bit Bit.pos = List.pos List.value = Bit.value Bit 0 Bit.value = 0 Bit 1 Bit.value = 2 Bit.pos *2 0 =28 R Bits =0 Ԑ
6 6 Computer Architecture Discussion Exercise 7: Consider the following syntax-directed definition over the grammar defined by G = ({S, A, Sign}, S, {,, -, +, n }, P) with P the set of production and the corresponding semantic rules depicted below. There is a special terminal symbol n that is lexically matched by any string of one numeric digit and whose value is the numeric value of its decimal representation. For the non-terminal symbols in G we have defined two attributes, sign and value. The nonterminal A has these two attributes whereas S only has the value attribute and Sign only has the sign attribute. S A Sign S.val = A.val; A.sign = Sign.sign; print(a.val); Sign + Sign.sign = 1 Sign - Sign.sign = 0 A n A.val = value(n) A A1, n A1.sign = A.sign; if(a.sign = 1) then A.val = max (A1.val,value(n)); else A.val = min (A1.val,value(n)); For this Syntax-Directed Definition answer to the following questions: a) Explain the overall operation of this syntax-directed definition and indicate (with a brief explanation) which of the attributes are either synthesized or inherited. b) Give an attributed parse tree for the source string 5,2,3- and evaluate the attributes in the attributed parse tree depicting the order in which the at tributes need to be evaluated (if more than one order is possible indicate one.) c) Suggest a modified grammar and actions exclusively using synthesized attributes. Explain its basic operation. a) This syntax-directed definition computes the maximum or minimum of a sequence of integers depending on the suffix - or + respectively. As to the attributes, clearly the sign attribute for the Sign non-terminal is synthesized. The val attribute is also synthesized but the sign attribute for A is inherited as it flows from right-to-left (thus from top to bottom in the parse tree) for a production of A. b)
7 7 Computer Architecture Discussion c) The idea is to decouple at the top the two situations, computing a minimum or maximum based on the value of the Sign non-terminal. To accomplish this we have two very similar non-terminal symbols B and C as shown below, which replace the A terminal symbol. Note also the presence of two productions for S for the two computation functions, min and max and the absence of the non-terminal Sign. All attributes are now synthesized as shown in the figure below. S B + S.val = B.val; print(b.val) S C - S.val = C.val; print(c.val) B n B.val = value(n) B B 1, n B.val = max(b1.val,value(n)) C n C.val = value(n) C C 1, n C.val = min(c1.val,value(n))
8 8 Computer Architecture Discussion Exercise 8: Let synthesized attribute val give the value of the binary number generated by S in the following grammar. For example, on input , S.val = S L.L L L LB B B 0 1 S L 1.L 2 S L L L 1 B L B B 0 B.val = 0 B 1 B.val = 1 S.val = L 1.val + (L 2.val/2^L 2.bit) S.val = L.val L.val = L 1.val 2 + B.val L.bit = L.bit+1 L.val = B.val L.bit = 1 باالعادة بعملها مناقشة واخر كومبايلر مناقشة اخر هي انو بما... فلسطين ترجعلنا و حقنا يرجعلنا هللا انو اختم فبدي 66 ال نكبتنا ذكرى أيار 15 بكرة انو وبما... أرضه على يرجع الجئ وكل... فلسطين كل موعدنا والعودة تجمعنا وفلسطين #انتماء #نكبة_فلسطين #nakbba_66 انو زكركو بدي اإلداري االعتقال إلسقاط اإلدرايين األسرى إلضراب 21 ال اليوم هو اليوم انو وبما... ندعيلهم انو نعملو بنقدر شي واقل مطالبهم ويحققو ينتصرو لحتى معهم نتضامن بيستنو األسرى #مي_وملح Best Wishes
[Syntax Directed Translation] Bikash Balami
1 [Syntax Directed Translation] Compiler Design and Construction (CSc 352) Compiled By Central Department of Computer Science and Information Technology (CDCSIT) Tribhuvan University, Kirtipur Kathmandu,
More informationSyntax-Directed Translation
Syntax-Directed Translation What is syntax-directed translation? The compilation process is driven by the syntax. The semantic routines perform interpretation based on the syntax structure. Attaching attributes
More informationSyntax-Directed Translation. CS Compiler Design. SDD and SDT scheme. Example: SDD vs SDT scheme infix to postfix trans
Syntax-Directed Translation CS3300 - Compiler Design Syntax Directed Translation V. Krishna Nandivada IIT Madras Attach rules or program fragments to productions in a grammar. Syntax directed definition
More informationSyntax-Directed Translation. Concepts Introduced in Chapter 5. Syntax-Directed Definitions
Concepts Introduced in Chapter 5 Syntax-Directed Definitions Translation Schemes Synthesized Attributes Inherited Attributes Dependency Graphs Syntax-Directed Translation Uses a grammar to direct the translation.
More informationSyntax Directed Translation
Syntax Directed Translation Rupesh Nasre. CS3300 Compiler Design IIT Madras Aug 2015 Character stream Lexical Analyzer Machine-Independent Code Optimizer F r o n t e n d Token stream Syntax Analyzer Syntax
More informationCOP5621 Exam 3 - Spring 2005
COP5621 Exam 3 - Spring 2005 Name: (Please print) Put the answers on these sheets. Use additional sheets when necessary. Show how you derived your answer when applicable (this is required for full cred
More informationSyntax-Directed Translation Part II
Syntax-Directed Translation Part II Chapter 5 Slides adapted from : Robert van Engelen, Florida State University Alessandro Artale, Free University of Bolzano Syntax-Directed Translation Schemes Syntax-directed
More informationAbstract Syntax Tree
Abstract Syntax Tree Condensed form of parse tree, useful for representing language constructs. The production S if B then s1 else s2 may appear as if-then-else B s1 s2 1 Abstract Syntax tree Chain of
More informationSyntax-Directed Translation Part I
1 Syntax-Directed Translation Part I Chapter 5 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2011 2 The Structure of our Compiler Revisited Character stream
More informationLecture 14 Sections Mon, Mar 2, 2009
Lecture 14 Sections 5.1-5.4 Hampden-Sydney College Mon, Mar 2, 2009 Outline 1 2 3 4 5 Parse A parse tree shows the grammatical structure of a statement. It includes all of the grammar symbols (terminals
More informationSyntax Directed Translation
Syntax Directed Translation Beyond syntax analysis An identifier named x has been recognized. Is x a scalar, array or function? How big is x? If x is a function, how many and what type of arguments does
More informationSemantic Analysis Attribute Grammars
Semantic Analysis Attribute Grammars Martin Sulzmann Martin Sulzmann Semantic Analysis Attribute Grammars 1 / 18 Syntax versus Semantics Syntax Analysis When is a program syntactically valid? Formalism:
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 11! Syntax- Directed Transla>on The Structure of the
More informationMore On Syntax Directed Translation
More On Syntax Directed Translation 1 Types of Attributes We have productions of the form: A X 1 X 2 X 3... X n with semantic rules of the form: b:= f(c 1, c 2, c 3,..., c n ) where b and the c s are attributes
More information1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8]
Code No: R05311201 Set No. 1 1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8] 2. Compute the FIRST and FOLLOW sets of each
More informationSyntax-Directed Translation
Syntax-Directed Translation 1 Syntax-Directed Translation 2 Syntax-Directed Translation 3 Syntax-Directed Translation In a syntax-directed definition, each production A α is associated with a set of semantic
More informationSemantic Analysis with Attribute Grammars Part 4
with Attribute Grammars Part 4 Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture Introduction
More informationA Simple Syntax-Directed Translator
Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called
More informationSemantic Analysis with Attribute Grammars Part 3
with Attribute Grammars Part 3 Department of Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture Introduction
More informationSyntax-Directed Translation
Syntax-Directed Translation 1 Syntax-Directed Translation 1. We associate information with the programming language constructs by attaching attributes to grammar symbols. 2. Values of these attributes
More informationCompilers. 5. Attributed Grammars. Laszlo Böszörmenyi Compilers Attributed Grammars - 1
Compilers 5. Attributed Grammars Laszlo Böszörmenyi Compilers Attributed Grammars - 1 Adding Attributes We connect the grammar rules with attributes E.g. to implement type-checking or code generation A
More informationType checking of statements We change the start rule from P D ; E to P D ; S and add the following rules for statements: S id := E
Type checking of statements We change the start rule from P D ; E to P D ; S and add the following rules for statements: S id := E if E then S while E do S S ; S Type checking of statements The purpose
More informationCSCI Compiler Design
University of Southern California CSCI565 Compiler Design Midterm Exam - Fall 26 CSCI 565 - Compiler Design Fall 26 Midterm Exam Solution Problem : Context-Free-Grammars and Parsing Algorithms [4 points]
More informationCSCI Compiler Design
CSCI 565 - Compiler Design Spring 2015 Midterm Exam March 04, 2015 at 8:00 AM in class (RTH 217) Duration: 2h 30 min. Please label all pages you turn in with your name and student number. Name: Number:
More information10/18/18. Outline. Semantic Analysis. Two types of semantic rules. Syntax vs. Semantics. Static Semantics. Static Semantics.
Outline Semantic Analysis In Text: Chapter 3 Static semantics Attribute grammars Dynamic semantics Operational semantics Denotational semantics N. Meng, S. Arthur 2 Syntax vs. Semantics Syntax concerns
More informationSemantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known.
SEMANTIC ANALYSIS: Semantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known. Parsing only verifies that the program consists of tokens
More informationWe now allow any grammar symbol X to have attributes. The attribute a of symbol X is denoted X.a
Attribute Grammars Attribute Grammars were invented by Don Knuth as a way to unify all of the stages of compiling into one. They give a formal way to pass semantic information (types, values, etc.) around
More informationProgram Assignment 2 Due date: 10/20 12:30pm
Decoration of parse tree for (1 + 3) * 2 N. Meng, S. Arthur 1 Program Assignment 2 Due date: 10/20 12:30pm Bitwise Manipulation of Hexidecimal Numbers CFG E E A bitwise OR E A A A ^ B bitwise XOR A B B
More informationCS 406: Syntax Directed Translation
CS 406: Syntax Directed Translation Stefan D. Bruda Winter 2015 SYNTAX DIRECTED TRANSLATION Syntax-directed translation the source language translation is completely driven by the parser The parsing process
More informationPrinciples of Programming Languages
Principles of Programming Languages h"p://www.di.unipi.it/~andrea/dida2ca/plp- 14/ Prof. Andrea Corradini Department of Computer Science, Pisa Lesson 10! Con:nua:on of the course Syntax- Directed Transla:on
More informationChapter 4 - Semantic Analysis. June 2, 2015
Chapter 4 - Semantic Analysis June 2, 2015 The role of the semantic analyzer Compilers use semantic analysis to enforce the static semantic rules of a language It is hard to generalize the exact boundaries
More information5. Syntax-Directed Definitions & Type Analysis
5. Syntax-Directed Definitions & Type Analysis Eva Rose Kristoffer Rose NYU Courant Institute Compiler Construction (CSCI-GA.2130-001) http://cs.nyu.edu/courses/spring15/csci-ga.2130-001/lecture-5.pdf
More informationΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 8a Syntax-directed Transla1on Elias Athanasopoulos
ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών Lecture 8a Syntax-directed Transla1on Elias Athanasopoulos eliasathan@cs.ucy.ac.cy Syntax-directed TranslaPon (SDT) Μετάφραση Κατευθυνόμενη από τη Σύνταξη We
More informationEvaluation of Semantic Actions in Predictive Non- Recursive Parsing
Evaluation of Semantic Actions in Predictive Non- Recursive Parsing José L. Fuertes, Aurora Pérez Dept. LSIIS School of Computing. Technical University of Madrid Madrid, Spain Abstract To implement a syntax-directed
More informationContext-sensitive analysis. Semantic Processing. Alternatives for semantic processing. Context-sensitive analysis
Semantic Processing The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the program based on its syntactic structure
More informationUNIT IV INTERMEDIATE CODE GENERATION
UNIT IV INTERMEDIATE CODE GENERATION 2 Marks 1. Draw syntax tree for the expression a=b*-c+b*-c 2. Explain postfix notation. It is the linearized representation of syntax tree.it is a list of nodes of
More information10/26/17. Attribute Evaluation Order. Attribute Grammar for CE LL(1) CFG. Attribute Grammar for Constant Expressions based on LL(1) CFG
Attribute Evaluation Order Determining attribute 2 expected_type evaluation order actual_type actual_type for any attribute grammar is a 5 complex problem, 1 [1] [2] requiring
More informationExamples of attributes: values of evaluated subtrees, type information, source file coordinates,
1 2 3 Attributes can be added to the grammar symbols, and program fragments can be added as semantic actions to the grammar, to form a syntax-directed translation scheme. Some attributes may be set by
More informationCSCI Compiler Design
University of Southern California CSCI565 Compiler Design Midterm Exam - Spring 26 CSCI 565 - Compiler Design Spring 26 Midterm Exam March, 26 at : PM in class (KAP 47) Duration: 2h 3 min. Please label
More informationComputer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres
Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres dgriol@inf.uc3m.es Introduction He am a driver might be syntactically correct but semantically wrong. Semantic
More informationUNIT-3. (if we were doing an infix to postfix translator) Figure: conceptual view of syntax directed translation.
UNIT-3 SYNTAX-DIRECTED TRANSLATION: A Grammar symbols are associated with attributes to associate information with the programming language constructs that they represent. Values of these attributes are
More informationSummary: Semantic Analysis
Summary: Semantic Analysis 1 Basic Concepts When SA is performed: Semantic Analysis may be performed: In a two-pass compiler: after syntactic analysis is finished, the semantic analyser if called with
More informationA simple syntax-directed
Syntax-directed is a grammaroriented compiling technique Programming languages: Syntax: what its programs look like? Semantic: what its programs mean? 1 A simple syntax-directed Lexical Syntax Character
More informationAbstract Syntax Trees Synthetic and Inherited Attributes
Abstract Syntax Trees Synthetic and Inherited Attributes Lecture 22 Sections 5.1-5.2 Robb T. Koether Hampden-Sydney College Mon, Mar 16, 2015 Robb T. Koether (Hampden-Sydney College)Abstract Syntax TreesSynthetic
More informationQUESTIONS RELATED TO UNIT I, II And III
QUESTIONS RELATED TO UNIT I, II And III UNIT I 1. Define the role of input buffer in lexical analysis 2. Write regular expression to generate identifiers give examples. 3. Define the elements of production.
More informationMore Assigned Reading and Exercises on Syntax (for Exam 2)
More Assigned Reading and Exercises on Syntax (for Exam 2) 1. Read sections 2.3 (Lexical Syntax) and 2.4 (Context-Free Grammars) on pp. 33 41 of Sethi. 2. Read section 2.6 (Variants of Grammars) on pp.
More informationSyntax-Directed Translation. Introduction
Syntax-Directed Translation Introduction Translation of languages guided by context-free grammars Attach attributes to the grammar symbols Values of the attributes are computed by semantic rules associated
More informationMATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL. John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards
MATVEC: MATRIX-VECTOR COMPUTATION LANGUAGE REFERENCE MANUAL John C. Murphy jcm2105 Programming Languages and Translators Professor Stephen Edwards Language Reference Manual Introduction The purpose of
More informationStructure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.
More detailed overview of compiler front end Structure of a compiler Today we ll take a quick look at typical parts of a compiler. This is to give a feeling for the overall structure. source program lexical
More informationSemantic analysis and intermediate representations. Which methods / formalisms are used in the various phases during the analysis?
Semantic analysis and intermediate representations Which methods / formalisms are used in the various phases during the analysis? The task of this phase is to check the "static semantics" and generate
More informationSyntax-directed translation. Context-sensitive analysis. What context-sensitive questions might the compiler ask?
Syntax-directed translation Context-sensitive analysis The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the
More informationCSCI Compiler Design
University of Southern California CSCI565 Compiler Design Mterm Exam Solution - Spring 2014 CSCI 565 - Compiler Design Spring 2014 Mterm Exam - Solution Problem 1: Context-Free-Grammars and Parsing Algorithms
More informationCompiler Construction
Compiler Construction Collection of exercises Version February 7, 26 Abbreviations NFA. Non-deterministic finite automaton DFA. Deterministic finite automaton Lexical analysis. Construct deterministic
More informationCOP4020 Programming Languages. Semantics Robert van Engelen & Chris Lacher
COP4020 Programming Languages Semantics Robert van Engelen & Chris Lacher Overview Static semantics Dynamic semantics Attribute grammars Abstract syntax trees Static Semantics Syntax concerns the form
More informationGujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)
Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov 2014 Compiler Design (170701) Question Bank / Assignment Unit 1: INTRODUCTION TO COMPILING
More informationCPS 506 Comparative Programming Languages. Syntax Specification
CPS 506 Comparative Programming Languages Syntax Specification Compiling Process Steps Program Lexical Analysis Convert characters into a stream of tokens Lexical Analysis Syntactic Analysis Send tokens
More informationCOP4020 Programming Languages. Semantics Prof. Robert van Engelen
COP4020 Programming Languages Semantics Prof. Robert van Engelen Overview Static semantics Dynamic semantics Attribute grammars Abstract syntax trees COP4020 Spring 2011 2 Static Semantics Syntax concerns
More informationSemantic Analysis. Role of Semantic Analysis
Semantic Analysis Chapter 4 Role of Semantic Analysis Following parsing, the next two phases of the "typical" compiler are semantic analysis (intermediate) code generation The principal job of the semantic
More informationCOMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]
More informationCompiler Construction
Compiled on 5/05/207 at 3:2pm Abbreviations NFA. Non-deterministic finite automaton DFA. Deterministic finite automaton Compiler Construction Collection of exercises Version May 5, 207 General Remarks
More informationCSE302: Compiler Design
CSE302: Compiler Design Instructor: Dr. Liang Cheng Department of Computer Science and Engineering P.C. Rossin College of Engineering & Applied Science Lehigh University April 3, 2007 Outline Recap Syntax-directed
More informationFormal Languages and Compilers Lecture IX Semantic Analysis: Type Chec. Type Checking & Symbol Table
Formal Languages and Compilers Lecture IX Semantic Analysis: Type Checking & Symbol Table Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/
More informationType Checking. Chapter 6, Section 6.3, 6.5
Type Checking Chapter 6, Section 6.3, 6.5 Inside the Compiler: Front End Lexical analyzer (aka scanner) Converts ASCII or Unicode to a stream of tokens Syntax analyzer (aka parser) Creates a parse tree
More informationA programming language requires two major definitions A simple one pass compiler
A programming language requires two major definitions A simple one pass compiler [Syntax: what the language looks like A context-free grammar written in BNF (Backus-Naur Form) usually suffices. [Semantics:
More informationComputer Programming: C++
The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #3 Loops Part I Contents Introduction For-Loop
More informationLECTURE 3. Compiler Phases
LECTURE 3 Compiler Phases COMPILER PHASES Compilation of a program proceeds through a fixed series of phases. Each phase uses an (intermediate) form of the program produced by an earlier phase. Subsequent
More informationTest I Solutions MASSACHUSETTS INSTITUTE OF TECHNOLOGY Spring Department of Electrical Engineering and Computer Science
Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY 6.035 Spring 2013 Test I Solutions Mean 83 Median 87 Std. dev 13.8203 14 12 10 8 6 4 2 0 0 10 20 30 40 50
More informationStatic and Dynamic Semantics
Copyright R.A. van Engelen, FSU Department of Computer Science, 2000 Semantic Analysis In this set of notes you will learn about: Static semantics Dynamic semantics Attribute grammars Abstract syntax trees
More informationThis book is licensed under a Creative Commons Attribution 3.0 License
6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars
More informationType Checking. Error Checking
Type Checking Error Checking Dynamic checking takes place while program is running Static checking takes place during compilation Type checks Flow-of-control checks Uniqueness checks Name-related checks
More informationSyntax-Directed Translation
Syntax-Directed Translation ALSU Textbook Chapter 5.1 5.4, 4.8, 4.9 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 What is syntax-directed translation? Definition: The compilation
More informationIntermediate Code Generation Part II
Intermediate Code Generation Part II Chapter 6: Type checking, Control Flow Slides adapted from : Robert van Engelen, Florida State University Static versus Dynamic Checking Static checking: the compiler
More information4. Semantic Processing and Attributed Grammars
4. Semantic Processing and Attributed Grammars 1 Semantic Processing The parser checks only the syntactic correctness of a program Tasks of semantic processing Checking context conditions - Declaration
More informationAbstract Syntax Trees & Top-Down Parsing
Abstract Syntax Trees & Top-Down Parsing Review of Parsing Given a language L(G), a parser consumes a sequence of tokens s and produces a parse tree Issues: How do we recognize that s L(G)? A parse tree
More informationAbstract Syntax Trees & Top-Down Parsing
Review of Parsing Abstract Syntax Trees & Top-Down Parsing Given a language L(G), a parser consumes a sequence of tokens s and produces a parse tree Issues: How do we recognize that s L(G)? A parse tree
More informationAttribute Grammars. Attribute Grammars
Attribute Grammars Definitions: synthesized, inherited, dependence graph Example: syntax-directed translation S-attributed grammars -attributed grammars Bottom Up euation of inherited attributes Top Down
More informationAs we have seen, token attribute values are supplied via yylval, as in. More on Yacc s value stack
More on Yacc s value stack As we noted last time, Yacc uses a second stack to store the attribute values of the tokens and terminals in the parse stack. For a token, the attributes are computed by the
More informationAbout the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design
i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target
More informationAbstract Syntax Trees & Top-Down Parsing
Review of Parsing Abstract Syntax Trees & Top-Down Parsing Given a language L(G), a parser consumes a sequence of tokens s and produces a parse tree Issues: How do we recognize that s L(G)? A parse tree
More informationError Handling Syntax-Directed Translation Recursive Descent Parsing
Error Handling Syntax-Directed Translation Recursive Descent Parsing Lecture 6 by Professor Vijay Ganesh) 1 Outline Recursive descent Extensions of CFG for parsing Precedence declarations Error handling
More informationCompiler Principle and Technology. Prof. Dongming LU April 15th, 2019
Compiler Principle and Technology Prof. Dongming LU April 15th, 2019 PART TWO 6. Semantic Analysis Contents Part One 6.1 Attributes and Attribute Grammars Part Two 6.2 Algorithms for Attribute Computation
More informationProgramming Languages
Programming Languages Tevfik Koşar Lecture - IX February 14 th, 2006 1 Roadmap Semantic Analysis Role of Semantic Analysis Static vs Dynamic Analysis Attribute Grammars Evaluating Attributes Decoration
More informationCS415 Compilers Context-Sensitive Analysis Type checking Symbol tables
CS415 Compilers Context-Sensitive Analysis Type checking Symbol tables These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Lecture 18 1 Announcements
More informationNARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY Page 1
SEM / YEAR : VI / III CS2352 PRINCIPLES OF COMPLIERS DESIGN UNIT III INTERMEDIATE CODE GENERATION PART A 1. What are the benefits of intermediate code generation? (A.U May 2008) A Compiler for different
More informationAmbiguity and Errors Syntax-Directed Translation
Outline Ambiguity (revisited) Ambiguity and rrors Syntax-Directed Translation xtensions of CFG for parsing Precedence declarations rror handling Semantic actions Constructing a parse tree CS780(Prasad)
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationQuestion Bank. 10CS63:Compiler Design
Question Bank 10CS63:Compiler Design 1.Determine whether the following regular expressions define the same language? (ab)* and a*b* 2.List the properties of an operator grammar 3. Is macro processing a
More informationChapter 3. Describing Syntax and Semantics
Chapter 3 Describing Syntax and Semantics Chapter 3 Topics Introduction The General Problem of Describing Syntax Formal Methods of Describing Syntax Attribute Grammars Describing the Meanings of Programs:
More informationCOP4020 Spring 2011 Midterm Exam
COP4020 Spring 2011 Midterm Exam Name: (Please print Put the answers on these sheets. Use additional sheets when necessary or write on the back. Show how you derived your answer (this is required for full
More informationChapter 4 :: Semantic Analysis
Chapter 4 :: Semantic Analysis Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier 1 Chapter04_Semantic_Analysis_4e - Tue November 21, 2017 Role of Semantic Analysis
More informationIntroduction to Parsing. Lecture 8
Introduction to Parsing Lecture 8 Adapted from slides by G. Necula Outline Limitations of regular languages Parser overview Context-free grammars (CFG s) Derivations Languages and Automata Formal languages
More informationCompilers. Compiler Construction Tutorial The Front-end
Compilers Compiler Construction Tutorial The Front-end Salahaddin University College of Engineering Software Engineering Department 2011-2012 Amanj Sherwany http://www.amanj.me/wiki/doku.php?id=teaching:su:compilers
More informationPRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS
Objective PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS Explain what is meant by compiler. Explain how the compiler works. Describe various analysis of the source program. Describe the
More information2068 (I) Attempt all questions.
2068 (I) 1. What do you mean by compiler? How source program analyzed? Explain in brief. 2. Discuss the role of symbol table in compiler design. 3. Convert the regular expression 0 + (1 + 0)* 00 first
More informationCS 4201 Compilers 2014/2015 Handout: Lab 1
CS 4201 Compilers 2014/2015 Handout: Lab 1 Lab Content: - What is compiler? - What is compilation? - Features of compiler - Compiler structure - Phases of compiler - Programs related to compilers - Some
More informationCSE 311 Lecture 21: Context-Free Grammars. Emina Torlak and Kevin Zatloukal
CSE 311 Lecture 21: Context-Free Grammars Emina Torlak and Kevin Zatloukal 1 Topics Regular expressions A brief review of Lecture 20. Context-free grammars Syntax, semantics, and examples. 2 Regular expressions
More informationProgramming Lecture 3
Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements
More informationPART 4 - SYNTAX DIRECTED TRANSLATION. F. Wotawa TU Graz) Compiler Construction Summer term / 309
PART 4 - SYNTAX DIRECTED TRANSLATION F. Wotawa (IST @ TU Graz) Compiler Construction Summer term 2016 109 / 309 Setting Translation of context-free languages Information attributes of grammar symbols Values
More informationThere is a level of correctness that is deeper than grammar. There is a level of correctness that is deeper than grammar
Beyond Syntax There is a level of correctness that is deeper than grammar fie(a,b,c,d) int a, b, c, d; { } What is wrong with this program? (let me count the ways ) fee() { int f[3],g[0], h, i, j, k; char
More informationPartial Exam Compilation and Program Analysis (CAP) October, 24th, 2016 Duration: 2 Hours
http://laure.gonnord.org/pro/ CAP, ENSL, 2016/2017 Partial Exam Compilation and Program Analysis (CAP) October, 24th, 2016 Duration: 2 Hours Only one a4 sheet (10pt, recto/verso) is autorized. Instructions
More information