Given the following context free grammar:

expr → . . .
      | case expr of match
match → mrule
      | mrule "|" match
mrule → pat "=>" expr
pat → . . .

it's ambiguous because case expr of pat "=>" case expr of pat "=>" expr "|" pat "=>" expr has 2 derivation trees.

How would I make this grammar unambiguous? In general, I don't know how to make cyclic grammars (we can go from expr to mrule and then back to expr, essentially nested case statements) unambiguous. I've tried searching for it online but haven't found much information on it.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.