Parsec: Parenthesized expressions and more!

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

Vimal wrote:
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 ()
I would indent "<|> return ()" a bit less: ... parens <|> return () Use "parens >> eof" to test for full string consumption. C.
participants (2)
-
Christian Maeder
-
Vimal