The Gateway to Computer Science Excellence
0 votes
459 views
Consider four programming languages viz. C, C++, C# and JAVA and three machines which have different configuration (such as OS, hardware). If someone needs to write a compiler for the above mentioned languages and machines, then the number of compilers required with and without intermediate code phase are --------- and ------ respectively.
in Compiler Design by Active (3.1k points) | 459 views

2 Answers

0 votes
While generating machine code directly from source code is possible, it entails two problems With m languages and n target machines, we need to write m front ends, m × n optimizers, and m × n code generators

The code optimizer which is one of the largest and very-difficult-to-write components of a compiler, cannot be reused

By converting source code to an intermediate code, a machine-independent code optimizer may be written T

This means just m front ends, n code generators and 1 optimizer

 

nptel
by Active (3.8k points)
0
but your answer is not correct, answer is 7 and 12.....please help me if you get the answer
0
machine-independent code optimizer - is it language independent too?
0 votes
If we generate machine code directly from source code (without intermediate code ) then for 4 languages and 3 machines we need to write 4 front ends , 4*3 code optimizers and 4*3 target code generators.

By converting source code to intermediate code a machine independent code optimizer may be written. So we require only 4 front ends + 1 code optimizer + 3 target code generator.

Please notice  4*3 target code generators are required but with intermediate step (as machine independent code optimizer are there) we require only 4 front end + 3 target code generator.

So with intermediate code we require (4+3) = 7 compiler bt withour intermediate code we need (4*3)=12 compiers
by Active (3k points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,647 questions
56,492 answers
195,439 comments
100,708 users