NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY Page 1

Size: px
Start display at page:

Download "NARESHKUMAR.R, AP\CSE, MAHALAKSHMI ENGINEERING COLLEGE, TRICHY Page 1"

Transcription

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 machines can be created by attaching different back end to the existing front ends of each machine. A Compiler for different source languages can be created by proving different front ends for corresponding source languages t existing back end. A machine independent code optimizer can be applied to intermediate code in order to optimize the code generation. 2. What are the various types of intermediate code representation? (A.U Nov/Dec 2007) There are mainly three types of intermediate code representations. Syntax tree Postfix Three address code 3. Define back patching. (A.U Nov/Dec 2009) (A.U Nov/Dec 2010)NOV DEC 2012 Back patching is the activity of filling up unspecified information of labels using appropriate semantic actions in during the code generation process. In the semantic actions the functions used are mklist (i), merge list(p1,p2) and back patch(p,i) 4.Mention the functions that are used in back patching. (A.U Nov/Dec 2007) (i)creates the new list. The index iis passed as an argument to this function where I is an index to the array of quadruple. (ii)merge list (p1, p2) this function concatenates two lists pointed by p1 and p2. It returns the pointer to the concatenated list. (iii)back patch (p, i) inserts i as target label for the statement pointed by pointer p. 5. What is the intermediate code representation for the expression a or b And not c? The intermediate code representation for the expression a or b and not c is the three address sequence t1 := not c t2 := b and t1 t3 := a or t2 6. What are the various methods of implementing three address statements? The three address statements can be implemented using the following methods. Quadruple: a structure with at most four fields such as operator (OP), arg1, arg2, result. Triples: the use of temporary variables is avoided by referring the pointersin the symbol table. Indirect triples: the listing of triples has been done and listing pointers are used instead of using statements. 7. Give the syntax-directed definition for if-else statement. (A.U May/june 2008) 1. S if E then S1 E.true := new_label() Page 1

2 E.false :=S.next S1.next :=S.next S.code :=E.code gen_code(e.true : ) S1.code 2. S if E then S1 else S2 E.true := new_label() E.false := new_label() S1.next :=S.next S2.next :=S.next S.code :=E.code gen_code(e.true : ) S1.code gen_code( go to,s.next) gen_code(e.false : ) S2.code 8. What are the methods to represent the value of a Boolean expression? Numerical representation Encode true and false. Numerically and to evaluate a Boolean expression analogously to an arithmetic expression. Flow of Control Implementing Boolean expression is by flow of control i.e.,representing the value of a Boolean expression by a positionreached in a program. 9. Define short-circuit code. (A.U May/June 2008) It translates a Boolean expression into three address code without generatingcode for any of the Boolean operators and without having the code necessarilyevaluates the entire expression. This type of evaluation is called short circuit orjumping code. 10. Define Boolean expression. Boolean expressions are composed of the Boolean operators (and,or, not) applied to elements. Those are Boolean variables or relational expressions. 11. Define three address codes. (A.U Nov/Dec 2010) Three address code is a sequence of statements of the general form x: = y op z where x,y,z are operand and op is operator. 12. Write the properties of intermediate languages. The intermediate language is an easy form of source language which Can be generated efficiently by the compiler. The generation of intermediate language should lead to efficient codegeneration. The intermediate language should act as effective mediator between Front and back end. The intermediate language should be flexible enough so that optimized Code can be generated. 13. Generate the three address code for an expression x: = a + b * c +d ; Assuming x and a as real and b,c and d are integer. t1 := b int * c t2 := t1 int + d t3 := inttoreal t2 t4 := a real + t3 x := t4 Page 2

3 14. Generate the three address code for while (i<10) {x := 0;i := i + 1; } The three address code can be generated as follows 100 L1 : if i<10 goto L2 101 GotoLnext 102 L2 : x = i = i goto L1 105 Lnext 15. Write the translation scheme for while (i<10) {x := 0;i := i + 1; }S.begin = new_label() = L1 E.true = new_label() = L2 E.code = if i<10 goto E.false = S.next = Lnext S1.code = x =0; i = i + 1 Generate the three address code for switch (ch) {case 1: c := a + b; break; case 2: c := a b; break; }The three address code can be generated as follows 100 ifch = 1 goto L1 101 ifch = 2 goto L2 102 L1: t1 := a + b 103 c := t1 104 goto Last 105 L2 : t1 : = a - b 106 c := t1 107 Page 3

4 goto Last 108 Last: 16. Write the translation scheme for switch (ch) {case 1: c := a + b; break; case 2: c := a b; break; }Evaluate E into t such that t = E Goto check L1 : code for s1 goto last L2 : code for s2 goto last check : if c = a + b goto L1 if c = a b goto L2 last: 17. Write the semantic action for the production rule of E E1 OR M E2. {Backpatch (E1.Flist, M.state); E.Tlist := merge ( E1.Tlist,E2.Tlist); E.Flist := E2.Flist } 18. Write the semantic action for the production rule of S call id (L). {for each item p in queue do append ( param p); append ( call id.place } 19. Write the semantic action for the production rule of L. L, E. { inserte.place in the queue } 20. Write the semantic action for the production rule of L. E(A.U Nov/Dec 2007) {initialize queue and insert E.place in the queue } 21. What are the advantages of generating an intermediate representation? i) Ease of conversion from the source program to the intermediate code. ii) Ease with which subsequent processing can be performed from the intermediate code. 22. Define a syntax-directed translation? Syntax-directed translation specifies the translation of a construct in terms of Attributes associated with its syntactic components. Syntax-directed translation uses a context free grammar to specify the syntactic structure of the input. It is an input- output mapping. 23. Define an attribute. Give the types of an attribute? An attribute may represent any quantity, with each grammar symbol, it associates a set of attributes and with each production, a set of semantic rules for computing values of the attributes associated with the symbols appearing in that production. Page 4

5 Example: a type, a value, a memory location etc., i) Synthesized attributes. ii) Inherited attributes. 24. Define annotated parse tree? A parse tree showing the values of attributes at each node is called an annotated parse tree. The process of computing an attribute values at the nodes is called annotating parse tree. Example: an annotated parse tree for the input 3*5+4n. 25. Define dependency graph? The interdependencies among the inherited and synthesized attributes at the nodes in a parse tree can be depicted by a directed graph is called a dependency graph. Example: Production E_ E1 + E2 Semantic Rule E.val:= E1.va; + E2.val 26. Define syntax tree. Give an example? APRIL MAY 2011 An (abstract) syntax tree is a condensed form of parse tree useful for representing language constructs. Example: syntax tree for a 4 + c + - c a What are the functions used to create the nodes of syntax trees? i) Mknode (op, left, right) SNSCT Department of Compute Science and Engineering Page 12 ii) Mkleaf (id,entry) iii) Mkleaf (num, val) 28. What are the functions for constructing syntax trees for expressions? i) The construction of a syntax tree for an expression is similar to the translation of the expression into postfix form. ii) Each node in a syntax tree can be implemented as a record with several fields. 29. Define DAG. Give an example? NOV DEC 2011 DAG is a directed acyclic graph for an expression identifies the common sub expression in the expression. Example: DAG for the expression a- 4 *c P1 = mkleaf(id,a) P2 = mknum(num,4) P3 = mkleaf(id,c) P4 = mknode( *,p2,p3) P5 = mknode( -,p1,p4) 30. What are the three kinds of intermediate representations? i) Syntax trees. ii) Postfix notation. iii) Three address code. 31. Define postfix notation? Postfix notation is a linearized representation of a syntax tree. It is a list of the nodes of the tree in which a node appears immediately after its children. The syntax tree is, a: = b*-c The postfix notation for the syntax tree is, abc-*c 32. Define three-address code? Three address code is a sequence of statements of the form x: = y op z. where x, y, z are names, constants, or compiler generated temporaries, op stand for any type of operator. Since a statement involves not more than three references it is called three-address statement, and hence a sequence of such statement is called three address codes. Page 5

6 33. What are the types of three address statements? NOV DEC 2011 Assignment statements, assignment instruction, copy statements, conditional jump, address-address statements, indexed assignment statements, address and pointer statements. 34. What are the three types of implementations of three-address statements? i) Quadruples ii) Triples iii) Indirect Triples. 35. What are the methods of translating Boolean expressions? There are two principal methods of representing the value of a Boolean expression. a) Encode true and false numerically and to evaluate a Boolean expression analogous to an arithmetic expression. SNSCT Department of Compute Science and Engineering Page 13 b) Flow-of control. Represent the value of a Boolean expression by a position reached in a program. 36. What are the two purposes of Boolean expressions? a) They are used to compute logical expressions. b) Often they are used as condition expression in statements that alter the flow of control, such as if-then, if-then-else, or while-do statements. 37. Define quadruple. Give an example? A quadruple is a record structure with four fields: op, arg1, arg2 and result. The op field contains an internal code for the operator. Example: x: =y op z 38. Give the advantages of quadruples? i) Can perform peephole optimization. ii) The contents of field s arg1, arg2 and result are normally pointers to The symbol-table entries for the names represented by these fields. If So, temporary names must be entered into the symbol table as they Are created. 39. Define triple. Give an example? Triple is a record structure with three fields: op, arg1 and arg2. The fields arg1 and arg2 are either pointes to the symbol-table or pointers into the triple structure. This method is used to avoid temporary names into the symbol table. 40. Define indirect triples. Give the advantage? Listing pointers to triples rather than listing the triples themselves are called indirect triples. Advantages: it can save some space compared with quadruples, if the same temporary value is used more than once. 41. Define translation scheme? A translation scheme is a CFG in which program fragments called semantic action are embedded within the right sides of productions. A translation scheme is like a syntax-directed definition, except that the order of evaluation of the semantic rules is explicitly shown. 42. What are the three address code for a or b and not c? The three address sequence is T1:= not c T2:= b and T1 T3:= a or T Write a three address code for the expression a < b or c < d? 100: if a<b goto : t1:=0 Page 6

7 102: goto : t1:=1 104: if c<d goto 107 SNSCT Department of Compute Science and Engineering Page : t2:=0 106: goto : t2:=1 108: t3:=t1 or t2 44. What are the parameter transmission mechanisms? 1. Call by value 2. Call by value-result 3. Call by reference 4. Call by name 45. Construct a DAG for the expression I: = I + 10? := + I What are the various data structure used for implementing the symbol table? 1. Linear list 2. Binary tree 3. Hash table 47. What is the purpose of DAG? i) A label for each node. For leaves the label is an identifier and for interior nodes, an operator symbol ii) For each node a list of attached identifiers. 48. What are the three functions of backpatching? i) Makelist(i) create a new list. ii) Merge(p1,p2) concatenates the lists pointed to by p1 and p2. iii) Backpatch(p,i) insert i as the target label for the statements pointed to by p. 49. Give short note about call-by-name? Call by name, at every reference to a formal parameter in a procedure body the name of the corresponding actual parameter is evaluated. Access is then made to the effective parameter. 50. How parameters are passed to procedures in call-by-value method? This mechanism transmits values of the parameters of call to the called program. The transfer is one way only and therefore the only way to returned can be the value of a function. Main ( ) { print (5); } Int SNSCT Department of Compute Science and Engineering Page 15 Void print (int n) { printf ( %d, n); } 51. Define symbol table? A compiler uses a symbol-table to keep track of scope and binding information about names. It is searched every time a name is encountered in the source text changes to the table occur, if a new name or new information about an existing name is discovered. 52. What are the semantic rules are defined in the declarations operations? 1) Mktable(previous) 2) Enter(table, name,type,offset) Page 7

8 3) Addwidth(table,width) 4) Enterproc(table,namenewtable) 53. Give the syntax of case statements? Switch expression Begin Case value: statement Case value: statement Case value: statement Default : statement End 54. Give the 2 attributes of syntax directed translation into 3-addr code? i) E.place, the name that will hold the value of E and ii) E.code, the sequence of 3-addr statements evaluating E. 55. Write a short note on declarations? Declarations in a procedure, for each local name, we create a symbol table entry with information like the type and the relative address of the storage for the name. The relative address consists of an offset from the base of the static data area or the field for local data in an activation record. The procedure enter (name, type, offset) create a symbol table entry. 56. Give the two parts of basic hashing scheme? 1) A hash table consisting of a fixed array of m pointers to table entries. 2) Table entries organized into m separate linked lists, called buckets. Each record in the symbol table appears on exactly one of these lists. 57. Write the grammar for flow-of-control statements? The following grammar generates the flow-of-control statements, if-then, if-thenelse, and while-do statements. S _ if E then S1 If E then S1 else S2 While E do S1. SNSCT Department of Compute Science and Engineering Page Write the 3-addr code for the statements a =b*-c + b*-c? Three address codes are: a=b*-c + b*-c T1 = -c T2 = b*t1 T3 = -c T4 = b*t3 T5 = T2+T4 a:= T5. Page 8

9 59. What. is a syntax tree? Draw the syntax tree for the following statement:a:=b - c+b*-c. APRIL MAY 2012 Syntax tree: A syntax tree depicts the natural hierarchical structure of a source program. A dag (Directed Acyclic Graph) gives the same information but in a more compact way because common subexpressions are identified. A syntax tree and dag for the assignment statement a : =b * - c + b * - c are as follows: 60. Page 9

UNIT IV INTERMEDIATE CODE GENERATION

UNIT 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 information

Syntax-Directed Translation

Syntax-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 information

UNIT-3. (if we were doing an infix to postfix translator) Figure: conceptual view of syntax directed translation.

UNIT-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 information

Module 25 Control Flow statements and Boolean Expressions

Module 25 Control Flow statements and Boolean Expressions Module 25 Control Flow statements and Boolean Expressions In this module we learn to generate three address code for control flow statements. We will also try to incorporate short circuit information in

More information

CMPSC 160 Translation of Programming Languages. Three-Address Code

CMPSC 160 Translation of Programming Languages. Three-Address Code CMPSC 160 Translation of Programming Languages Lectures 16: Code Generation: Three- Address Code Three-Address Code Each instruction can have at most three operands Each operand corresponds to a memory

More information

Chapter 6 Intermediate Code Generation

Chapter 6 Intermediate Code Generation Chapter 6 Intermediate Code Generation Outline Variants of Syntax Trees Three-address code Types and declarations Translation of expressions Type checking Control flow Backpatching Introduction Intermediate

More information

Dixita Kagathara Page 1

Dixita Kagathara Page 1 2014 Sem-VII Intermediate Code Generation 1) What is intermediate code? Intermediate code is: The output of the parser and the input to the Code Generator. Relatively machine-independent: allows the compiler

More information

Formal Languages and Compilers Lecture X Intermediate Code Generation

Formal Languages and Compilers Lecture X Intermediate Code Generation Formal Languages and Compilers Lecture X Intermediate Code Generation Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation 1 Intermediate Code Generation Translating source program into an intermediate language" Simple CPU Independent, yet, close in spirit to machine language Benefits Retargeting

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target

More information

Principle of Compilers Lecture VIII: Intermediate Code Generation. Alessandro Artale

Principle of Compilers Lecture VIII: Intermediate Code Generation. Alessandro Artale Free University of Bolzano Principles of Compilers. Lecture VIII, 2003/2004 A.Artale (1 Principle of Compilers Lecture VIII: Intermediate Code Generation Alessandro Artale Faculty of Computer Science Free

More information

PRINCIPLES OF COMPILER DESIGN

PRINCIPLES OF COMPILER DESIGN PRINCIPLES OF COMPILER DESIGN 2 MARK QUESTIONS WITH ANSWERS UNIT I 1. What is a Complier? A Complier is a program that reads a program written in one language-the source language-and translates it in to

More information

VIVA QUESTIONS WITH ANSWERS

VIVA QUESTIONS WITH ANSWERS VIVA QUESTIONS WITH ANSWERS 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the

More information

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program. COMPILER DESIGN 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the target

More information

Module 26 Backpatching and Procedures

Module 26 Backpatching and Procedures Module 26 Backpatching and Procedures In this module, we would learn to generate three-address code for control flow statements using backpatching. We shall also discuss to combine Boolean expressions

More information

CS2210: Compiler Construction. Code Generation

CS2210: Compiler Construction. Code Generation Modern Compiler Project Fortran program Fortran s Lexer, Parser, and Static Checker Intermediate Code Generator IR MIPS Code Generator MIPS code C program C s Lexer, Parser, and Static Checker Intermediate

More information

A Simple Syntax-Directed Translator

A 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 information

CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV. Department of Computer Science University of Arizona

CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV. Department of Computer Science University of Arizona CSc 453 Compilers and Systems Software 16 : Intermediate Code IV Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Control Structures Control Structures

More information

UNIT I INTRODUCTION TO COMPILING

UNIT I INTRODUCTION TO COMPILING UNIT I INTRODUCTION TO COMPILING 1. Define compiler? A compiler is a program that reads a program written in one language (source language) and translates it into an equivalent program in another language

More information

Computer 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 Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres dgriol@inf.uc3m.es Compiler Architecture Source language Scanner (lexical analysis) tokens Parser (syntax

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation 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 information

intermediate-code Generation

intermediate-code Generation intermediate-code Generation }sequence of intermediate representations source program High Level intermediate Representation Low Level intermediate Representation Target Code e.g. C programming language

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Rupesh Nasre. CS3300 Compiler Design IIT Madras July 2018 Character stream Lexical Analyzer Machine-Independent Code Code Optimizer F r o n t e n d Token stream Syntax Analyzer

More information

Control Structures. Boolean Expressions. CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV

Control Structures. Boolean Expressions. CSc 453. Compilers and Systems Software. 16 : Intermediate Code IV CSc 453 Compilers and Systems Software 16 : Intermediate Code IV Control Structures Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Control Structures

More information

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI UNIT I - LEXICAL ANALYSIS 1. What is the role of Lexical Analyzer? [NOV 2014] 2. Write

More information

Semantic 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? 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 information

COP5621 Exam 3 - Spring 2005

COP5621 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 information

THEORY OF COMPILATION

THEORY OF COMPILATION Lecture 09 IR (ackpatching) THEORY OF COMPILATION Eran Yahav www.cs.technion.ac.il/~yahave/tocs2011/compilers-lec09.pptx Reference: Dragon 6.2,6.3,6.4,6.6 1 Recap Lexical analysis regular expressions identify

More information

Question Bank. 10CS63:Compiler Design

Question 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 information

Concepts Introduced in Chapter 6

Concepts Introduced in Chapter 6 Concepts Introduced in Chapter 6 types of intermediate code representations translation of declarations arithmetic expressions boolean expressions flow-of-control statements backpatching EECS 665 Compiler

More information

Time : 1 Hour Max Marks : 30

Time : 1 Hour Max Marks : 30 Total No. of Questions : 6 P4890 B.E/ Insem.- 74 B.E ( Computer Engg) PRINCIPLES OF MODERN COMPILER DESIGN (2012 Pattern) (Semester I) Time : 1 Hour Max Marks : 30 Q.1 a) Explain need of symbol table with

More information

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design

PSD3A Principles of Compiler Design Unit : I-V. PSD3A- Principles of Compiler Design PSD3A Principles of Compiler Design Unit : I-V 1 UNIT I - SYLLABUS Compiler Assembler Language Processing System Phases of Compiler Lexical Analyser Finite Automata NFA DFA Compiler Tools 2 Compiler -

More information

CS322 Languages and Compiler Design II. Spring 2012 Lecture 7

CS322 Languages and Compiler Design II. Spring 2012 Lecture 7 CS322 Languages and Compiler Design II Spring 2012 Lecture 7 1 USES OF BOOLEAN EXPRESSIONS Used to drive conditional execution of program sections, e.g. IF (a < 17) OR (b = 12) THEN... ELSE...; WHILE NOT

More information

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών Lecture 11a Intermediate Code Generation Elias Athanasopoulos eliasathan@cs.ucy.ac.cy Declarations For each local name Creation of symbol-table entry Add type

More information

Syntax Directed Translation

Syntax 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 information

Concepts Introduced in Chapter 6

Concepts Introduced in Chapter 6 Concepts Introduced in Chapter 6 types of intermediate code representations translation of declarations arithmetic expressions boolean expressions flow-of-control statements backpatching EECS 665 Compiler

More information

Acknowledgement. CS Compiler Design. Intermediate representations. Intermediate representations. Semantic Analysis - IR Generation

Acknowledgement. CS Compiler Design. Intermediate representations. Intermediate representations. Semantic Analysis - IR Generation Acknowledgement CS3300 - Compiler Design Semantic Analysis - IR Generation V. Krishna Nandivada IIT Madras Copyright c 2000 by Antony L. Hosking. Permission to make digital or hard copies of part or all

More information

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan Language Processing Systems Prof. Mohamed Hamada Software ngineering Lab. The University of Aizu Japan Intermediate/Code Generation Source language Scanner (lexical analysis) tokens Parser (syntax analysis)

More information

Module 27 Switch-case statements and Run-time storage management

Module 27 Switch-case statements and Run-time storage management Module 27 Switch-case statements and Run-time storage management In this module we will discuss the pending constructs in generating three-address code namely switch-case statements. We will also discuss

More information

CSc 453 Intermediate Code Generation

CSc 453 Intermediate Code Generation CSc 453 Intermediate Code Generation Saumya Debray The University of Arizona Tucson Overview Intermediate representations span the gap between the source and target languages: closer to target language;

More information

Intermediate Representations

Intermediate Representations Intermediate Representations A variety of intermediate representations are used in compilers Most common intermediate representations are: Abstract Syntax Tree Directed Acyclic Graph (DAG) Three-Address

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Intermediate codes are machine independent codes, but they are close to machine instructions The given program in a source language is converted to an equivalent program in

More information

Compiler Theory. (Intermediate Code Generation Abstract S yntax + 3 Address Code)

Compiler Theory. (Intermediate Code Generation Abstract S yntax + 3 Address Code) Compiler Theory (Intermediate Code Generation Abstract S yntax + 3 Address Code) 006 Why intermediate code? Details of the source language are confined to the frontend (analysis phase) of a compiler, while

More information

Principles of Compiler Design

Principles of Compiler Design Principles of Compiler Design Intermediate Representation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Unambiguous Program representation

More information

CSCI Compiler Design

CSCI 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 information

Compiler. --- Intermediate Code Generation. Zhang Zhizheng.

Compiler. --- Intermediate Code Generation. Zhang Zhizheng. Compiler --- Intermediate Code Generation Zhang Zhizheng seu_zzz@seu.edu.cn School of Computer Science and Engineering, Software College Southeast University 2013/12/12 Zhang Zhizheng, Southeast University

More information

Semantic Analysis computes additional information related to the meaning of the program once the syntactic structure is known.

Semantic 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 information

Computer 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 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 information

Intermediate Representations

Intermediate Representations Compiler Design 1 Intermediate Representations Compiler Design 2 Front End & Back End The portion of the compiler that does scanning, parsing and static semantic analysis is called the front-end. The translation

More information

Gujarat 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 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 information

Syntax-Directed Translation. Concepts Introduced in Chapter 5. Syntax-Directed Definitions

Syntax-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 information

COMPILER CONSTRUCTION (Intermediate Code: three address, control flow)

COMPILER CONSTRUCTION (Intermediate Code: three address, control flow) COMPILER CONSTRUCTION (Intermediate Code: three address, control flow) Prof. K R Chowdhary Email: kr.chowdhary@jietjodhpur.ac.in Campus Director, JIET, Jodhpur Thursday 18 th October, 2018 kr chowdhary

More information

Syntax-Directed Translation

Syntax-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 information

LECTURE 17. Expressions and Assignment

LECTURE 17. Expressions and Assignment LECTURE 17 Expressions and Assignment EXPRESSION SYNTAX An expression consists of An atomic object, e.g. number or variable. An operator (or function) applied to a collection of operands (or arguments)

More information

VALLIAMMAI ENGINEERING COLLEGE

VALLIAMMAI ENGINEERING COLLEGE VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur 60 20 DEPARTMENT OF INFORMATION TECHNOLOGY QUESTION BANK VI SEMESTER CS6660 COMPILER DESIGN Regulation 20 Academic Year 207 8 Prepared by Ms. S.

More information

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall Announcements Weekly team meetings starting today Wednesday (4/4) will be a workshop Wednesday - Post questions you'd like addressed

More information

Languages and Compiler Design II IR Code Generation I

Languages and Compiler Design II IR Code Generation I Languages and Compiler Design II IR Code Generation I Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring 2010 rev.: 4/16/2010 PSU CS322 HM 1 Agenda Grammar G1

More information

Compilers. 5. Attributed Grammars. Laszlo Böszörmenyi Compilers Attributed Grammars - 1

Compilers. 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 information

Syntax-Directed Translation Part II

Syntax-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 information

CSc 453. Compilers and Systems Software. 13 : Intermediate Code I. Department of Computer Science University of Arizona

CSc 453. Compilers and Systems Software. 13 : Intermediate Code I. Department of Computer Science University of Arizona CSc 453 Compilers and Systems Software 13 : Intermediate Code I Department of Computer Science University of Arizona collberg@gmail.com Copyright c 2009 Christian Collberg Introduction Compiler Phases

More information

Alternatives for semantic processing

Alternatives for semantic processing Semantic Processing Copyright c 2000 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided that copies

More information

CMPT 379 Compilers. Anoop Sarkar. 11/13/07 1. TAC: Intermediate Representation. Language + Machine Independent TAC

CMPT 379 Compilers. Anoop Sarkar.  11/13/07 1. TAC: Intermediate Representation. Language + Machine Independent TAC CMPT 379 Compilers Anoop Sarkar http://www.cs.sfu.ca/~anoop 11/13/07 1 TAC: Intermediate Representation Language Specific Language + Machine Independent Machine Dependent Front End AST Intermediate Code

More information

Formal Languages and Compilers Lecture IX Semantic Analysis: Type Chec. Type Checking & Symbol Table

Formal 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 information

1. (a) What are the closure properties of Regular sets? Explain. (b) Briefly explain the logical phases of a compiler model. [8+8]

1. (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 information

Functional Programming. Pure Functional Programming

Functional Programming. Pure Functional Programming Functional Programming Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends only on the values of its sub-expressions (if any).

More information

Intermediate representation

Intermediate representation Intermediate representation Goals: encode knowledge about the program facilitate analysis facilitate retargeting facilitate optimization scanning parsing HIR semantic analysis HIR intermediate code gen.

More information

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-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 information

LECTURE NOTES ON COMPILER DESIGN P a g e 2

LECTURE NOTES ON COMPILER DESIGN P a g e 2 LECTURE NOTES ON COMPILER DESIGN P a g e 1 (PCCS4305) COMPILER DESIGN KISHORE KUMAR SAHU SR. LECTURER, DEPARTMENT OF INFORMATION TECHNOLOGY ROLAND INSTITUTE OF TECHNOLOGY, BERHAMPUR LECTURE NOTES ON COMPILER

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Basic Approach and Application to Assignment and xpressions Array xpressions Boolean xpressions Copyright 2017, Pedro C. Diniz, all rights reserved. Students enrolled in the

More information

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 20 Intermediate code generation Part-4 Run-time environments

More information

Semantic Analysis and Intermediate Code Generation

Semantic Analysis and Intermediate Code Generation DDD55 Compilers and Interpreters DDB44 Compiler Construction Semantic Analysis and Intermediate Code Generation Semantic Analysis and Intermediate Code Generation able management source program Lexical

More information

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules.

Type Checking. Outline. General properties of type systems. Types in programming languages. Notation for type rules. Outline Type Checking General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time

More information

Intermediate-Code Generat ion

Intermediate-Code Generat ion Chapter 6 Intermediate-Code Generat ion In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates

More information

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http://www.cse.buffalo.edu/faculty/alphonce/sp17/cse443/index.php https://piazza.com/class/iybn4ndqa1s3ei shift/reduce conflict with

More information

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http://www.cse.buffalo.edu/faculty/alphonce/sp17/cse443/index.php https://piazza.com/class/iybn4ndqa1s3ei Announcements Be sure to

More information

Midterm Solutions COMS W4115 Programming Languages and Translators Wednesday, March 25, :10-5:25pm, 309 Havemeyer

Midterm Solutions COMS W4115 Programming Languages and Translators Wednesday, March 25, :10-5:25pm, 309 Havemeyer Department of Computer cience Columbia University Midterm olutions COM W4115 Programming Languages and Translators Wednesday, March 25, 2009 4:10-5:25pm, 309 Havemeyer Closed book, no aids. ach question

More information

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference

Outline. General properties of type systems. Types in programming languages. Notation for type rules. Common type rules. Logical rules of inference Type Checking Outline General properties of type systems Types in programming languages Notation for type rules Logical rules of inference Common type rules 2 Static Checking Refers to the compile-time

More information

CSCI565 Compiler Design

CSCI565 Compiler Design CSCI565 Compiler Design Spring 2015 Homework 2 - Solution Problem 1: Attributive Grammar and Syntax-Directed Translation [25 points] Conser the grammar fragment below. It allows for the declaration of

More information

5. Syntax-Directed Definitions & Type Analysis

5. 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

IR Lowering. Notation. Lowering Methodology. Nested Expressions. Nested Statements CS412/CS413. Introduction to Compilers Tim Teitelbaum

IR Lowering. Notation. Lowering Methodology. Nested Expressions. Nested Statements CS412/CS413. Introduction to Compilers Tim Teitelbaum IR Lowering CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 19: Efficient IL Lowering 7 March 07 Use temporary variables for the translation Temporary variables in the Low IR store intermediate

More information

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002 University of Arizona, Department of Computer Science CSc 453 Assignment 5 Due 23:59, Dec 4 100 points Christian Collberg November 19, 2002 1 Introduction Your task is to write a code generator for the

More information

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End

More information

Code No: R Set No. 1

Code No: R Set No. 1 Code No: R05010106 Set No. 1 1. (a) Draw a Flowchart for the following The average score for 3 tests has to be greater than 80 for a candidate to qualify for the interview. Representing the conditional

More information

ECS 142 Project: Code generation hints (2)

ECS 142 Project: Code generation hints (2) ECS 142 Project: Code generation hints (2) Winter 2011 This document describes the nature of final code generation for your project. I have made a number of assumptions here, mostly in terms of availability

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Basic Approach and Application to Assignment and xpressions Array xpressions Boolean xpressions Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Control-Flow tatements hort-circuit Predicate valuation Back-Patching Copyright 2015, Pedro C. Diniz, all rights reserved. tudents enrolled in the Compilers class at the University

More information

2.2 Syntax Definition

2.2 Syntax Definition 42 CHAPTER 2. A SIMPLE SYNTAX-DIRECTED TRANSLATOR sequence of "three-address" instructions; a more complete example appears in Fig. 2.2. This form of intermediate code takes its name from instructions

More information

SEM / YEAR : VI / III CS2352 PRINCIPLES OF COMPLIERS DESIGN UNIT I - LEXICAL ANALYSIS PART - A

SEM / YEAR : VI / III CS2352 PRINCIPLES OF COMPLIERS DESIGN UNIT I - LEXICAL ANALYSIS PART - A SEM / YEAR : VI / III CS2352 PRINCIPLES OF COMPLIERS DESIGN UNIT I - LEXICAL ANALYSIS PART - A 1. What is a compiler? (A.U Nov/Dec 2007) A compiler is a program that reads a program written in one language

More information

Compilerconstructie. najaar Rudy van Vliet kamer 140 Snellius, tel rvvliet(at)liacs(dot)nl. college 7, vrijdag 2 november 2018

Compilerconstructie. najaar Rudy van Vliet kamer 140 Snellius, tel rvvliet(at)liacs(dot)nl. college 7, vrijdag 2 november 2018 Compilerconstructie najaar 2018 http://www.liacs.leidenuniv.nl/~vlietrvan1/coco/ Rudy van Vliet kamer 140 Snellius, tel. 071-527 2876 rvvliet(at)liacs(dot)nl college 7, vrijdag 2 november 2018 + werkcollege

More information

CS415 Compilers. Intermediate Represeation & Code Generation

CS415 Compilers. Intermediate Represeation & Code Generation CS415 Compilers Intermediate Represeation & Code Generation These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Review - Types of Intermediate Representations

More information

VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY

VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY VETRI VINAYAHA COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING CS6660 COMPILER DESIGN III year/ VI sem CSE (Regulation 2013) UNIT I -INTRODUCTION TO COMPILER PART A

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation Control-Flow tatements hort-circuit Predicate valuation Back-Patching Copyright 2011, Pedro C. Diniz, all rights reserved. tudents enrolled in the Compilers class at the University

More information

Intermediate Representations

Intermediate Representations Most of the material in this lecture comes from Chapter 5 of EaC2 Intermediate Representations Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP

More information

Syntax-Directed Translation

Syntax-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 information

COMPILER DESIGN. Intermediate representations Introduction to code generation. COMP 442/6421 Compiler Design

COMPILER DESIGN. Intermediate representations Introduction to code generation. COMP 442/6421 Compiler Design 1 COMPILER DESIGN Intermediate representations Introduction to code generation Concordia University Introduction to code generation 2 Front end: Lexical Analysis Syntactic Analysis Intermediate Code/Representation

More information

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation

Comp 204: Computer Systems and Their Implementation. Lecture 22: Code Generation and Optimisation Comp 204: Computer Systems and Their Implementation Lecture 22: Code Generation and Optimisation 1 Today Code generation Three address code Code optimisation Techniques Classification of optimisations

More information

Intermediate Representa.on

Intermediate Representa.on IR Intermediate Representa.on CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilers-class Intermediate Representation Language Specific Language + Machine Independent Machine Dependent

More information

Compilers. Intermediate representations and code generation. Yannis Smaragdakis, U. Athens (original slides by Sam

Compilers. Intermediate representations and code generation. Yannis Smaragdakis, U. Athens (original slides by Sam Compilers Intermediate representations and code generation Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Today Intermediate representations and code generation Scanner Parser Semantic

More information

CS5363 Final Review. cs5363 1

CS5363 Final Review. cs5363 1 CS5363 Final Review cs5363 1 Programming language implementation Programming languages Tools for describing data and algorithms Instructing machines what to do Communicate between computers and programmers

More information

SYNTAX DIRECTED TRANSLATION FOR CONTROL STRUCTURES

SYNTAX DIRECTED TRANSLATION FOR CONTROL STRUCTURES UNIT 3 SYNTAX DIRECTED TRANSLATION FOR CONTROL STRUCTURES M.B.Chandak www.mbchandak.com hodcs@rknec.edu CONTROL STRUCTURES 1. If (condition) then Statement 2. If (condition) then Statement 1 else statement

More information