
On 2016-01-27 13:48, Francesco Ariis wrote:
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.)?
Oh, I read Simon's question as being constrained to the specific problem [x, y] (i.e. recognizing AA*(AA* + BB*)). If the problem is to run any list of parsers such as [x,y,x,x], then this won't work.