# Which Type of Grammar is this?

I am learning Compiler Design. Can somebody explain what type of Grammar this is? The answer given is $LL(1)$ but there exists a left recursion in the grammar so it cannot be $LL(1)$. I derived the parse table it had conflicts. Am I doing some thing wrong or is the answer given wrong?

My texbook defines:

For LL(1) Grammar if there is left recursion or left factoring then that grammar is not LL(1) grammar if this applies to this grammar then it is not a LL(1) grammar

$E \to E+T \mid E$

$T \to T$#$F \mid F$

$F \to (E) \mid i$

I also have one more question: "Is there a Grammar which can be LL(1) but not LALR(1)"

• Are you sure you copied the answer correctly? You can never get rid of $E$. Which book are you using? As for your second question (try to ask only one per post, please!), it's been answered in our reference answer. – Raphael Feb 11 '14 at 7:25

## 2 Answers

There is left recursion in the grammar, so it isn't $LL(1)$.

The set of $LL(1)$ grammars is a proper subset of the $LR(1)$ grammars, see for example this summary, which incidentally also shows that $LL(1)$ isn't a subset of $LR(0)$. The first part is is intuitively easy to see, the $LL(k)$ parser has to decide looking only at the $k$ first symbols; the $LR(k)$ has the whole left hand side (and $k$ extra symbols) at its disposal.

If you want to test the grammer is LL(1).

First if you have left recursion it must be solve it .

Then the new output you want to calculate the first and follow to draw the table .

Then check if you don't have multiple entry in the table so this grammer is LL(1) else is not LL(1). Note in your grammer may be have error in writting it. plz check it.

E→E+T∣T

T→T#F∣F

F→(E)∣i

• What you have done is correct for the grammar which you considered while solving. but the grammar is not what i have mentioned. Thanks for looking into it. – Nikhil Mahajan Feb 12 '14 at 3:17