in Compiler Design retagged ago by
8,749 views
20 votes
20 votes

Consider the following statements.

  1. Symbol table is accessed only during lexical analysis and syntax analysis.
  2. Compilers for programming languages that support recursion necessarily need heap storage for memory allocation in the run-time environment.
  3. Errors violating the condition ‘any variable must be declared before its use’ are detected during syntax analysis.

  Which of the above statements is/are TRUE?

  1. I only
  2. I and III only
  3. Ⅱ only
  4. None of  Ⅰ, Ⅱ and  Ⅲ
in Compiler Design retagged ago by
by
8.7k views

3 Comments

0
0
edited by

@Arjun @Deepak Poonia @Shaik Masthan sir

Can we implement recursion with just heap memory and not stack memory?

→ recursion needs stack memory. It can be done using heap memory but then we have to stimulate stack in heap memory, which we can easily do..using a linked list.In linked list each node will represent the activation record of function.

is this correct?

0
0

@samarpita Yes, As per my knowledge.

0
0

3 Answers

15 votes
15 votes
Best answer

1. False.

The symbol table is accessed by most phases of a compiler, beginning with lexical analysis, and continuing through optimization.

Symbol table is accessed during other stages also.

Ref: https://en.m.wikipedia.org/wiki/Symbol_table

2. Not essential, any one of heap and stack is enough to support recursion.  Dynamic allocation of activation records is essential to implement recursion. Remember the stack size can also grow dynamical (see C memory layout).

3. Syntax analyser uses CFL which cannot check for this, we need power of Context sensitive language which is available in semantic analysis phase. So this error is detected only during semantic analysis phase.

So D is correct.

selected by

1 comment

Can someone provide a detail reason for statement 2
0
0
12 votes
12 votes
Answer : D

Symbol tables is accessed by Other Phases also , not only by Lexical and Syntax analyses. So, false,

Heap is necessary for recursion, can be done via stack.  So, false

Variable declare before its use must be done by Semantic analyses. So, false,
edited by

4 Comments

I too ticked option C .

has anyone challenged this?
0
0
A recursive program may not have any dynamic variable.

Ex-.   test(int i){

             If(i>0)test(i -1);

}

Note- local variables (like here int i) are kept in Activation record and stored in stack
0
0

pradhanaditya

i think they are asking that   “ is heap necessary for memory allocation in the runtime environment for the activation records to be stored in case of recursion”

so that’s why this statement is false as we can also use stack for the same!!

anything wrong in my reasoning?

 

EDIT: one more thing is there that nowhere in question they mentioned dynamic memory allocation!

0
0
7 votes
7 votes
i) symbol table may be used in other phases.Therefore False.

ii) for recursion we need stack. Therefore False

iii) Syntax analysis can only work on DCFG. variable declared before use wcw is not in DCFG. Therfore false.

option is  D) None of the above

2 Comments

WCW is not even context free. It is Context Sensitive
0
0
But we can use any unambiguous CFG with bottom up parser right.
0
0
Answer:

Related questions