• retagged by
17,728 views
26 26 votes

Which one of the following statements is $\text{TRUE}?$

  1. The $\textit{LALR}(1)$ parser for a grammar $\textit{G}$ cannot have reduce-reduce conflict if the $\textit{LR}(1)$ parser for $\textit{G}$ does not have reduce-reduce conflict.
  2. Symbol table is accessed only during the lexical analysis phase.
  3. Data flow analysis is necessary for run-time memory management.
  4. $\textit{LR}(1)$ parsing is sufficient for deterministic context-free languages.

3 Answers

Best answer
32 32 votes

Answer D

$\text{Option A}$

Connsider a LR(1) DFA with no RR Conflicts. Take two states, say, I3 and I5 in such LR(1) DFA.

I3 :  $[A \rightarrow \alpha.\color{red}{, a}, B \rightarrow \beta.\color{blue}{, b}]$ and

I5: $[A \rightarrow \alpha.\color{blue}{, b}, B \rightarrow \beta.\color{red}{, a}]$

Since the core items are same, we will merge $I_3$ and $I_5$ in LALR, say merged state is $I_{35}$

$I_{35}$ :  $[A \rightarrow \alpha.\color{red}{, a}\color{blue}{, b} \text{  } B \rightarrow \beta.\color{red}{, a}\color{blue}{, b}]$ 

A common confusion: $I_{35}$ has RR conflict on $a \text{ and } b$.​

$\text{Do } I_{35} \text{ really has any conflict? }$ –  Yes.

See one example – here

 

$\text{Option B}$

Symbol table is accessed among all phases. For example – “int x”, here lexical analyzer will assign 2 tokens, but lexical  analyzer won’t know whether x is of type int since it reads int and x as two different tokens. Syntax analyzer will feed type of x to symbol table.

C. It is optional

D. LR(1) = DCFL Ref: https://cs.stackexchange.com/questions/43/language-theoretic-comparison-of-ll-and-lr-grammars

• selected by
0 0 votes

A. The LALR(1) parser for a grammar G cannot have reduce-reduce conflict if the LR(1) parser for G does not have reduce-reduce conflict.

❌ False

  • LALR(1) is obtained by merging LR(1) states that have the same LR(0) core.

  • When states are merged, their lookahead sets are combined.

  • This merging can introduce new conflicts, including reduce–reduce conflicts, even if the original LR(1) parser had none.

✅ Hence, LR(1) being conflict-free does not guarantee LALR(1) will be conflict-free.


B. Symbol table is accessed only during the lexical analysis phase.

❌ False

The symbol table is used in multiple phases, such as:

  • Lexical analysis (installing identifiers)

  • Semantic analysis (type checking, scope checking)

  • Intermediate code generation (addresses, types)

  • Optimization / Code generation (storage locations)

✅ Hence, it is not limited to lexical analysis.


C. Data flow analysis is necessary for run-time memory management.

❌ False

  • Run-time memory management (stack allocation, heap management, garbage collection) is mainly handled by the runtime system and compilation strategy.

  • Data flow analysis is primarily used for compile-time optimizations, such as:

    • dead code elimination

    • reaching definitions

    • liveness analysis (used for register allocation, not runtime memory allocation)

✅ Hence, it is not necessary for runtime memory management.


D. LR(1) parsing is sufficient for deterministic context-free languages.

✅ True

  • Deterministic context-free languages (DCFLs) are exactly the class of languages accepted by deterministic pushdown automata (DPDA).

  • It is a known result in compiler theory that LR(1) parsers can parse all deterministic CFLs.

  • Therefore, LR(1) parsing is sufficient for deterministic context-free languages.

0 0 votes

IN CONTINUATION WITH SACHIN'S ANSWER

Anyone who is having difficulty in option c this might help you 

refering to the dragon book 

the term necessary is wrong here 

Data Flow Analysis supports global optimization technique 

and the code optimization could have been done through local optimization techniques 

or even no code optimizatio could have been done still that wont be an issue 

 

now coming onto the second point 

the data flow analysis is perfomed at compile time  and not at runtime so this adds on to  being this statement incorrect 

 

coming to the third point 

runtime memory management is written here but it is not the case here dataflow analysis involves liveliness analysis which helps in  register aloocation and not the same as run-time memory management

• edited by
Answer:
Position:
Show:

Related questions

22 22 votes
3 answers 3 answers
16.9k
16.9k views
Arjun asked Feb 15, 2022
16,857 views
Consider the augmented grammar with $\{ +, {\ast}, (,),\text{id} \}$ as the set of terminals.$S’ \rightarrow S$$S \rightarrow S + R\; |\; R$$R \rightarrow R {\ast} P \;| ...
1 1 vote
2 2 answers
900
900 views
admin asked Oct 23, 2022
900 views
Consider the following statements:Statement $\text{I}$: $\text{LALR}$ parser is more powerful than canonical $\text{LR}$ Parser.Statement $\text{II}$: $\text{SLR}$ parser...
1 1 vote
1 1 answer
1.3k
1.3k views
soujanyareddy13 asked Apr 12, 2022
1,270 views
Which of the following statements about the parser is/are correct?Canonical $\text{LR}$ is more powerful than $\text{SLR}.$$\text{SLR}$ is more powerful than $\text{LALR}...
25 25 votes
5 answers 5 answers
15.3k
15.3k views
Arjun asked Feb 7, 2019
15,289 views
Which one of the following kinds of derivation is used by LR parsers?LeftmostLeftmost in reverseRightmostRightmost in reverse