Lab #10 Solution

$35.00 $29.00

Objective: To augment the mini compiler you have designed with the translation of flow control structures capability. In previous lab, you have designed and implemented a mini compiler consisting lexer, parser, and semantic analyzer, to deal with variable declarations in a block structured language and also augmented the same with the capability. In this lab,…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Categorys:
Tags:

Description

5/5 – (2 votes)

Objective: To augment the mini compiler you have designed with the translation of flow control structures capability.

In previous lab, you have designed and implemented a mini compiler consisting lexer, parser, and semantic analyzer, to deal with variable declarations in a block structured language and also augmented the same with the capability. In this lab, you further enhance your compiler translation of the flow control structures to three address code, as specified below,

  • translation of If, If-else and While to equivalent three address code,

  • generating error if a variable is not declared, and

  • preforming typechecking.

Input : Blocks of C variable declarations, statements containing flow control statements and arithmetic expressions.

Output: three address code and errors if any

Execusion: $./minicc prog.c

1. Testcase:

Input:

{

i n t x , y ;

i f ( x < 1 0 0 )

x = x + 1 0 0 ;

e l s e

y = y + 5 ;

while ( x < 100 | | x > 200 && x != y ) {

x = x + 1 ;

y = x + y ;

}

}

Output:

i f x < 100 goto L1

goto L2

L1 : t 0 = x + 100

x = t 0

goto L3

L2 : t 1 = y + 5

y = t 1

L3 :

L6 :

L7 :

i f x < 100 goto L5

goto L6

i f x > 200 goto L7

goto L4

i f x != y goto L5

goto L4

L5 : t 2 = x + 1

x = t 2

t 3 = x + y

y = t 3

goto L3

L4 :

Lab #10 Solution
$35.00 $29.00