[Haskell-beginners] Parsing 'A's and then ('A's or 'B's)

Simon Jakobi simon.jakobi at googlemail.com
Sun Jan 24 21:56:31 UTC 2016


Hi Francesco,

Thanks for your response!


>     if I understood your specification correctly, there would be multiple
> ways to parse the string "AAA":
>
>     - 3 'x' elements ("A", "A", "A")
>     - 2 'x' elements ("AA", "A")
>     - 2 'x' elements again (first one shorter) ("A", "AA")
>     - 1 'x' element ("AAA")
>

There would be even more ways because 'y', too, can represent one or more
'A's.

Which of these four should we choose?Maybe "parse as many As as possible
> without consuming the A followed by a series of B"?


I don't think that there could be a general rule.

For the string "AABB" and the sequence of symbols [x, y, y] there would be
two possible parses:

[x: "AA", y: "B", y: "B"]
or
[x: "A", y: "A", y: "BB"].

I only care whether there are any valid parses.

I've just tried to solve the problem with regular expressions (using
pcre-light) and didn't come across the same problem. Is this due to
attoparsec not being able to "backtrack" (not sure if this is the right
term)? Is backtracking something that parsers generally are incapable of?

Cheers,
Simon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160124/d7ff15db/attachment.html>


More information about the Beginners mailing list