2,152 views
0 votes
0 votes
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.

2 Answers

1 votes
1 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
0 votes
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

Related questions

0 votes
0 votes
2 answers
1
bts1jimin asked Jan 12, 2019
572 views
Answer is 6,6Can anybody explain how?
1 votes
1 votes
1 answer
2
Markzuck asked Jan 8, 2019
760 views
someone please share detailed rules for this along with solution- would be of great help.and we usually dont take start and end state- arent they extra here? coz count co...