Related Content: CS606 - VU Lectures, Handouts, PPT Slides, Assignments, Quizzes, Papers & Books of Compiler Construction
Prior to proceeding with flow-of-control construct, here are the types of three-Address statements that we will use
We associate with a boolean expression E two labels (attributes); E.true and E.false. The
control flows to E.true if the expression evaluates to true, to E.false otherwise.
Following is syntax-directed translation for
S → if E then S1
E.true = newlabel()
E.false = S.next
S1.next = S.next
S.code = E.code || gen(E.true ‘:’) || S1.code
The attribute “next” records the label of the next statement to execute. “code” is string-valued attribute that holds the actual code generated in the form of a character string. The code can be eventually written out to a file. The || is the string concatenation operator, that is “hello”|| “ world” will yield the combined string “hello world”.
Suppose E is “a < b”. E.code would be
if a < b goto E.true
goto E.false
We will discuss semantic rules for boolean expressions shortly
The syntax-directed translation for