in Compiler Design retagged by
14,268 views
26 votes
26 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 by
by
14.3k views

4 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
great insight  ..Thanks
0
0

4 Answers

25 votes
25 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

2 Comments

Can someone provide a detail reason for statement 2
1
1
The first statement is not entirely accurate. The symbol table is accessed during different phases of a compiler, including lexical analysis, syntax analysis, semantic analysis, and code generation. It is used to store information about identifiers, such as variable names and their attributes, throughout the compilation process.

Ⅱ. The second statement is true. Compilers for programming languages that support recursion typically need heap storage for dynamic memory allocation during the run-time environment. Recursive function calls create a stack of activation records, and heap memory is often used for dynamic memory requirements.

Ⅲ. The third statement is not true. Errors violating the condition "any variable must be declared before its use" are detected during semantic analysis, not syntax analysis. Syntax analysis primarily focuses on the grammatical structure of the program, while semantic analysis checks for meaningfulness and correctness of the program, including variable declarations and usage.
0
0
13 votes
13 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
0 votes
0 votes

None of the statements are true.

  • Symbol table is a data structure used by compilers to store information about the variables, functions, and other entities in a program. It is accessed during both lexical analysis and syntax analysis, but may also be used by later stages of the compilation process, such as code generation.
  • Compilers for programming languages that support recursion may or may not need heap storage for memory allocation in the run-time environment. The decision to use heap storage or not depends on the specific implementation of the compiler and the features of the programming language.
  • Errors violating the condition 'any variable must be declared before its use' are typically detected during the semantic analysis phase of compilation, not during syntax analysis. Syntax analysis checks the structure of the program to ensure it follows the rules of the programming language's grammar, while semantic analysis checks the meaning of the program to ensure it is semantically correct.
Answer:

Related questions