How to make a context free grammar for a particular case -
the problem this
create cfg generates {a^i b^j: 2i < j + 2 < 3i}. problem there way many cases here. example not work j=1,2,4. j=5,6,7,8,9 need have i=3,3,4,4,4. how handle this, there tricks doing stuff or making harder looks.
you're making harder is.
coming grammars classic recursive analysis technique. recursion, need ask 2 questions: how next step? how know when i'm done?
the second question easy: you've figured out base case aabbb
(that is, i=2, j=3
). no shorter word can part of grammar.
now, suppose have longer word, means i
must greater 2. how next step? in other words, how find shorter valid word? can remove a
(decrement i
), need fix j
. inequalities, it's clear j
can decremented either 2 or 3 (it's possible both work, 1 of 2 must work).
that result in ambiguous grammar, question doesn't grammar needs unambiguous. however, it's easy come unambiguous grammar, based on strategy of resolving decision (two or three) in same direction, if both answers possible.
Comments
Post a Comment