in Compiler Design retagged by
355 views
0 votes
0 votes

The following grammar $\text{G}$ is left recursive.

  • $\text{E} \rightarrow \text{E + T}\; \mid \; \text{T} $
  • $\text{T} \rightarrow \text{T * F} \; \mid \; \text{F} $
  • $\text{F} \rightarrow \text{(E)} \mid \textbf{id} $

Which of the following is a correct left-recursive variant of $\text{G}$?

  1. $\text{E} \rightarrow \text{E}’\text{T} \\ \text{E}' \rightarrow \text{+TE}’ \mid  \epsilon \\ \text{T} \rightarrow \text{T}’\text{F} \\ \text{T}' \rightarrow \text{*FT}’ \mid \epsilon \\ \text{F} \rightarrow \text{(E)} \mid \textbf{id} $

 

  1. $\\ \text{E} \rightarrow \text{TE}' \\ \text{E}' \rightarrow \text{+TE}’ \mid  \epsilon  \\ \text{T} \rightarrow \text{FT}' \\ \text{T}' \rightarrow \text{FT}’* \mid \epsilon \\ \text{F} \rightarrow \text{(E)} \mid \textbf{id} $

 

  1. $\text{E} \rightarrow \text{TE}' \\ \text{E}' \rightarrow \epsilon \mid \text{TE}' \\ \text{T} \rightarrow \text{FT}' \\ \text{T}' \rightarrow \text{*FT}’ \mid \epsilon \\ \text{F} \rightarrow \text{(E)} \mid \textbf{id} $

 

  1. $\text{E} \rightarrow \text{TE}' \\ \text{E}' \rightarrow \text{T + E}' \\ \text{T} \rightarrow \text{FT}' \\ \text{T}' \rightarrow \text{F* + T}' \\ \text{F} \rightarrow \text{(E)} \mid \textbf{id} $
in Compiler Design retagged by
by
355 views

1 Answer

0 votes
0 votes
T--->FT`

T`-->*FT`|{

F-->(E)|id

E-->TE`

E`-->+TE`|{

would be right as E-->T+E` would run infinitely
Answer:

Related questions