Spread Knowledge

CS606 - Compiler Construction - Lecture Handout 38

User Rating:  / 0

Related Content: CS606 - VU Lectures, Handouts, PPT Slides, Assignments, Quizzes, Papers & Books of Compiler Construction

Three-Address Statement Types

Prior to proceeding with flow-of-control construct, here are the types of three-Address statements that we will use

  • Assignment statement
    x = y op z
    op is a binary arithmetic or logical operation
  • Copy statement
    x = y
    value of y is assigned to x

  • Unconditional jump
    goto L
    The three-address statement with label L is executed next
  • Conditional jump
    if x relop y goto L
    relop is <, =, >=, etc. If x stands in relation relop to y, execute statement with label L, next otherwise
  • Indexed assignment
    • x = y[i]
    • x[i] = y
      In a), set x to value in location i memory units beyond location y.
      In b), set contents of location i memory units beyond x to y.

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

syntax-directed translation