Search code examples
grammarbnf

BNF grammar matching


My teacher has given me two bnf grammars:

A ::= 'd' | A 'e' A | A 'f' A
B ::= 'd' | B B 'e' | B B 'f'

and four strings to match with them:

  • dffd
  • dddefddfe
  • dedf
  • deded

I've figured out two of them, but the other two have me stumped. I don't want anyone to tell me the answers, but if someone could give me some hints as to where I'm going wrong it would be much appreciated.


Solution

  • Hmmm...

    By induction, all matches must have an odd number of characters. So neither of the 4 character strings can be a hit...


    Oh wait. I just noticed the 'Y' in the first rule. Do we know what that is? It could break my argument right open...