CS 415 Compilers: Problem Set 1 Due date: Wednesday, February 3, in recitation Problem 1 Code Optimization Goals
Optimizing compilers may have dierent optimization objectives such as producing (1) fast code, (2) code with a small footprint (small code siz
CS415 Compilers SyntaxDirected Translation Schemes, type systems / type checking, simple code generation
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Example Building an Abstract Syntax Tree
CS415 Compilers Contextsensitive Analysis Attribute Grammars, SyntaxDirected Translation Schemes
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Attribute Grammars
What is an attribute grammar
CS415 Compilers LR(0), SLR(1), LALR(1) Contextsensitive Analysis
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Left Recursion versus Right Recursion
Right recursion * * Required for terminati
Lecture 2
Sunday, February 22, 2015
11:52 PM

OPTIMIZER
run by a series of passes
removes redundent computations
remove useless code
put stuff in more efficient places
RUN TIME SYSTEM
 memory management services
allocate, deallocate, collect garbage

CS415 Compilers LR(1) parsing
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
LR(k)
items
The LR(1) table construction algorithm uses LR(1) items to represent valid configurations of an LR(1) pa
CS415 Compilers LR(1) parsing, (LR(1), SLR(1), LALR(1)
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Review  LR(1) Parsers
LR(1) parsers are tabledriven, shiftreduce parsers that
use a lim
CS415 Compilers Bottomup parsing, LR(1) parsing
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Parsing (Syntax Analysis)
EAC Chapters 3.4 3.5
cs415, spring 10
Lecture 13
2
Parsing Techniques:
CS415 Compilers leftrecursion removal, left factoring, LL(1) summary, recursive descent parsing example, introduction to bottomup parsing
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Review
CS415 Compilers Top Down vs. Bottom Up parsing; first and follow sets; LL(1) parsing
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Parsing (Syntax Analysis)
EAC Chapters 3.3
cs415, spring 10
L
CS415 Compilers Code Generation
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Code Generation: Structure of a Compiler (EaC Ch. 7)
O(n) O(n)
words
O(n), O(n log n), NPComplete
Scanner
Parser
CS415 Compilers Code Generation
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Project 2
Consists of two parts: 1 syntax errors and type checking (static semantics) 2 simple code generation  c
CS415 Compilers Procedure Abstraction
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Procedure Abstraction
Chapter 6 in EAC
The compiler must deal with interface between compile time
and run t
Lecture 1
Sunday, February 22, 2015
7:59 PM

Compiler
translates program from one language to another
hides hardware interaction from program
must recognize legal and illegal commands
store variables
TWO PASS COMPILER
 IR  intermediate representation

DFA
Wednesday, February 25, 2015
2:33 AM

 Front end deals with input languages
does the language make sense?
 if so build IR version for compiler
 Scanner
characters into words
token type = what the thing is
<type, actual token>
so <id, x>, <plu
dependence graph
Monday, February 23, 2015
3:47 AM



DATA DEPENDENCE
A writes a location that B later reads  RAW Conflict
a reads a location that b later writes  war conflict
a writes a location that b later writes  waw conflict
reorder instruction
ILOC
Monday, February 23, 2015
12:15 AM
ILOC  IR LANGUAGE
 "load" and "stores" transfers values to and from register and memory
 ex: add register 1 and 2 and put value in 3
 each instruction can have
operation name (add)
list of operands (r1, r2)
s
CS415 Compilers Procedure Abstraction
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Lexical Scoping: Translating Local Names
How does the compiler represent a specific instance of x ? Name is
CS 314 Principles of Programming
Languages
Lecture 26
Zheng Zhang
Department of Computer Science
Rutgers University
Wednesday 14th December, 2016
Zheng Zhang
1
[email protected] University
Class Information
I
Project 4 (optional) will be posted soon.
Topic: Para
CS415 Compilers Optimizations
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Final Road Map
Project extension? read submission procedure carefully; credit reductions if you do not follow these
CS415 Compilers Procedure Abstraction
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Establishing Addressability
Using access links ( static links ) Each AR has a pointer to AR of lexical ances
CS415 Compilers Syntax Analysis CFG, derivations, ambiguity, introduction to parsing
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Parsing (Syntax Analysis)
EAC Chapters 3.1  3.2
cs415, sprin
CS415 Compilers Lexical Analysis
These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
Review: Automating Scanner Construction
RE NFA (Thompsons construction)
Build an NFA for each term Combine them
HW 5 Sample Solution Problem 1 First(A) = cfw_ ( , a First(B) = cfw_ ( , a First(C) = cfw_ ), ',' Follow(A) = cfw_ eof , ',' , ) Follow(B) = cfw_ ) Follow(C) = cfw_ )
(
a
)
,
eof
A
A => (B)
A => a
B
B => AC
B => AC C => epsilon C => ,AC
C
Stack Cont
CS 415 Compilers: Problem Set 5 Due date: Wednesday, March 10, 2010, before recitation Problem 1
Consider the following grammar with start symbol A. 1 2 3 3 4 A := ( B )  a B := A C C := , A C  epsilon 1. Compute the FIRST and FOLLOW sets for the gramma
HW 4 Sample Solution Problem 1 The following pseudostring case <arith_expr> : case <arith_expr> : default <stmt> produces to parse trees. By denition the grammar is ambiguous. Problem 2 A A
(
B
) (
B
)
B
,
A B , A
A
x A
x 2.2 Leftmost A > ( B ) > ( B
CS 415 Compilers: Problem Set 4 Due date: Wednesday, March 3, 2010, before recitation Problem 1
You want to include an arithmetic switch statement in a programming language. The sematics of the new construct is as follows: The expression in the switch sta
0 HW 3  Sample Solution Problem 1 1 1 0 EO 0 OO EE 0 1 1 OE
0mod4
ust ut m ith Inp in w beg one! a
0 1 1 S 1 1 1mod4 1 0 0 0
rep 1mod res ent 4 & 3m ed with od4 c the an b sam e e st ate ! 2mod4
3mod4 0 Start 1 1 mod 7 0 0 1 0 4 mod 7 1 0 0 3 mod 7 1 0 m
CS 415 Compilers: Problem Set 3 Due date: Wednesday, February 24, in recitation Problem 1 DFA
Give a DFA for the following languages over the aphabet cfw_0, 1: 1. The set of all strings with an odd number of 0s and an even number of 1s . 2. The set of all