Study Notes on Intermediate Code Generation
By BYJU'S Exam Prep
Updated on: September 25th, 2023
Intermediate codes are machine-independent codes, but they are close to machine instructions. The given program in a source language is converted to an equivalent program in an intermediate language by the intermediate code generator.
- The designer of the compiler decides the intermediate language.
- Syntax trees can be used as an intermediate language.
- Postfix notations, three address codes (quadruples) can be used as an intermediate language.
Syntax Tree
Syntax tree is a variant of the parse tree, where each leaf represents an operand and each interior node represent an operator.
A sentence a * (b +d) would have the following syntax tree
Three-Address Code
When each statement contains three addresses (two for operands and one for result), Most general kind of three-address code is
x = yop z
Where x, y and z are names, constants or compiler generated temporaries and op is any operator.
But we can also use the following notation for quadruples (much better notation because it looks like a machine code instruction)
Op y, z, x
Apply operator op to y and z and store the result in x.
Representation of Three-Address Codes
Three-address code can be represented in various forms i.e., quadruples, triples and indirect triples. These forms are demonstrated by way of examples below.
e.g., A = – B*(C +0)
Three address code is as follow
T1 = – B
T2 = C + D
T3 = T1* T2
A = T3
Quadruples
Triples
Indirect triple
You can follow the detailed champion study plan for GATE CS 2022 from the following link:
Detailed GATE CSE 2022 Champion Study Plan
Candidates can also practice 110+ Mock tests for exams like GATE, NIELIT with BYJU’S Exam Prep Test Series check the following link:
Click Here to Avail GATE CSE Test Series!(100+ Mock Tests)
Get unlimited access to 21+ structured Live Courses all 112+ mock tests with Online Classroom Program for GATE CS & PSU Exams:
Click here to avail Online Classroom Program for Computer Science Engineering
Thanks.