Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

Size: px
Start display at page:

Download "Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev"

Transcription

1 Fall Compiler Principles Lecture 5: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev

2 Tentative syllabus Front End Intermediate Representation Optimizations Code Generation Scanning Operational Semantics Dataflow Analysis Register Allocation Top-down Parsing (LL) Lowering Loop Optimizations Energy Optimization Bottom-up Parsing (LR) Instruction Selection mid-term exam 2

3 Previously Becoming parsing ninjas Going from text to an Abstract Syntax Tree By Admiral Ham [GFDL ( or CC-BY-SA-3.0 ( via Wikimedia Commons 3

4 From scanning to parsing program text 59 + (1257 * xposition) Lexical Analyzer token stream num + ( num * id ) Grammar: E id E num E E + E E E * E E ( E ) syntax error + Parser valid Abstract Syntax Tree num * num x 4

5 Agenda The role of intermediate representations Two example languages A high-level language An intermediate language Lowering Correctness Formal meaning of programs 5

6 Role of intermediate representation Bridge between front-end and back-end High-level Language Lexical Analysis Syntax Analysis Parsing AST Symbol Table etc. Inter. Rep. (IR) Code Generation Executable Code (scheme) Allow implementing optimizations independent of source language and executable (target) language 6

7 Motivation for intermediate representation 7

8 Intermediate representation A language that is between the source language and the target language Not specific to any source language or machine language Goal 1: retargeting compiler components for different source languages/target machines Java Pentium C++ IR Java bytecode Pyhton Sparc 8

9 Intermediate representation A language that is between the source language and the target language Not specific to any source language or machine language Goal 1: retargeting compiler components for different source languages/target machines Goal 2: machine-independent optimizer Narrow interface: small number of node types (instructions) Lowering Code Gen. Java optimize Pentium C++ IR Java bytecode Pyhton Sparc 9

10 Multiple IRs Some optimizations require high-level constructs while others more appropriate on low-level code Solution: use multiple IR stages optimize optimize Pentium AST HIR LIR Java bytecode Sparc 10

11 Multiple IRs example Elixir a language for parallel graph algorithms Elixir Program Delta Inferencer Query Answer Automated Reasoning (Boogie+Z3) Elixir Program + delta HIR Lowering HIR IL Synthesizer Planning Problem Plan Automated Planner LIR C++ backend C++ code Galois Library 11

12 AST vs. LIR for imperative languages AST Rich set of language constructs Rich type system Declarations: types (classes, interfaces), functions, variables Control flow statements: ifthen-else, while-do, breakcontinue, switch, exceptions Data statements: assignments, array access, field access Expressions: variables, constants, arithmetic operators, logical operators, function calls LIR An abstract machine language Very limited type system Only computation-related code Labels and conditional/ unconditional jumps, no looping Data movements, generic memory access statements No sub-expressions, logical as numeric, temporaries, constants, function calls explicit argument passing 12

13 three address code 13

14 Three-Address Code IR A popular form of IR High-level assembly where instructions have at most three operands Chapter 8 There exist other types of IR For example, IR based on acyclic graphs more amenable for analysis and optimizations 14

15 Base language: While 15

16 Syntax n Num x Var numerals program variables A n x A ArithOp A (A) ArithOp - + * / B true false A = A A A B B B (B) S x := A skip S; S { S } if B then S else S while B S 16

17 Example program while x < y { { x := x + 1 y := x; 17

18 Intermediate language: IL 18

19 Syntax n Num l Num x Temp Var Numerals Labels Temporaries and variables V n x R V Op V Op - + * / = << >> C l: skip l: x := R l: Goto l l: IfZ x Goto l l: IfNZ x Goto l IR C + 19

20 Intermediate language programs An intermediate program P has the form 1:c 1 n:c n We can view it as a map from labels to individual commands and write P(j) = c j 1: t0 := 137 2: y := t : IfZ x Goto 7 4: t1 := y 5: z := t1 6: Goto 9 7: t2 := y 8: x := t2 9: skip 20

21 Lowering 21

22 TAC generation At this stage in compilation, we have an AST annotated with scope information and annotated with type information We generate TAC recursively (bottom-up) First for expressions Then for statements 22

23 TAC generation for expressions Define a function cgen(expr) that generates TAC that: 1. Computes an expression, 2. Stores it in a temporary variable, 3. Returns the name of that temporary Define cgen directly for atomic expressions (constants, this, identifiers, etc.) Define cgen recursively for compound expressions (binary operators, function calls, etc.) 23

24 Translation rules for expressions cgen(n) = (l: t:=n, t) where l and t are fresh cgen(x) = (l: t:=x, t) where l and t are fresh cgen(e 1 ) = (P 1, t 1 ) cgen(e 2 ) = (P 2, t 2 ) cgen(e 1 op e 2 ) = (P 1 P 2 l: t:=t 1 op t 2, t) where l and t are fresh 24

25 cgen for basic expressions Maintain a counter for temporaries in c, and a counter for labels in l Initially: c = 0, l = 0 cgen(k) = { // k is a constant c = c + 1, l = l +1 emit(l: tc := k) return tc { cgen(id) = { // id is an identifier c = c + 1, l = l +1 emit(l: tc := id) return tc { 25

26 Naive cgen for binary expressions cgen(e 1 op e 2 ) = { let A = cgen(e 1 ) let B = cgen(e 2 ) c = c + 1, l = l +1 emit( l: tc := A op B; ) return tc } The translation emits code to evaluate e 1 before e 2. Why is that? 26

27 Example: cgen for binary expressions cgen( (a*b)-d) 27

28 Example: cgen for binary expressions c = 0, l = 0 cgen( (a*b)-d) 28

29 Example: cgen for binary expressions c = 0, l = 0 cgen( (a*b)-d) = { let A = cgen(a*b) let B = cgen(d) c = c + 1, l = l +1 emit(l: tc := A - B; ) return tc } 29

30 Example: cgen for binary expressions c = 0, l = 0 cgen( (a*b)-d) = { let A = { let A = cgen(a) let B = cgen(b) c = c + 1, l = l +1 emit(l: tc := A * B; ) return tc } let B = cgen(d) c = c + 1, l = l +1 emit(l: tc := A - B; ) return tc } 30

31 Example: cgen for binary expressions c = 0, l = 0 cgen( (a*b)-d) = { let A = { here A=t1 let A = {c=c+1, l=l+1, emit(l: tc := a;), return tc } let B = {c=c+1, l=l+1, emit(l: tc := b;), return tc } c = c + 1, l = l +1 emit(l: tc := A * B; ) return tc } let B = {c=c+1, l=l+1, emit(l: tc := d;), return tc } c = c + 1, l = l +1 emit(l: tc := A - B; ) return tc } Code 31

32 Example: cgen for binary expressions c = 0, l = 0 cgen( (a*b)-d) = { let A = { here A=t1 let A = {c=c+1, l=l+1, emit(l: tc := a;), return tc } let B = {c=c+1, l=l+1, emit(l: tc := b;), return tc } c = c + 1, l = l +1 emit(l: tc := A * B; ) return tc } let B = {c=c+1, l=l+1, emit(l: tc := d;), return tc } c = c + 1, l = l +1 emit(l: tc := A - B; ) return tc } Code 1: t1:=a; 32

33 Example: cgen for binary expressions c = 0, l = 0 cgen( (a*b)-d) = { let A = { here A=t1 let A = {c=c+1, l=l+1, emit(l: tc := a;), return tc } let B = {c=c+1, l=l+1, emit(l: tc := b;), return tc } c = c + 1, l = l +1 emit(l: tc := A * B; ) return tc } let B = {c=c+1, l=l+1, emit(l: tc := d;), return tc } c = c + 1, l = l +1 emit(l: tc := A - B; ) return tc } Code 1: t1:=a; 2: t2:=b; 33

34 Example: cgen for binary expressions c = 0, l = 0 cgen( (a*b)-d) = { let A = { here A=t1 let A = {c=c+1, l=l+1, emit(l: tc := a;), return tc } let B = {c=c+1, l=l+1, emit(l: tc := b;), return tc } c = c + 1, l = l +1 emit(l: tc := A * B; ) return tc } let B = {c=c+1, l=l+1, emit(l: tc := d;), return tc } c = c + 1, l = l +1 emit(l: tc := A - B; ) return tc } Code 1: t1:=a; 2: t2:=b; 3: t3:=t1*t2 34

35 Example: cgen for binary expressions c = 0, l = 0 here A=t3 cgen( (a*b)-d) = { let A = { here A=t1 let A = {c=c+1, l=l+1, emit(l: tc := a;), return tc } let B = {c=c+1, l=l+1, emit(l: tc := b;), return tc } c = c + 1, l = l +1 emit(l: tc := A * B; ) return tc } let B = {c=c+1, l=l+1, emit(l: tc := d;), return tc } c = c + 1, l = l +1 emit(l: tc := A - B; ) return tc } Code 1: t1:=a; 2: t2:=b; 3: t3:=t1*t2 35

36 Example: cgen for binary expressions c = 0, l = 0 here A=t3 cgen( (a*b)-d) = { let A = { here A=t1 let A = {c=c+1, l=l+1, emit(l: tc := a;), return tc } let B = {c=c+1, l=l+1, emit(l: tc := b;), return tc } c = c + 1, l = l +1 emit(l: tc := A * B; ) return tc } let B = {c=c+1, l=l+1, emit(l: tc := d;), return tc } c = c + 1, l = l +1 emit(l: tc := A - B; ) return tc } Code 1: t1:=a; 2: t2:=b; 3: t3:=t1*t2 4: t4:=d 36

37 Example: cgen for binary expressions c = 0, l = 0 here A=t3 cgen( (a*b)-d) = { let A = { here A=t1 let A = {c=c+1, l=l+1, emit(l: tc := a;), return tc } let B = {c=c+1, l=l+1, emit(l: tc := b;), return tc } c = c + 1, l = l +1 emit(l: tc := A * B; ) return tc } let B = {c=c+1, l=l+1, emit(l: tc := d;), return tc } c = c + 1, l = l +1 emit(l: tc := A - B; ) return tc } Code 1: t1:=a; 2: t2:=b; 3: t3:=t1*t2 4: t4:=d 5: t5:=t3-t4 37

38 cgen for statements We can extend the cgen function to operate over statements as well Unlike cgen for expressions, cgen for statements does not return the name of a temporary holding a value (Why?) 38

39 Syntax n Num x Var numerals program variables A n x A ArithOp A (A) ArithOp - + * / B true false A = A A A B B B (B) S x := A skip S; S { S } if B then S else S while B S 39

40 Translation rules for statements cgen(skip) = l: skip where l is fresh cgen(e) = (P, t) cgen(x := e) = P l: x :=t where l is fresh cgen(s 1 ) = P 1, cgen(s 2 ) = P 2 cgen(s 1 ; S 2 ) = P 1 P 2 40

41 Translation rules for conditions cgen(b) = (Pb, t), cgen(s 1 ) = P 1, cgen(s 2 ) = P 2 cgen(if b then S 1 else S 2 ) = Pb IfZ t Goto l false P 1 l finish : Goto L after l false : skip P 2 l after : skip where l finish, l false, l after are fresh 41

42 Translation rule for loops cgen(b) = (Pb, t), cgen(s) = P cgen(while b S) = l before : skip Pb IfZ t Goto l after P l loop : Goto L before l after : skip where l after, l before, l loop are fresh 42

43 Translation example y := 137+3; if x=0 z := y; else x := y; 1: t1 := 137 2: t2 := 3 3: t3 := t1 + t2 4: y := t3 5: t4 := x 6: t5 := 0 7: t6 := t4=t5 8: IfZ t6 Goto 12 9: t7 := y 10: z := t7 11: Goto 14 12: t8 := y 13: x := t8 14: skip 43

44 Translation Correctness 44

45 Compiler correctness Compilers translate programs in one language (usually high) to another language (usually lower) such that they are both equivalent Our goal is to formally define the meaning of this equivalence First, we must formally define the meaning of programs 45

46 Formal semantics 46

47 47

48 What is formal semantics? Formal semantics is concerned with rigorously specifying the meaning, or behavior, of programs, pieces of hardware, etc. 48

49 Why formal semantics? Implementation-independent definition of a programming language Automatically generating interpreters (and some day maybe full fledged compilers) Optimization, verification, and debugging If you don t know what it does, how do you know its correct/incorrect? How do you know whether a given optimization is correct? 49

50 Operational semantics Elements of the semantics States/configurations: the (aggregate) values that a program computes during execution Transition rules: how the program advances from one configuration to another 50

51 Operational semantics of while 51

52 While syntax reminder n Num x Var numerals program variables A n x A ArithOp A (A) ArithOp - + * / B true false A = A A A B B B (B) S x := A skip S; S { S } if B then S else S while B do S 52

53 Semantic categories Z T State Integers {0, 1, -1, 2, -2, } Truth values {ff, tt} Var Z Example state: =[x 5, y 7, z 0] Lookup: (x) = 5 Update: [x 6] = [x 6, y 7, z 0] 53

54 Semantics of expressions 54

55 Semantics of arithmetic expressions Semantic function A : State Z Defined by induction on the syntax tree n = n x = (x) a 1 + a 2 = a 1 + a 2 a 1 - a 2 = a 1 - a 2 a 1 * a 2 = a 1 a 2 (a 1 ) = a not needed - a = 0 - a 1 Compositional Expressions in While are side-effect free 55

56 Arithmetic expression exercise Suppose x = 3 Evaluate x+1 56

57 Semantics of boolean expressions Semantic function B : State T Defined by induction on the syntax tree true = tt false = ff a 1 = a 2 = a 1 a 2 = b 1 b 2 = b = Compositional Expressions in While are side-effect free 57

58 Semantics of statements S, first step By Vanillase (Own work) [CC BY-SA 3.0 ( via Wikimedia Commons This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license. 58

59 Operational semantics Developed by Gordon Plotkin Configurations: has one of two forms: S, Transitions S, Statement S is about to execute on state Terminal (final) state first step = S, Execution of S from is not completed and remaining computation proceeds from intermediate configuration = Execution of S from has terminated and the final state is S, is stuck if there is no such that S, 59

60 Form of semantic rules defined by rules of the form premise conclusion S 1, 1 1,, S n, n n S, if side condition The meaning of compound statements is defined using the meaning immediate constituent statements 60

61 Operational semantics for While [ass] [skip] [comp 1 ] [comp 2 ] x:=a, [x a ] skip, S 1, S 1, S 1 ; S 2, S 1 ; S 2, S 1, S 1 ; S 2, S 2, When does this happen? [if tt ] [if ff ] if b then S 1 else S 2, S 1, if b then S 1 else S 2, S 2, if b = tt if b = ff [while tt ] [while ff ] while b do S, S; while b do S, while b do S, if b = tt if b = ff 61

62 Factorial (n!) example Input state such that x = 3 y := 1; while (x=1) do (y := y * x; x := x 1) y :=1 ; W, W, [y 1] ((y := y * x; x := x 1); W), [y 1] (x := x 1; W), [y 3] W, [y 3][x 2] ((y := y * x; x := x 1); W), [y 3] [x 2] (x := x 1; W), [y 6] [x 2] W, [y 6][x 1] [y 6][x 1] 62

63 An interpreter Derivation sequences Given a statement S and an input state start with the initial configuration S, Repeatedly apply rules until either a terminal state is reached or an infinite sequence We will write S, k if can be obtained from S, by k derivation steps We will write S, * if S, k for some k 0 63

64 The semantics of statements The meaning of a statement S is defined as if S, * S = else Examples: skip = x:=1 = [x 1] while true do skip = 64

65 Properties of operational semantics 65

66 Deterministic semantics for While Theorem: for all statements S and states 1, 2 if S, * 1 and S, * 2 then 1 = 2 66

67 Program termination Given a statement S and input S terminates on if there exists a state such that S, * S loops on if there is no state such that S, * Given a statement S S always terminates if for every input state, S terminates on S always loops if for every input state, S loops on 67

68 Semantic equivalence S 1 and S 2 are semantically equivalent if for all : S 1, * if and only if S 2, * is either stuck or terminal and there is an infinite derivation sequence for S 1, if and only if there is one for S 2, Examples S; skip and S while b do S and if b then (S; while b S) else skip ((S 1 ; S 2 ); S 3 ) and (S 1 ; (S 2 ; S 3 )) (x:=5; y:=x*8) and (x:=5; y:=40) 68

69 Exercise Why do we need this? 69

70 Operational semantics of IL 70

71 IL syntax reminder n Num l Num x Var Temp Numerals Labels Variables and temporaries V n x R V Op V V Op - + * / = << >> C l: skip l: x := R l: Goto l l: IfZ x Goto l IR C + 71

72 Intermediate program states Z IState Integers {0, 1, -1, 2, -2, } (Var Temp {pc}) Z Var, Temp, and {pc} are all disjoint For every state m and program P=1:c 1,,n:c n we have that 1 m(pc) n+1 We can check that the labels used in P are legal 72

73 Rules for executing commands We will use rules of the following form m(pc) = l P(l) = C m m Here m is the pre-state, which is scheduled to be executed as the program counter indicates, and m is the post-state The rules specialize for the particular type of command C and possibly other conditions 73

74 Evaluating values n m = n x m = m(x) v 1 op v 2 m = v 1 m op v 2 m 74

75 Rules for executing commands m(pc) = l P(l) = skip m m[pc l+1] m(pc) = l P(l) = x:=v m m[pc l+1, x v m] m(pc) = l P(l) = x:=v 1 op v 2 m m[pc l+1, x v 1 m op v 2 m] m(pc) = l P(l) = Goto l m m[pc l ] 75

76 Rules for executing commands m(pc) = l P(l) = IfZ x Goto l m(x)=0 m m[pc l ] m(pc) = l P(l) = IfZ x Goto l m(x) 0 m m[pc l+1] m(pc) = l P(l) = IfNZ x Goto l m(x) 0 m m[pc l ] m(pc) = l P(l) = IfNZ x Goto l m(x)=0 m m[pc l+1] 76

77 Executing programs For a program P=1:c 1,,n:c n we define executions as finite or infinite sequences m 1 m 2 m n We write m * m if there is a finite execution starting at m and ending at m : m = m 1 m 2 m n = m 77

78 Semantics of a program For a program P=1:c 1,,n:c n and a state m s.t. m(pc)=1 we define the result of executing P on m as P m = m if m * m and m (pc)=n+1 else Lemma: the function is well-defined (i.e., at most one output state) 78

79 Execution example Execute the following intermediate language program on a state where all variables evaluate to 0 1: t1 := 137 2: y := t : IfZ x Goto 7 4: t2 := y 5: z := t2 6: Goto 9 7: t3 := y 8: x := t3 9: skip m = [pc 1, t1 0, t2 0, t3 0, x 0, y 0]? 79

80 Execution example Execute the following intermediate language program on a state where all variables evaluate to 0 1: t1 := 137 2: y := t : IfZ x Goto 7 4: t2 := y 5: z := t2 6: Goto 9 7: t3 := y 8: x := t3 9: skip m = [pc 1, t1 0, t2 0, t3 0, x 0, y 0] m[pc 2, t1 137] m[pc 3, t1 137, y 140] m[pc 7, t1 137, y 140] m[pc 8, t1 137, t3 140, y 140] m[pc 9, t1 137, t3 140,, x 140, y 140] m[pc 10, t1 137, t3 140,, x 140, y 140] 80

81 Adding procedures 81

82 While+procedures syntax n Num x Var f Numerals Program variables Function identifiers, including main A n x A ArithOp A (A) f(a * ) ArithOp - + * / B true false A = A A A B B B (B) S x := A skip S; S { S } if B then S else S while B S f(a * ) F f(x * ) { S } P ::= F + Can be used to call side-effecting functions and to return values from functions 82

83 IL+procedures syntax n Num l Num x Var Temp Params f Numerals Labels and function identifiers Variables, temporaries, and parameters Function identifiers V n x R V Op V V Call f(v * ) pn Op - + * / = << >> C l: skip l: x := R l: Goto l l: IfZ x Goto l l: IfNZ x Goto l l: Call f(x * ) l: Ret x IR C + Accesses value of function parameter n 83

84 Exercise 84

85 Defining translation correctness 85

86 Exercise 1 Are the following equivalent in your opinion? While IL x := 137 1: t1 := 137 2: x := t1 86

87 Exercise 2 Are the following equivalent in your opinion? While IL x := 137 1: y := 137 2: x := y 87

88 Exercise 3 Are the following equivalent in your opinion? While IL x := 137 2: t2 := 138 3: t1 := 137 4: x := t1 88

89 Exercise 4 Are the following equivalent in your opinion? While IL x := 137 2: t2 := 138 3: t1 := 137 4: x := t1 5: t1 :=

90 Equivalence of arithmetic expressions Define TVar = Var Temp While state: Var Z IL state: m (Var Temp {pc}) Z Define label(p) to be first label of IL program P An arithmetic While expression a is equivalent to an IL program P and x TVar iff for every input state m such that m(pc)=label(p): a m Var = ( P m) x 90

91 Statement equivalence We define state equivalence by m iff =m Var That is, for each x Var (x)=m(x) A While statement S is equivalent to an IL program P iff for every input state m such that m(pc)=label(p): S m Var P m 91

92 Next lecture: Dataflow-based Optimizations

Fall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

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

IR Optimization. May 15th, Tuesday, May 14, 13

IR Optimization. May 15th, Tuesday, May 14, 13 IR Optimization May 15th, 2013 Tuesday, May 14, 13 But before we talk about IR optimization... Wrapping up IR generation Tuesday, May 14, 13 Three-Address Code Or TAC The IR that you will be using for

More information

IR Generation. May 13, Monday, May 13, 13

IR Generation. May 13, Monday, May 13, 13 IR Generation May 13, 2013 Monday, May 13, 13 Monday, May 13, 13 Monday, May 13, 13 Midterm Results Grades already in Repeal policy Talk to TA by the end of the Tuesday reserve the right to regrade the

More information

Three-Address Code IR

Three-Address Code IR Three-Address Code IR Announcements Programming Project 3 due tonight at 11:59PM. OH today after lecture. Ask questions on Piazzza! Ask questions via email! Programming Project 4 out, due Wednesday, August

More information

Compilation Lecture 6: Attribute Grammars IR Noam Rinetzky

Compilation Lecture 6: Attribute Grammars IR Noam Rinetzky Compilation 0368-3133 Lecture 6: Attribute Grammars IR Noam Rinetzky 1 Context Analysis Identification Gather information about each named item in the program e.g., what is the declaration for each usage

More information

Fall Compiler Principles Lecture 2: LL parsing. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 2: LL parsing. Roman Manevich Ben-Gurion University of the Negev Fall 2017-2018 Compiler Principles Lecture 2: LL parsing Roman Manevich Ben-Gurion University of the Negev 1 Books Compilers Principles, Techniques, and Tools Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman

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

Fall Compiler Principles Lecture 2: LL parsing. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 2: LL parsing. Roman Manevich Ben-Gurion University of the Negev Fall 2016-2017 Compiler Principles Lecture 2: LL parsing Roman Manevich Ben-Gurion University of the Negev 1 Books Compilers Principles, Techniques, and Tools Alfred V. Aho, Ravi Sethi, Jeffrey D. Ullman

More information

Formal Semantics of Programming Languages

Formal Semantics of Programming Languages Formal Semantics of Programming Languages Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson http://www.daimi.au.dk/~bra8130/wiley_book/wiley.html Benefits of formal

More information

Formal Semantics of Programming Languages

Formal Semantics of Programming Languages Formal Semantics of Programming Languages Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson http://www.daimi.au.dk/~bra8130/wiley_book/wiley.html Benefits of formal

More information

Crafting a Compiler with C (II) Compiler V. S. Interpreter

Crafting a Compiler with C (II) Compiler V. S. Interpreter Crafting a Compiler with C (II) 資科系 林偉川 Compiler V S Interpreter Compilation - Translate high-level program to machine code Lexical Analyzer, Syntax Analyzer, Intermediate code generator(semantics Analyzer),

More information

Where we are. What makes a good IR? Intermediate Code. CS 4120 Introduction to Compilers

Where we are. What makes a good IR? Intermediate Code. CS 4120 Introduction to Compilers Where we are CS 4120 Introduction to Compilers Andrew Myers Cornell University Lecture 13: Intermediate Code 25 Sep 09 Source code (character stream) Token stream Abstract syntax tree Abstract syntax tree

More information

Fall Compiler Principles Lecture 4: Parsing part 3. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Lecture 4: Parsing part 3. Roman Manevich Ben-Gurion University of the Negev Fall 2016-2017 Compiler Principles Lecture 4: Parsing part 3 Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation Scanning

More information

Fall Compiler Principles Lecture 3: Parsing part 2. Roman Manevich Ben-Gurion University

Fall Compiler Principles Lecture 3: Parsing part 2. Roman Manevich Ben-Gurion University Fall 2014-2015 Compiler Principles Lecture 3: Parsing part 2 Roman Manevich Ben-Gurion University Tentative syllabus Front End Intermediate Representation Optimizations Code Generation Scanning Lowering

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

Fall Compiler Principles Lecture 12: Register Allocation. Roman Manevich Ben-Gurion University

Fall Compiler Principles Lecture 12: Register Allocation. Roman Manevich Ben-Gurion University Fall 2014-2015 Compiler Principles Lecture 12: Register Allocation Roman Manevich Ben-Gurion University Syllabus Front End Intermediate Representation Optimizations Code Generation Scanning Lowering Local

More information

Formal Syntax and Semantics of Programming Languages

Formal Syntax and Semantics of Programming Languages Formal Syntax and Semantics of Programming Languages Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson http://www.daimi.au.dk/~bra8130/wiley_book/wiley.html The 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

An Overview of Compilation

An Overview of Compilation An Overview of Compilation (www.cse.iitb.ac.in/ uday) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay January 2014 cs306 Compilation Overview: Outline 1/18 Outline

More information

Formal Syntax and Semantics of Programming Languages

Formal Syntax and Semantics of Programming Languages Formal Syntax and Semantics of Programming Languages Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson http://www.daimi.au.dk/~bra8130/wiley_book/wiley.html axioms

More information

Compilers. Compiler Construction Tutorial The Front-end

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

PROGRAM ANALYSIS & SYNTHESIS

PROGRAM ANALYSIS & SYNTHESIS Lecture 02 Structural Operational Semantics (SOS) PROGRAM ANALYSIS & SYNTHESIS EranYahav 1 Previously static analysis over-approximation of program behavior abstract interpretation abstraction, transformers,

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

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

Undergraduate Compilers in a Day

Undergraduate Compilers in a Day Question of the Day Backpatching o.foo(); In Java, the address of foo() is often not known until runtime (due to dynamic class loading), so the method call requires a table lookup. After the first execution

More information

Formal Languages and Compilers Lecture I: Introduction to Compilers

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

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

COMPILER DESIGN. For COMPUTER SCIENCE

COMPILER DESIGN. For COMPUTER SCIENCE COMPILER DESIGN For COMPUTER SCIENCE . COMPILER DESIGN SYLLABUS Lexical analysis, parsing, syntax-directed translation. Runtime environments. Intermediate code generation. ANALYSIS OF GATE PAPERS Exam

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

Application: Programming Language Semantics

Application: Programming Language Semantics Chapter 8 Application: Programming Language Semantics Prof. Dr. K. Madlener: Specification and Verification in Higher Order Logic 527 Introduction to Programming Language Semantics Programming Language

More information

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1 Table of Contents About the Authors... iii Introduction... xvii Chapter 1: System Software... 1 1.1 Concept of System Software... 2 Types of Software Programs... 2 Software Programs and the Computing Machine...

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

TACi: Three-Address Code Interpreter (version 1.0)

TACi: Three-Address Code Interpreter (version 1.0) TACi: Three-Address Code Interpreter (version 1.0) David Sinclair September 23, 2018 1 Introduction TACi is an interpreter for Three-Address Code, the common intermediate representation (IR) used in compilers.

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

COS 320. Compiling Techniques

COS 320. Compiling Techniques Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly

More information

Fall Compiler Principles Lecture 5: Parsing part 4. Roman Manevich Ben-Gurion University

Fall Compiler Principles Lecture 5: Parsing part 4. Roman Manevich Ben-Gurion University Fall 2014-2015 Compiler Principles Lecture 5: Parsing part 4 Roman Manevich Ben-Gurion University Tentative syllabus Front End Intermediate Representation Optimizations Code Generation Scanning Lowering

More information

CS153: Compilers Lecture 17: Control Flow Graph and Data Flow Analysis

CS153: Compilers Lecture 17: Control Flow Graph and Data Flow Analysis CS153: Compilers Lecture 17: Control Flow Graph and Data Flow Analysis Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 5 out Due Tuesday Nov 13 (14 days) Project 6 out Due

More information

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING PRINCIPLES OF COMPILER DESIGN 2 MARKS 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

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 Representations & Symbol Tables

Intermediate Representations & Symbol Tables Intermediate Representations & Symbol Tables Copyright 2014, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission

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

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

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher COP4020 ming Languages Compilers and Interpreters Robert van Engelen & Chris Lacher Overview Common compiler and interpreter configurations Virtual machines Integrated development environments Compiler

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

List of Figures. About the Authors. Acknowledgments

List of Figures. About the Authors. Acknowledgments List of Figures Preface About the Authors Acknowledgments xiii xvii xxiii xxv 1 Compilation 1 1.1 Compilers..................................... 1 1.1.1 Programming Languages......................... 1

More information

LECTURE 3. Compiler Phases

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

5. Semantic Analysis!

5. Semantic Analysis! 5. Semantic Analysis! Prof. O. Nierstrasz! Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes.! http://www.cs.ucla.edu/~palsberg/! http://www.cs.purdue.edu/homes/hosking/!

More information

CS412/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 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 information

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4303 April 9, 2010 14.00-15.30 This exam (6 pages) consists of 52 True/False

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

CS 314 Principles of Programming Languages. Lecture 3

CS 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 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

5. Semantic Analysis. Mircea Lungu Oscar Nierstrasz

5. Semantic Analysis. Mircea Lungu Oscar Nierstrasz 5. Semantic Analysis Mircea Lungu Oscar Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes. http://www.cs.ucla.edu/~palsberg/

More information

Program Analysis: Lecture 02 Page 1 of 32

Program Analysis: Lecture 02 Page 1 of 32 Program Analysis: Lecture 02 Page 1 of 32 Program Analysis/ Mooly Sagiv Lecture 1, 31/10/2012 Operational Semantics Notes by: Kalev Alpernas As background to the subject of Program Analysis, we will first

More information

Fall Compiler Principles Context-free Grammars Refresher. Roman Manevich Ben-Gurion University of the Negev

Fall Compiler Principles Context-free Grammars Refresher. Roman Manevich Ben-Gurion University of the Negev Fall 2016-2017 Compiler Principles Context-free Grammars Refresher Roman Manevich Ben-Gurion University of the Negev 1 xample grammar S S ; S S id := S print (L) id num + L L L, shorthand for Statement

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

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

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

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Chapter 3 (part 3) Describing Syntax and Semantics

Chapter 3 (part 3) Describing Syntax and Semantics Chapter 3 (part 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

More information

A simple syntax-directed

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

Compiler Design (40-414)

Compiler Design (40-414) Compiler Design (40-414) Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007 Evaluation: Midterm Exam 35% Final Exam 35% Assignments and Quizzes 10% Project

More information

Lecture 12: Conditional Expressions and Local Binding

Lecture 12: Conditional Expressions and Local Binding Lecture 12: Conditional Expressions and Local Binding Introduction Corresponds to EOPL 3.3-3.4 Please review Version-1 interpreter to make sure that you understand how it works Now we will extend the basic

More information

CST-402(T): Language Processors

CST-402(T): Language Processors CST-402(T): Language Processors Course Outcomes: On successful completion of the course, students will be able to: 1. Exhibit role of various phases of compilation, with understanding of types of grammars

More information

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done What is a compiler? What is a compiler? Traditionally: Program that analyzes and translates from a high level language (e.g., C++) to low-level assembly language that can be executed by hardware int a,

More information

Lexical Analysis. Introduction

Lexical Analysis. Introduction Lexical Analysis Introduction Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission to make copies

More information

CSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1

CSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1 CSE P 501 Compilers Intermediate Representations Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 G-1 Administrivia Semantics/types/symbol table project due ~2 weeks how goes it? Should be caught up on

More information

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES (2018-19) (ODD) Code Optimization Prof. Jonita Roman Date: 30/06/2018 Time: 9:45 to 10:45 Venue: MCA

More information

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson

6.184 Lecture 4. Interpretation. Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 6.184 Lecture 4 Interpretation Tweaked by Ben Vandiver Compiled by Mike Phillips Original material by Eric Grimson 1 Interpretation Parts of an interpreter Arithmetic calculator

More information

Principles of Programming Languages

Principles of Programming Languages Principles of Programming Languages Lesson 14 Type Checking Collaboration and Management Dana Fisman www.cs.bgu.ac.il/~ppl172 1 Type Checking We return to the issue of type safety we discussed informally,

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

COMP 181. Prelude. Intermediate representations. Today. High-level IR. Types of IRs. Intermediate representations and code generation

COMP 181. Prelude. Intermediate representations. Today. High-level IR. Types of IRs. Intermediate representations and code generation Prelude COMP 181 Lecture 14 Intermediate representations and code generation October 19, 2006 Who is Seth Lloyd? Professor of mechanical engineering at MIT, pioneer in quantum computing Article in Nature:

More information

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m.

Note that in this definition, n + m denotes the syntactic expression with three symbols n, +, and m, not to the number that is the sum of n and m. CS 6110 S18 Lecture 8 Structural Operational Semantics and IMP Today we introduce a very simple imperative language, IMP, along with two systems of rules for evaluation called small-step and big-step semantics.

More information

Chapter 2 A Quick Tour

Chapter 2 A Quick Tour Chapter 2 A Quick Tour 2.1 The Compiler Toolchain A compiler is one component in a toolchain of programs used to create executables from source code. Typically, when you invoke a single command to compile

More information

CSE 401/M501 Compilers

CSE 401/M501 Compilers CSE 401/M501 Compilers Intermediate Representations Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 G-1 Agenda Survey of Intermediate Representations Graphical Concrete/Abstract Syntax Trees (ASTs)

More information

Syntax-Directed Translation. Lecture 14

Syntax-Directed Translation. Lecture 14 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik) 9/27/2006 Prof. Hilfinger, Lecture 14 1 Motivation: parser as a translator syntax-directed translation stream of tokens parser ASTs,

More information

Intermediate Representations

Intermediate Representations COMP 506 Rice University Spring 2018 Intermediate Representations source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students

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! Next time reading assignment [ALSU07] Chapters 1,2 [ALSU07] Sections 1.1-1.5 (cover in class) [ALSU07] Section 1.6 (read on your

More information

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation Language Implementation Methods The Design and Implementation of Programming Languages Compilation Interpretation Hybrid In Text: Chapter 1 2 Compilation Interpretation Translate high-level programs to

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

CS 314 Principles of Programming Languages

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

5. Semantic Analysis. Mircea Lungu Oscar Nierstrasz

5. Semantic Analysis. Mircea Lungu Oscar Nierstrasz 5. Semantic Analysis Mircea Lungu Oscar Nierstrasz Thanks to Jens Palsberg and Tony Hosking for their kind permission to reuse and adapt the CS132 and CS502 lecture notes. http://www.cs.ucla.edu/~palsberg/

More information

1 Lexical Considerations

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

Control Flow Analysis

Control Flow Analysis Control Flow Analysis Last time Undergraduate compilers in a day Today Assignment 0 due Control-flow analysis Building basic blocks Building control-flow graphs Loops January 28, 2015 Control Flow Analysis

More information

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 2010 P. N. Hilfinger CS 164: Final Examination (revised) Name: Login: You have

More information

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent

More information

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1 CSE P 501 Compilers Static Semantics Hal Perkins Winter 2008 1/22/2008 2002-08 Hal Perkins & UW CSE I-1 Agenda Static semantics Types Attribute grammars Representing types Symbol tables Note: this covers

More information

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100 GATE- 2016-17 Postal Correspondence 1 Compiler Design Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts,

More information

TDDD55 - Compilers and Interpreters Lesson 3

TDDD55 - Compilers and Interpreters Lesson 3 TDDD55 - Compilers and Interpreters Lesson 3 November 22 2011 Kristian Stavåker (kristian.stavaker@liu.se) Department of Computer and Information Science Linköping University LESSON SCHEDULE November 1,

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

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

Compiler Construction

Compiler Construction Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ws-1819/cc/ Generation of Intermediate Code Outline of Lecture 15

More information

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1 CS321 Languages and Compiler Design I Winter 2012 Lecture 1 1 COURSE GOALS Improve understanding of languages and machines. Learn practicalities of translation. Learn anatomy of programming languages.

More information

Formal Semantics of Programming Languages

Formal Semantics of Programming Languages Formal Semantics of Programming Languages Mooly Sagiv Reference: Semantics with Applications Chapter 2 H. Nielson and F. Nielson http://www.daimi.au.dk/~bra8130/wiley_book/wiley.html Benefits of formal

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

CS 360 Programming Languages Interpreters

CS 360 Programming Languages Interpreters CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like

More information

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday

Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday Announcements! P1 part 1 due next Tuesday P1 part 2 due next Friday 1 Finite-state machines CS 536 Last time! A compiler is a recognizer of language S (Source) a translator from S to T (Target) a program

More information

Page No 1 (Please look at the next page )

Page 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

Parsing II Top-down parsing. Comp 412

Parsing II Top-down parsing. Comp 412 COMP 412 FALL 2018 Parsing II Top-down parsing Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled

More information

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis? Anatomy of a Compiler Program (character stream) Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Semantic Analysis Parse Tree Intermediate Code Generator Intermediate Code Optimizer Code Generator

More information