Ticker

6/recent/ticker-posts

Compiler Subjective question for competitive exam(1)

Q1.Find first and Follow of grammar S->AaA|BbB A->bB B->null

First of S=First of A U First of B First of A={b} First of B={null} When put null in the place of B where S->BbB get first b So First of S={b}U{b} First of S={b} So First of A={b} First of B={null} First of S={b} Follow of S={$} Follow of A={a}U {Follow of S} So Follow of A={a,$} Follow of B={b}U {Follow of S} U {Follow of A} Follow of B={a,b,$}

Q2.Grammar S->iCtSS'|a S'->eS|null C->b is this grammar is LL(1) or not.

First of S={i,a} First of S'={e,null} First of C={b} Follow of S={$}U First of S'UFollow of S'}={$,e} Follow of S'={Follow of S}={$,e} Follow of C={t} Parsing table a b e i t $ S S->a S->iCtSS' S' S'->eS S'->null S'->null C C->b S'->eS and S'->null multiple entries in same column so grammar is not LL(1).



Q3.Remove left recursion of a grammar. S->Aa|b A->Ac|Sd|e

S->Aa S->b Put the value of S in A A->Ac A->Aad A->bd A->e now remove immediate left recursion S->Aa|b A->bdA' A->eA' A'->cA' A'->adA' A'->null

Q4.List the phases that constitute the front end of a compiler

The front end consists of those phases or parts of phases that depend primarily on the source language and are largely independent of the target machine. These include Lexical and Syntactic analysis The creation of symbol table Semantic analysis Generation of intermediate code A certain amount of code optimization can be done by the front end as well. Also includes error handling that goes along with each of these phases.

Q5.Mention the properties that a code generator should possess.

The code generator should produce the correct and high quality code. In other words, the code generated should be such that it should make effective use of the resources of the target machine. Code generator should run efficiently. Define and use – the three address statement a:=b+c is said to define a and to use b and c. Live and dead – the name in the basic block is said to be live at a given point if its value is used after that point in the program. And the name in the basic block is said to be dead at a given point if its value is never used after that point in the program.



Post a Comment

0 Comments