

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These notes provide an explanation of the bottom-up parse of an assignment statement and its translation into three-address code. The document also discusses the implementation of three-address codes as a set of quadruples and the use of a linked list to overcome size limitations. Lastly, it covers the syntax-directed translation scheme for flow-of-control statements.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Here is the bottom-up parse of the assignment statement a = b-c + b-c** and the syntax-directed translation into three-address code.
Parser action attribute Three- address code id=id โ โid + id โ โid id=E1 โ โid + id โ โid E1.place = b id=E1 โ โE2 + id โ โid E2.place = c id=E1 โ E2 + id โ โid E2.place = t1^ t1 = โ c id=E1 + id โ โid E1.place = t2^ t2 = bโt id=E1 + E2 โ โid E2.place = b id=E1 + E2 โ โE3 E3.place = c id=E1 + E2 โ E3 E3.place = t3^ t3 = โ c id=E1 + E2 E2.place = t4 (^) t4 = bโt id=E1 E1.place = t5 t5 = t2+t S a = t
Representing Linear Codes
Three-address codes are often implemented as a set of quadruples. Each quadruple has four fields: an operator, two operands (or sources) and a destination. In C++, for example, one can design a quadruple class and then declare a simple array of quadruples. This leads to the following arrangement; the index of the array element acts as the number of quadruple generated.
Target Op Arg1 Arg t1 โ 2 t2 โ y t3 (^) ร t1 t t4 โ x t5 โ t4 t
An array of pointers to quads can be employed which leads to the following structure:
Both simple array and array of pointers have maximum size limitation. This limitation can be overcome by using a linked list of quads:
Flow-of-Control Statements
We now use the syntax-directed translation scheme for the flow-of-control statements found in most procedural programming languages.
S โ if E then S 1 | if E then S 1 else S 2 | while E do S 1
where E is a boolean expression. Consider the statement
if c < d then x = y + z else x = y โ z
-^ t^1 โ^2 -^ t^2 โ^ y