|Binary File parsing with Flex & Bison??? firstname.lastname@example.org (Raghu Kodali) (2005-05-14)|
|Re: Binary File parsing with Flex & Bison??? email@example.com (2005-05-14)|
|From:||firstname.lastname@example.org (Hans Aberg)|
|Date:||14 May 2005 12:18:15 -0400|
|Posted-Date:||14 May 2005 12:18:15 EDT|
"Raghu Kodali" <email@example.com> wrote:
> Can I use Flex & Bison to parse a binary file?
> I know the BNF of the binary file but I dont know how to do it with
> Flex & Bison.
> Can you please let me know if this is possible? if yes, how?
> [Flex is pretty much 8-bit clean, so you can put arbitrary bytes in
> your patterns as \123 or \x42.
Actually, I have started to use Flex to parse UTF-8, by merely feeing
it a UTF-8 .l file, and this seems to work just fine. I use the latest
Flex, available from the CVS at <http://flex.sourceforge.net/>. Older
Flex used to have 7-bit mode, but the later versions seem to have the
8-bit mode as default.
> You might want to check carefully to
> make sure that \000 zero bytes are handled correctly.
There I think Flex is doing the matching correctly. The problem is
that the identifier string is temporarily in the buffer augmented with
a zero byte, and one cannot use C string functions to handle
that. Instead use the yytext and yylen variables, and binary mem...()
The thing one should watch out with Flex is that long rule matches may
slow it down -- the implemented lexer apparently has some buffer
problems. So in order to avoid that, break down rules into shorter
segments, roughly not exceeding the length of lines in text data.
There is a mailing list for Flex available:
Return to the
Search the comp.compilers archives again.