0

can somebody please help me turn the following grammar to LL(1), and explain how he did it please?

B → B and B | not B | ( B ) | id

i need the not operator to have precedence over the and operator. thank you! edit: my results so far:

B - > Eb'
B' -> andBE'
B" -> epslion (empty)
E -> E'F
E' -> notE'F
E' -> epsilon (empty)
F -> id
F -> (B)
F -> B
mike
  • 767
  • 2
  • 10
  • 18
  • Assuming this is a context-free grammar, try converting to [Greibach Normal Form](https://en.wikipedia.org/wiki/Greibach_normal_form), where the right hand side for the non-terminals (B) all start with different terminals. Hint: you may need to introduce new non-terminals. There are plenty of class notes on the internet that describe how to do this step-by-step. – Evil Dog Pie Nov 14 '16 at 09:19
  • thank you for your answer. i have tried all of those for quite some time, yet i failed. i will add my result – mike Nov 14 '16 at 09:29
  • You're making it more difficult than it needs to be. Start with your alphabet of terminals `{and, not, (, ), id}`. For GNF, the right hand side of each production rule must start with one and only one of these, followed by zero or more non-terminal symbols. Don't worry about epsilon, you don't need it. And don't worry about the operator precedence until you've sorted the basic GNF. – Evil Dog Pie Nov 14 '16 at 09:42

0 Answers0