Re: Exercise 2.1.2 from Aho&Ulman The theory of Parsing textbook?



In article
<0a72f6c4-1337-4884-bb1c-a205b1fef1a3@xxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Tegiri Nenashi <TegiriNenashi@xxxxxxxxx> wrote:

"Construct CFG that generates all strings having equal number of a's
and b's"

My attempt:

X = 1 + aXa + aaX +Xaa + bXb + Xbb +bbX +YY
Y = 1 + (a+b)Y

looks too complicated for such concise problem statement. Any shorter
solution?

The difficulty isn't that it's too complicated, but that it's wrong.
Your Y can be any string of a's and b's; the "YY" alternative in X does
*not* mean that the same Y string is replicated, but rather that 2
independent Y strings are concatenated. So, your X grammar will accept
*any* string of a's and b's (e.g., with the first Y being empty, and the
second being any string of a's and b's).

--
---------------------------
| BBB b \ Barbara at LivingHistory stop co stop uk
| B B aa rrr b |
| BBB a a r bbb | Quidquid latine dictum sit,
| B B a a r b b | altum viditur.
| BBB aa a r bbb |
-----------------------------
.



Relevant Pages

  • Re: 1st and 2nd.... positions
    ... It took your posting the idea of searching a string for the correct position to give me a nudge. ... Can the shorter main text string in the second formula really add significantly to the efficiency of performing the MID function call that it can compensate for the extra function call? ...
    (microsoft.public.excel.misc)
  • Re: Replacement Strat Machineheads
    ... > Two are the same lengths as the original tuners and four are shorter - ... > especially on the D string. ... > four shorter tuners were for the strings that go via the trees with the ... string angle for the higher 4 strings and eliminate the string trees for a ...
    (rec.music.makers.guitar)
  • Re: Collation....
    ... If you use varying-length (varchar or nvarchar), ... on comparison the shorter string will be padded to ...
    (microsoft.public.sqlserver.programming)
  • Re: code for Computer Language Shootout
    ... > mainisn't useful for this very short loop, and you can use shorter ... import string, itertools, sys ... reverse, and format the string. ...
    (comp.lang.python)
  • Re: The best, (right?), way to trim a char*
    ... >> Good you give us an example of shorter code. ... there is no need to check against npos because the ... > return String; ... the TrimLeft function you originally provided didn't handle the empty ...
    (comp.lang.cpp)