954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

LL(1) conflict

Hello everyone,

I'm really struggling with this problem:
Suppose we have the following grammar fragment for a language that allows an assignment to appear in any context in which an expression is expected: the value of the expression is the right-hand side of the assignment, which is placed into the left-hand-side as a side effect.

expr --> id := expr
     --> term term_tail
term_tail --> + term term_tail | e
term --> factor factor_tail
factor_tail --> * factor factor_tail | e
factor --> ( expr ) | id


The question asks to discuss why it is not LL(1) and what can be done to make it so.
I am thinking that there is a left recursion conflict here but I'm really not sure. I can see that in the first line the assignment operator basically assigns expr to itself which causes a conflict. I couldn't figure it out beyond that (and what I figured out is probably wrong as well! :) ).

I am not looking for quick solutions here just a general direction or some informative explanation so that I may better understand this material

Thank you so much for your help!!

ayoitzrimz
Newbie Poster
9 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

An LL(k) language requires k tokens of lookahead to make a decision. How many do you need to decide what kind of expr you have?

Rashakil Fol
Super Senior Demiposter
Team Colleague
2,658 posts since Jun 2005
Reputation Points: 1,135
Solved Threads: 177
 

It's not LL(1) because there would be difficulty in determine which choice to follow if the next token is say "id", because now you have expr --> id := expr or factor --> ( expr ) | id

I would think for the solution to this, you would want to look into left factoring.

sloan31
Junior Poster in Training
65 posts since Apr 2008
Reputation Points: 14
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: