Escolar Documentos
Profissional Documentos
Cultura Documentos
Syntax Analysis
Sections 4.1-4.4:
CH4.1
345 CS
An overview of parsing :
Functions & Responsibilities
Top-Down Parsing
Recursive Descent & Predictive LL
Bottom-Up Parsing
LR & LALR
Concluding Remarks/Looking Ahead
CH4.2
An Overview of Parsing
345 CS
CH4.3
errors
345 CS
source
program
lexical
analyzer
token
get next
token
parser
symbol
table
parse
tree
rest of
front end
interm
repres
Parsing Responsibilities
345 CS
CH4.5
345 CS
Detecting errors
Finding position at which they occur
Clear / accurate presentation
CH4.6
345 CS
As reported by MS VC++
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(u*u)
return j; }
int main()
{
int i,j=0;
for (i=1;i<10;i++)
{
j=j+i*I;
printf(%d\n,i);
printf("%d\n",f1(j));
return 0;
CH4.7
CH4.8
CH4.9
Motivating Grammars
Regular Expressions
345 CS
CFLs
CH4.10
CH4.11
345 CS
expr term
term id
term real
What do blue
symbols represent?
term integer
operator +
operator -
CH4.12
Derivation
Lets derive: id := id + real integer ;
345 CS
assign_stmt
using production:
assign_stmt id := expr ;
id := expr ;
expr term
term id
operator +
term real
operator -
id := id + real - term;
term integer
id := id + real - integer;
CH4.13
Example Grammar
345 CS
Black : NT
Blue : T
expr : S
9 Production rules
CH4.14
CH4.15
Grammar Concepts
A step in a derivation is zero or one action that
replaces a NT with the RHS of a production rule.
345 CS
CH4.16
W : is a sentence of G
*
E
id * id
Dr. Mohamed Ramadan Saady
CH4.17