[Haskell-beginners] Parsing 'A's and then ('A's or 'B's)
Francesco Ariis
fa-ml at ariis.it
Wed Jan 27 12:48:55 UTC 2016
On Wed, Jan 27, 2016 at 01:34:29PM +0100, Ulrik Rasmussen wrote:
> The language is recognized by a relatively simple DFA (attached), so the
> simplest solution (I think) is to just encode that:
>
> module Main where
>
> import Text.Parsec
> import Text.Parsec.String
>
> p :: Parser ()
> p = char 'A' >> ((char 'A' >> sA) <|> (char 'B' >> sB))
> where
> sA = (char 'A' >> sA) <|> (char 'B' >> sB) <|> return ()
> sB = (char 'B' >> sB) <|> return ()
I am probably missing something: say we have an "AAB" string, how does
this check that it is `compatible` with [x,y] or [x,x,y] or [x,y,y]
(or not compatible with [x,x,x], etc.)?
More information about the Beginners
mailing list