UFRN – DIMAP

DIM0339 - Compiladores

Segundo Semestre de 2005

 

Exercícios - Análise sintática (2a. Parte)

 1.      Escrever analizadores sintáticos preditivos recursivos para as linguagens definidas pelas seguintes gramáticas: (aonde letras maiúscilas representam símbolos não terminais, letras minúsculas representam símbolos terminais, e /\ representa a cadeia vazia)

a.       A -> BCD
B -> a C b
B -> /\
C -> c A d
C -> e B f
C -> g D h
C -> /\
D -> i

b.      A -> B C D
B -> b | /\
C -> c | /\
D -> d | /\

c.       S -> S inst
S -> S var D
S -> /\
D -> D ident E
D -> D ident sep
D -> int
D -> float
E -> S proc

d.      S -> A B
A -> begin S end B theend
A -> /\
B -> var L : tipo
B -> B fvar
B -> /\
L -> L , id
L -> id

e.       S -> S inst
S -> T R V
T -> tipo
T -> /\
R -> blq V fblq
R -> /\
V -> /\
V -> id S fin
V -> id ;

f.        E -> [ L
E -> a
L -> E Q
Q -> , L
Q -> ]

g.       P -> D S
D -> D V
D -> /\
S -> S N
S -> /\
V -> decl id ;
V -> decl id ( P ) ;
V -> decl [ D ] id ;
N -> id ;
N -> begin P end

2.      Escrever tabelas de analisadores sintáticos preditivos não recursivos para cada uma das linguagens definidas no exercicio anterior.

3.      Escrever tabelas de analizadores sintáticos SLR para as linguagens definidas pelas seguintes gramáticas: (aonde letras maiúscilas representam símbolos não terminais, letras minúsculas representam símbolos terminais, e /\ representa a cadeia vazia)

a.       S -> id ( L )
S -> id
L -> /\
L -> S Q
Q -> /\
Q -> , S Q

b.      S -> S inst
S -> T R V
T -> tipo
T -> /\
R -> blq V fblq
R -> /\
V -> id S fin
V -> id ;
V -> /\

c.       E -> [ L ]
E -> a
L -> E Q
Q -> , L
Q -> /\

d.      S -> S inst
S -> S var D
S -> /\
D -> D ident E
D -> D ident sep
D -> int
D -> float
E -> S fproc

e.       S -> U
S -> M
M -> i M e M
M -> a
U -> i S
U -> M e U

f.        P -> P C
P -> [ C ]
P -> /\
C -> { P }
C -> ( P )

g.       S -> A B C
A -> begin C end
A -> /\
B -> var tipo
C -> B C
C -> fvar

4.      Exercício 4.50 do livro-texto.

5.      Exercício 4.51 do livro-texto.

6.      Exercício 4.52 do livro-texto.

7.      Exercício 4.53 do livro-texto.