




























































































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!





























































































An overview of parsing
Functions & Responsibilities
Context Free Grammars
Concepts & Terminology
Writing and Designing Grammars
Resolving Grammar Problems / Difficulties
Top-Down Parsing
Recursive Descent & Predictive LL
Bottom-Up Parsing
Concluding Remarks/Looking Ahead
regular
expressions
or parsing
info on tokens in source,
type checking, semantic
analysis
check structure of tokens
recovery
interm
repres
errors
lexical
analyzer
parser
rest of
front end
symbol
table
source
program
parse
tree get next
token
token
put - closure({s 0
}) as an unmarked state into the set of DFA
(DStates)
while (there is one unmarked S 1
in DStates) do
mark S 1
for (each input symbol a)
2
- closure(move(S 1
,a))
if (S 2
is not in DStates) then
add S 2
into DStates as an unmarked state
transfunc[S 1
,a] S 2
accepting state of NFA
,...,s n
are positions in S and symbols in those positions are a
’ followpos(s 1
) ... followpos(s n
)
: set of accepting states
: set of non-accepting states
and s 2
are in the same group if
for all input symbols a, states s 1
and s 2
have transitions to states in the same group.
the start state of the original DFA.
the accepting states of the original DFA.
#include<stdio.h>
int f1(int v)
{ int i,j=0;
for (i=1;i<5;i++)
{ j=v+f2(i) }
return j; }
int f2(int u)
{ int j;
j=u+f1(uu);*
return j; }
int main()
{ int i,j=0;
for (i=1;i<10;i++)
{ j=j+ii printf(“%d\n”,i); }*
printf(“%d\n”,f1(j$));
return 0;
}
Which are “easy” to
recover from? Which
are “hard”?
As reported by MS VC++
'f2' undefined; assuming extern returning int
syntax error : missing ';' before '}‘
syntax error : missing ';' before identifier ‘printf’
Panic Mode – Discard tokens until a “synchronizing” token is
found ( end, “;”, “}”, etc. )
-- Decision of designer
E.g., (1 + + 2) * 3 skip +
-- Problems:
skip input miss declaration – causing more errors
miss errors in skipped material
-- Advantages:
simple suited to 1 error per statement
Phrase Level – Local correction on input
-- “,” ”;” – Delete “,” – insert “;”……
-- Also decision of designer, Not suited to all situations
-- Used in conjunction with panic mode to allow less
input to be skipped
E.g., x=1 ; y=
regular
expressions
or parsing
info on tokens in source,
type checking, semantic
analysis
check structure of tokens
recovery
interm
repres
errors
lexical
analyzer
parser
rest of
front end
symbol
table
source
program
parse
tree get next
token
token
CFLs
Basis of lexical analysis
Represent regular languages
Basis of parsing
Represent language constructs
Characterize context free languages
Reg. Lang.
EXAMPLE: (a+b)*abb
A0 - > aA0 | bA0 | aA
A1 - > bA
A2 - > bA
A3 - > ɛ
i )
i | i>=0 } Non-regular language (Why)
by a context-free grammar.
and non-terminals (including the empty string)
E E + E | E – E | E * E | E / E | - E
E ( E )
E id
E num
expr expr op expr
expr ( expr )
expr - expr
expr id
op +
op -
op __*
op /
Black : NT
Blue : T
expr : S
8 Production rules
A fragment of Cool:
EXPR if EXPR then EXPR else EXPR fi
| while EXPR loop EXPR pool
| id