Compiler Design Important Questions — 3

Ashish Patel
Codebrace
Published in
2 min readOct 19, 2016
  1. What are the benefits of intermediate code generation?
  • A Compiler for different machines can be created by attaching different back end to the existing front ends of each machine.
  • A Compiler for different source languages can be created by proving different front ends for corresponding source languages t existing back end.
  • A machine independent code optimizer can be applied to intermediate code in order to optimize the code generation.
  1. What are the various types of intermediate code representation?

There are mainly three types of intermediate code representations.

  • Syntax tree
  • Postfix
  • Three address code
  1. Define backpatching.

Backpatching is the activity of filling up unspecified information of labels using appropriate semantic actions in during the code generation process.In the semantic actions the functions used are mklist(i),merge_list(p1,p2) and backpatch(p,i)

  1. Mention the functions that are used in backpatching.
  • mklist(i) creates the new list. The index i is passed as an argument to this function where I is an index to the array of quadruple.
  • merge_list(p1,p2) this function concatenates two lists pointed by p1 and p2. It returns the pointer to the concatenated list.
  • backpatch(p,i) inserts i as target label for the statement pointed by pointer p.
  1. What is the intermediate code representation for the expression a or b and not c?

The intermediate code representation for the expression a or b and not c is the three address sequence

t1 := not c

t2 := b and t1

t3 := a or t2

  1. What are the various methods of implementing three address statements?

The three address statements can be implemented using the following methods.

  • Quadruple : a structure with atmost four fields such as operator(OP),arg1,arg2,result.
  • Triples : the use of temporary variables is avoided by referring the pointers in the symbol table.
  • Indirect triples : the listing of triples has been done and listing pointers are used instead of using statements.
  1. Give the syntax-directed definition for if-else statement.
    S → if E then S1

E.true := new_label()

E.false :=S.next

S1.next :=S.next

S.code :=E.code | | gen_code(E.true ‘: ‘) | | S1.code

S → if E then S1 else S2

E.true := new_label()

E.false := new_label()

S1.next :=S.next

S2.next :=S.next

S.code :=E.code | | gen_code(E.true ‘: ‘) | | S1.code| | gen_code(‘go to’,S.next) | |gen_code(E.false ‘:’) | | S2.code

--

--

Ashish Patel
Codebrace

Big Data Engineer at Skyscanner , loves Competitive programming, Big Data.