0

I have a grammar rules like that;

S -> S and S
S -> S or S
S -> (S)
S -> true | false

-- and , or , ( , ) , true ,false are terminals -- 

I can find out that this grammar is ambiguous, but how can I modify this grammar to solve the ambiguity?

svick
  • 236,525
  • 50
  • 385
  • 514
ccca
  • 75
  • 2
  • 11

1 Answers1

1

The standard approach is to give them precedence/associativity:

S -> S or  A | A
A -> A and P | P
P -> (S)
P -> true | false
user541686
  • 205,094
  • 128
  • 528
  • 886