Escolar Documentos
Profissional Documentos
Cultura Documentos
Branch-Computer Science
Roll Number-0800310001
Subject-Compiler Design
Topic-Syntax directed translation
Faculty-Mr.Mighty Abrol
It is a CFG grammar augmented with:
“Attributes” (assigned to each grammar symbol).
Semantic Rules (associated to each production
involving the Attributes of the symbols in the
production).
Attributes can be synthesized or inherited.
Semantic Rules for a production A have
the form:
b = f (c1,…,cn) where
(b is synthesized) b is an attribute of A and c1…cn are
attributes of symbols in .
(b is inherited) b is an attribute of some symbol in
and c1…cn are attributes of symbols in A,
Terminals have only synthesized attributes
whose values are provided by the lexical
analyzer.
The start non-terminal typically has no inherited
attributes.
[we may allow function calls as semantic-rules
also; these are “Side-effects”…
Parse-tree that also shows the values of the
attributes at each node.
Values of Attributes in nodes of annotated
parse-tree are either,
initialized to constant values or by the lexical
analyzer.
determined by the semantic-rules.
If a syntax-directed definition employs only
Synthesized attributes the evaluation of all
attributes can be done in a bottom-up fashion.
Print(19)
E val=19
T val=15
T val=3 T val=4
L
T in=real
type=real
addtype(id1,real)
L
in=real
id id id
real entry=id1
, entry=id2
, entry=id3
Directed Graph
Shows interdependencies between attributes.
Construction:
Put each semantic rule into the form b=f(c1,…,ck) by
introducing dummy synthesized attribute b for
every semantic rule that consists of a procedure
call.
E.g.,
LEn print(E.val)
Becomes: dummy = print(E.val)
Etc.
for each node n in the parse tree do
for each attribute a of the grammar symbol at n do
construct a node in the dependency graph for a
Print(19)
E val=19
T val=15
T val=3 T val=4
val=19
val=15
val=3 val=4