Showing posts with label parsec. Show all posts
Showing posts with label parsec. Show all posts

Sunday, May 4, 2008

character vs. token based parser in Parsec with haskell

Ok, the first parser did look *ugly*, so I wrote a bit less ugly one, using the token parser. It's not much shorter,
but runs two times faster!


$ time ./packet_template_token >/dev/null

real 0m0.138s
user 0m0.130s
sys 0m0.006s
$ time ./packet_template_char >/dev/null

real 0m0.395s
user 0m0.388s
sys 0m0.005s
$



In case you are interested, both are here

Saturday, May 3, 2008

Packet template parser in Haskell

As part of the dive into Haskell, I've tried out Parsec, which allows a pretty intuitive construction of parsers.

The result is a parser that can consume the packet template file. It does not do anything smart with it beyond some printing.

You can take a look at the two here.

The code leaves a lot to be desired - as I've used the lowest-level character parser.