












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













2
Front End
Back End
source code
IR (^) machine code
errors
4
5
Front end is O(n) or
O(n log n)
Back end is NP-Complete
(NPC)
7
Modules
Scanner
Parser
sourcecode scanner tokens (^) parser IR
errors
8
sourcecode scanner tokens (^) parser IR
errors
10
token type
word
<id, x >
11
we call the pair
“<token type, word>” a “token”
typical tokens: number ,
identifier , +, -, new , while , if
13
Recognizes context-free
syntax and reports errors
Guides context-sensitive
(“semantic”) analysis
Builds IR for source
program
14
Context-free syntax is specified with a grammar G= ( S,N,T,P )
S is the start symbol
N is a set of non-terminal symbols
T is set of terminal symbols or words
P is a set of productions or rewrite rules
16
For this CFG
17
Given a CFG, we can derive
sentences by repeated substitution
Consider the sentence
(expression) x + 2 – y
19
To recognize a valid
sentence in some CFG, we reverse this process and build up a parse
A parse can be represented
by a tree: parse tree or syntax tree
20
Production Result goal 1 expr 2 expr op term 5 expr op y 7 expr – y 2 expr op term – y 4 expr op 2 – y 6 expr + 2 – y 3 term^ + 2 – y 5 x + 2 – y