Compiler. --- Intermediate Code Generation. Zhang Zhizheng.
|
|
- Jordan Booth
- 6 years ago
- Views:
Transcription
1 Compiler --- Intermediate Code Generation Zhang Zhizheng School of Computer Science and Engineering, Software College Southeast University 2013/12/12 Zhang Zhizheng, Southeast University 1
2 Role I 2013/12/12 Zhang Zhizheng, Southeast University 2
3 Role II 2013/12/12 Zhang Zhizheng, Southeast University 3
4 Why Use Intermediate code Facilitate Portability Facilitate Opertimization E E1 Digit has E.val=E1.val Digit.val Digit.type=E1.type E.code=E1.code Digit.code 2013/12/12 Zhang Zhizheng, Southeast University 4
5 How to implement Utilize semantics rule to evaluate the code attribute E E1 Digit has E.val=E1.val Digit.val Digit.type=E1.type E.code=E1.code Digit.code 2013/12/12 Zhang Zhizheng, Southeast University 5
6 Example 2013/12/12 Zhang Zhizheng, Southeast University 6
7 Intermediate Representation: Three address code 2013/12/12 Zhang Zhizheng, Southeast University 7
8 2013/12/12 Zhang Zhizheng, Southeast University 8
9 2013/12/12 Zhang Zhizheng, Southeast University 9
10 2013/12/12 Zhang Zhizheng, Southeast University 10
11 Data Structure of Three Address Code I Quadruples 2013/12/12 Zhang Zhizheng, Southeast University 11
12 Data Structure of Three Address Code I Example 2013/12/12 Zhang Zhizheng, Southeast University 12
13 Data Structure of Three Address Code II Triples 2013/12/12 Zhang Zhizheng, Southeast University 13
14 Data Structure of Three Address Code III Indirect Triples 2013/12/12 Zhang Zhizheng, Southeast University 14
15 Data Structure of Three Address Code I Example 2013/12/12 Zhang Zhizheng, Southeast University 15
16 Translation of common statements I Expression 2013/12/12 Zhang Zhizheng, Southeast University 16
17 Translation of common statements I Example 2013/12/12 Zhang Zhizheng, Southeast University 17
18 Translation of common statements II Array 2013/12/12 Zhang Zhizheng, Southeast University 18
19 Translation of common statements II Example 2013/12/12 Zhang Zhizheng, Southeast University 19
20 Translation of common statements II Example (Cont.) 2013/12/12 Zhang Zhizheng, Southeast University 20
21 Translation of common statements III Flow-of-Control statements 2013/12/12 Zhang Zhizheng, Southeast University 21
22 Translation of common statements III Coding Approaches Two ways: 1)Short Circuit(Jumping) codes, where.code is managed as inherited attribute. 2)Backpatching codes, where.code is managed as synthesized attribute. 2013/12/12 Zhang Zhizheng, Southeast University 22
23 Translation of common statements III Short Circuit Encoding I 1 For Boolean Expression 2013/12/12 Zhang Zhizheng, Southeast University 23
24 Translation of common statements III Short Circuit Encoding I 1 For Boolean Expression Example iffalse is allowed iffalse is not allowed 2013/12/12 Zhang Zhizheng, Southeast University 24
25 Translation of common statements III Short Circuit Encoding II 2 For Flow Control 2013/12/12 Zhang Zhizheng, Southeast University 25
26 Translation of common statements III Short Circuit Encoding II 2 For Flow Control example iffalse is not allowed 2013/12/12 Zhang Zhizheng, Southeast University 26
27 Translation of common statements III Short Circuit Encoding III 3 Semantics Rules 2013/12/12 Zhang Zhizheng, Southeast University 27
28 2013/12/12 Zhang Zhizheng, Southeast University 28
29 2013/12/12 Zhang Zhizheng, Southeast University 29
30 Case Analysis i=0; tag=0; while (tag==0 && i<=10) do { j=1; while (tag==0 && j<=10) do if (a[i,j]==x) tag=1; else j=j+1; if (tag==0) i=i+1 } 2013/12/12 Zhang Zhizheng, Southeast University 30
31 i=1 tag=0 L1: if (tag==0) goto L2 goto L3 L2: if (i<=10) goto L4 goto L3 L4: j=1 L5: if (tag==0) goto L6 goto L7 L6: if (j<=10) goto L8 goto L7 L8: t1=addra-11 t2=i*10 t3=t2+j t4=t1[t3] if (t4==x) goto L9 goto L10 L9: tag=1 goto L11 L10: t5=j+1 j=t5 L11: goto L5 L7: if (tag==0) goto L12 goto L13 L12: t6=i+1 i=t6 L13: goto L1 L3: Jumping codes
32 (1) (=,0,_,i) (2) (=,0,_,tag) (3) (j==,tag,0,(5)) (4) (j,_,_,0(28)) (5) (j<=,i,10,(7)) (6) (j,_,_,4(28)) (7) (=,1,_,j) (8) (j==,tag,0,(10)) (9) (j,_,_,0(23)) (10) (j<=,j,10,(12)) (11) (j,_,_,9(23)) (12) (-,addra,11,t1) (13) (*,i,10,t2) (14) (+,t2,j,t3) (15) (=[],t1[t3],_,t4) (16) (j==,t4,x,(18)) (17) (j,_,_,(20)) (18) (=,1,_,tag) (19) (j,_,_,(22)) (20) (+,j,1,t5) (21) (=,t5,_,j) (22) (j,_,_,(8)) (23) (j==,tag,0,(25)) (24) (j,_,_,(27)) (25) (+,i,1,t6) (26) (=,t6,_,i) (27) (j,_,_,(3)) (28) Backpatch ing
33 Written Assignment Please translate the following program fragment into threeaddress code using the form of short circuit code. i=2; loop=0; while (loop==0 && i<=10) { j=1; while (loop ==0 && j<i) if (a[i,j] == x) loop=1; else j=j+1; if (loop==0) i=i+1; } Notes: Here we assume that the declaration of array A is array [1..10,1..10], each data element of array A would use 2 storage units, and the start address of array A s storage area is addra. 33
34 Appendix Backpatching 1.Why and what is backpatching? When generating code for boolean expressions and flowof-control statements, we may not know the labels that control must go to. We can get around this problem by generating a series of branching statement with the targets of the jumps temporarily left unspecified. Each such statement will be put on a list of goto statements whose labels will be filled in when the proper label can be determined. This subsequent filling in of labels is called backpatching
35 2.Functions to manipulate lists of labels related to backpatching Makelist(i) Creates a new list containing only i, an index into the array of quadruples; makelist returns a pointer to the list it has made. Merge(p1,p2) Concatenates the lists pointed to by p1 and p2, and returns a pointer to the concatenated list. Backpatch(p,i) Inserts i as the target label for each of the statements on the list pointed to by p.
36 3.Boolean expression 1)Modify the grammar E E A E E 0 E not E (E) i E a rop E a E A E and E 0 E or 2)Semantic Rules (1) E i {E TC=NXQ; E FC=NXQ+1; GEN(jnz,ENTRY(i),_,0); GEN(j,_,_,0)}
37 3.Boolean expression 2)Semantic Rules (2) E E a rop E a {E TC=NXQ; E FC=NXQ+1; GEN(jrop, E a (1) PLACE, E a (2) PLACE,0); GEN(j,_,_,0)} (3) E (E (1) ) {E TC= E (1) TC; E FC= E (1) FC} (4) E not E (1) {E TC= E (1) FC; E FC= E (1) TC}
38 3.Boolean expression 2)Semantic Rules (5)E A E (1) and {BACKPATCH(E (1) TC,NXQ); (6) E E A E (2) E A FC= E (1) FC;} {E TC= E (2) TC; E FC=MERG(E A FC,E (2) FC}
39 3.Boolean expression 2)Semantic Rules (7)E 0 E (1) or (8) E E 0 E (2) {BACKPATCH(E (1) FC,NXQ); E 0 TC= E (1) TC;} {E FC= E (2) FC; E TC=MERG(E 0 TC,E (2) TC}
40 Translate A and B or not C INPUT SYM TC FC quadruple A and B or not C# # - - and B or not C# #i and B or not C# #E (jnz,a,-,(3)) B or not C# #E and (j,-,-(5)) B or not C# # E A or not C# # E A i
41 INPUT or not C # or not C# or not C# not C# C# # # # # success SYM # E A E #E #E or # E 0 # E 0 not # E 0 not i # E 0 note # E 0 E #E TC FC quadruple 3.(jnz,B,-,0) 4.(j,-,-(5)) 5.(jnz,C,-,0) 6.(j,-,-,3)
42 4.Flow of control statements 1) modify the grammar S if E then S (1) else S (2) C if E then T C S (1) else S T S (2) S if E then S (1) C if E then S C S (1)
43 4.Flow of control statements 2) Semantic Rules C if E then {BACKPATCH(E TC,NXQ); C CHAIN=E FC;} T C S (1) else {q=nxq; GEN(j,-,-0); BACKPATCH(C CHAIN,NXQ); T CHAIN=MERG(S (1) CHAIN,q)} S T S (2) {S CHAIN=MERG(T CHAIN,S (2) CHAIN)} S C S (1) {S CHAIN=MERG(C CHAIN,S (1) CHAIN)}
44 e.g. If a then if b then A:=2 else A:=3 Else if c then A=4 Else a=5 (1) (jnz,a,_,0) (2) (j,_,_,0)
45 If a then if b then A:=2 else A:=3 Else if c then A=4 Else a=5 (1)(jnz,a,_,(3)) (2)(j,_,_,0) (3)(jnz,b,_,0) (4)(j,_,_,0) Ca CHAIN->2
46 If a then if b then A:=2 else A:=3 Else if c then A=4 Else a=5 (1)(jnz,a,_,(3)) (2)(j,_,_,0) (3)(jnz,b,_,(5)) (4)(j,_,_,0) (5)(:=,2,_,A) Ca CHAIN->2 Cb CHAIN->4
47 If a then if b then A:=2 else A:=3 Else if c then A=4 Else a=5 (1)(jnz,a,_,(3)) (2)(j,_,_,0) (3)(jnz,b,_,(5)) (4)(j,_,_,(7)) (5)(:=,2,_,A) (6)(j,_,_,0) Ca CHAIN->2 Cb CHAIN->6
48 Answer (1)(jnz,a,_,(3)) (2)(j,_,_,(9)) (3)(jnz,b,_,(5)) (4)(j,_,_,(7)) (5)(:=,2,_,A) (6)(j,_,_,0) (7)(:=,3,_,A) (8)(j,_,_,6) (9)(jnz,c,_,(11)) (10)(j,_,_,(13)) (11)(:=,4,_,A) (12)(j,_,_,8) (13)(:=,5,_,A) S CHAIN->6->8->12
49 1,2 a 3,4 b 6 5 S1(A:=2) 8 7 9,10 S2(A:=3) c TRUE FALSE S3(A:=4) 13 S4(A:=5)
50 4.Flow of control statements 3) While statement S while E do S (1) W while W d W E do S W d S (1)
51 4.flow of control statements 3) While statement W while {W QUAD=NXQ} W d W E do {BACKPATCH(E TC,NXQ); W d CHAIN=E FC; W d QUAD=W QUAD;} S W d S (1) {BACKPATCH(S (1) CHAIN, W d QUAD); GEN(j,_,_, W d QUAD); S CHAIN= W d CHAIN}
52 4.flow of control statements 3) While statement Code of E Code of S (1) S.CHAIN
53 e.g. While (A<B) do if (C<D) then X:=Y+Z; (100) (j<,a,b,0) (101)(j,_,_,0)
54 e.g. While (A<B) do if (C<D) then X:=Y+Z; : (100) (j<,a,b,(102)) (101)(j,_,_,0) (102)(j<,C,D,0) (103)(j,_,_,(100))
55 e.g. While (A<B) do if (C<D) then X:=Y+Z; : (100) (j<,a,b,(102)) (101)(j,_,_,0) (102)(j<,C,D,(104)) (103)(j,_,_,(100)) (104)(+,Y,Z,T 1 ) (105)(:=, T 1,_,X)
56 e.g. While (A<B) do if (C<D) then X:=Y+Z; : (100) (j<,a,b,(102)) (106)(j,_,_,(100)) (101)(j,_,_,(107)) (102)(j<,C,D,(104)) (103)(j,_,_,(100)) (104)(+,Y,Z,T 1 ) (105)(:=, T 1,_,X)
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 informationChapter 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 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 informationModule 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 informationPrinciple 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 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 informationCSE443 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 informationCMPT 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 informationPSD3A 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 informationIntermediate Code Generation Part II
1 Intermediate Code Generation Part II Chapter 6 (1 st ed Chapter 8) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2009 2 Advanced Intermediate Code Generation
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 informationIntermediate 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 informationControl 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 informationIntermediate 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 informationCSc 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 informationCS2210: 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 informationIntermediate 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 informationFormal 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 informationCSE443 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 informationConcepts 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 informationCompiler 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 informationCompilerconstructie. 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 informationThe 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 informationIntermediate 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 informationintermediate-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 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 Compiler Architecture Source language Scanner (lexical analysis) tokens Parser (syntax
More informationDixita 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 informationCMPSC 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 informationTHEORY 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 informationIntermediate Code Generation
Intermediate Code Generation Translating source program into an intermediate language. Simple CPU Indepent, yet, close in spirit to machine language. Three Address Code (quadruples) Two Address Code, etc.
More informationConcepts 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 informationDEPARTMENT 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 informationPrinciple 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 informationAcknowledgement. 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 informationIntermediate 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 informationIR 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 informationIntermediate 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 informationCS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 19: Efficient IL Lowering 5 March 08
CS412/CS413 Introduction to Compilers Tim Teitelbaum Lecture 19: Efficient IL Lowering 5 March 08 CS 412/413 Spring 2008 Introduction to Compilers 1 IR Lowering Use temporary variables for the translation
More informationCode optimization. Have we achieved optimal code? Impossible to answer! We make improvements to the code. Aim: faster code and/or less space
Code optimization Have we achieved optimal code? Impossible to answer! We make improvements to the code Aim: faster code and/or less space Types of optimization machine-independent In source code or internal
More informationVIVA 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 informationPRINCIPLES 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 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 informationLanguages 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 informationCode Generation. CS 1622: Code Generation & Register Allocation. Arrays. Why is Code Generation Hard? Multidimensional Arrays. Array Element Address
Code Generation CS 1622: Code Generation & Register Allocation Input: Intermediate representation Output: Target code Example: cond_expr if-statement stmt_list L1: slti $t1, 3, $s0 beq $t1, $zero, L1 addi
More informationIntermediate 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 informationFinal Exam Review Questions
EECS 665 Final Exam Review Questions 1. Give the three-address code (like the quadruples in the csem assignment) that could be emitted to translate the following assignment statement. However, you may
More informationCSCE 531, Spring 2015 Final Exam Answer Key
CSCE 531, Spring 2015 Final Exam Answer Key 1. (40 points total) Consider the following grammar with start symbol S : S S S asb S T T T a T cs T ɛ (a) (10 points) Find FIRST(S), FIRST(T ), FOLLOW(S), and
More informationComp 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 informationObject Code (Machine Code) Dr. D. M. Akbar Hussain Department of Software Engineering & Media Technology. Three Address Code
Code Generation Intermediate Code? Assembly Code Object Code (Machine Code) 1 Intermediate Code P-Code Three Address Code 2 Compiler Construction F6S 1 Intermediate Representation Abstract Syntax Tree
More informationType 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 informationSemantic Actions and 3-Address Code Generation
Compiler Design 1 Semantic Actions and 3-Address Code Generation Compiler Design 2 Introduction We start with different constructs of the given grammar (laboratory assignment-5) and discuss semantic actions
More informationOutline. 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 informationIntermediate Representations
Intermediate Representations Intermediate Representations (EaC Chaper 5) Source Code Front End IR Middle End IR Back End Target Code Front end - produces an intermediate representation (IR) Middle end
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 informationLECTURE 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 informationIntermediate 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 informationGenerating 3-Address Code from an Attribute Grammar
Generating 3-Address Code from an Attribute Grammar Here is a small but realistic programming language with integer and boolean data, loops and conditionals, procedures with no arguments that compute but
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 informationIntermediate 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 informationCS322 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 information1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail.
Code No: R05320502 Set No. 1 1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail. 2. Construct predictive parsing
More informationVALLIAMMAI 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 informationCSCI565 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 informationCSE443 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 informationIntermediate Code Generation
Intermediate Code Generation Front-end intermediate code generation source program Lexical Analyzer Syntax Analyzer Semantic Analyzer Int. Code Generator intermediate representation Symbol Table Advantages
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 informationCSc 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 informationModule 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 informationCS 432 Fall Mike Lam, Professor. Code Generation
CS 432 Fall 2015 Mike Lam, Professor Code Generation Compilers "Back end" Source code Tokens Syntax tree Machine code char data[20]; int main() { float x = 42.0; return 7; } 7f 45 4c 46 01 01 01 00 00
More informationFall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev
Fall 2015-2016 Compiler Principles Lecture 6: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation
More informationKINGS COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ACADEMIC YEAR / EVEN SEMESTER
KINGS COLLEGE OF ENGINEERING PUNALKULAM DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING ACADEMIC YEAR 2010-2011 / EVEN SEMESTER SUBJECT CODE\SUBJECT NAME: CS1352 \ PRINCIPLES OF COMPILER DESIGN QUESTION BANK
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 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 informationTheory of Compilation Erez Petrank. Lecture 7: Intermediate Representation Part 2: Backpatching
Theory of Compilation 236360 rez Petrank Lecture 7: Intermediate Representation Part 2: ackpatching 1 You are here Compiler Source text txt Lexical Analysis Syntax Analysis Semantic Analysis Inter. Rep.
More informationRoll No. :... Invigilator's Signature :. CS/B.Tech(CSE)/SEM-7/CS-701/ LANGUAGE PROCESSOR. Time Allotted : 3 Hours Full Marks : 70
Name : Roll No. :... Invigilator's Signature :. CS/B.Tech(CSE)/SEM-7/CS-701/2011-12 2011 LANGUAGE PROCESSOR Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates
More informationCopyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit
Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make copies
More informationCS 314 Principles of Programming Languages
CS 314 Principles of Programming Languages Lecture 2: Syntax Analysis Zheng (Eddy) Zhang Rutgers University January 22, 2018 Announcement First recitation starts this Wednesday Homework 1 will be release
More informationTime : 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 informationUNIT 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 informationExpressions vs statements
Expressions vs statements Every expression results in a value (+side-effects?): 1+2, str.length(), f(x)+1 Imperative prg: Statements have just side-effects, no value: (for, if, break) Assignment is statement/expression
More informationProgramming Fundamentals - A Modular Structured Approach using C++ By: Kenneth Leroy Busbee
1 0 1 0 Foundation Topics 1 0 Chapter 1 - Introduction to Programming 1 1 Systems Development Life Cycle N/A N/A N/A N/A N/A N/A 1-8 12-13 1 2 Bloodshed Dev-C++ 5 Compiler/IDE N/A N/A N/A N/A N/A N/A N/A
More informationC-LANGUAGE CURRICULAM
C-LANGUAGE CURRICULAM Duration: 2 Months. 1. Introducing C 1.1 History of C Origin Standardization C-Based Languages 1.2 Strengths and Weaknesses Of C Strengths Weaknesses Effective Use of C 2. C Fundamentals
More informationSRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTER SCIENCE AND ENGINEERING COURSE PLAN
SRM UNIVERSITY FACULTY OF ENGINEERING AND TECHNOLOGY SCHOOL OF COMPUTER SCIENCE AND ENGINEERING COURSE PLAN Course Code : CS1014 Semester: VI Course Title : System Software and Compiler Design Course Time:
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 informationCS 314 Principles of Programming Languages. Lecture 3
CS 314 Principles of Programming Languages Lecture 3 Zheng Zhang Department of Computer Science Rutgers University Wednesday 14 th September, 2016 Zheng Zhang 1 CS@Rutgers University Class Information
More informationCMSC 430 Introduction to Compilers. Spring Intermediate Representations and Bytecode Formats
CMSC 430 Introduction to Compilers Spring 2016 Intermediate Representations and Bytecode Formats Introduction Front end Source code Lexer Parser Types AST/IR IR 2 IR n IR n.s Middle end Back end Front
More informationLecture Notes on Intermediate Representation
Lecture Notes on Intermediate Representation 15-411: Compiler Design Frank Pfenning Lecture 10 September 26, 2013 1 Introduction In this lecture we discuss the middle end of the compiler. After the source
More informationSemantic 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 informationIntermediate-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 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 informationLecture Notes on Intermediate Representation
Lecture Notes on Intermediate Representation 15-411: Compiler Design Frank Pfenning Lecture 9 September 24, 2009 1 Introduction In this lecture we discuss the middle end of the compiler. After the source
More informationΕΠΛ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 informationAlternatives 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 informationLecture Notes on Intermediate Representation
Lecture Notes on Intermediate Representation 15-411: Compiler Design Frank Pfenning Lecture 10 September 23, 2010 1 Introduction In this lecture we discuss the middle end of the compiler. After the source
More informationTest 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B.
CSE 3302 Test 1 1. Preprocessor macros are associated with: A. C B. Java C. JavaScript D. Pascal 2. (define x (lambda (y z) (+ y z))) is an example of: A. Applying an anonymous function B. Defining a function
More informationIntermediate 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 informationFall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev
Fall 2016-2017 Compiler Principles Lecture 5: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation
More informationCOMPILER 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 informationBoolean Expressions. Lecture 31 Sections 6.6, 6.7. Robb T. Koether. Hampden-Sydney College. Wed, Apr 8, 2015
Boolean Expressions Lecture 31 Sections 6.6, 6.7 Robb T. Koether Hampden-Sydney College Wed, Apr 8, 2015 Robb T. Koether (Hampden-Sydney College) Boolean Expressions Wed, Apr 8, 2015 1 / 22 1 Relational
More informationPage No 1 (Please look at the next page )
Salman Bin Abdul Aziz University Collage of Computer Engineering and Sciences Computer Science Department 1433-1434 (2012-2013) First Term CS 4300 Compiler Construction 8 th Level Final Exam 120 Minutes
More information