[Haskell-cafe] Parsec: Parenthesized expressions and more!
Vimal
j.vimal at gmail.com
Tue Aug 14 04:42:33 EDT 2007
Hi
I was trying out some parsing with parsec. I tried:
Accepting proper parenthesized expressions, this was the
code:
parens :: Parser ()
parens = do
char '('
parens
char ')'
parens
<|> return ()
Implementing basically: S -> (S)S | e.
I doubt the fact that 'e' was actually considered, because
the program seems to be accepting all strings of the form
())*. Did I go wrong somewhere? I guess this could be because,
the input was "partially" accepted. Can I force it to derive the
entire input string?
And, btw, is there a method to implement an epsilon production?
I tried
do { string "" ; rules ... }
And it didn't seem to work.
I am also trying out this problem just for fun, but I seem to be getting
wrong answers! http://spoj.pl/problems/FOOL
Maybe I implemented something wrong. So, i will wait for some comments
on the above parsing, and try one more time before I ask questions on that :D
Cheers
--
-- Vimal
Department of Computer Science and Engineering
Indian Institute of Technology Madras
More information about the Haskell-Cafe
mailing list