woodtluk
woodtluk

Reputation: 963

Parsing binary data

I got interested in parser generators. But I don't have the theoretical background. I just read a few things on the internet.

Currently I'm trying to do something with ANTLR

So my questions:

I have a special format of my dataframes:

I hope my description is clear. My questions:

Can I create such a parser with ANTLR that reads the lengs of the frame and then knows when the frame ends?

In ANTLR can I load the different tags I use from a generated file?

Thank you!

Upvotes: 1

Views: 737

Answers (2)

AndersK
AndersK

Reputation: 36092

I think you will be better off to create a hand written binary parser instead of using ANTLR because ANTLR is primarily intended to read and make sense of a text file and not binary data. The lexer part is focused on tokenizing text so trying to make it read binary data instead would be an uphill battle.

It sounds as if your structure would need some kind of recursive way of reading the data although it could be done easier just having a tree structure and then fill it as you read your file.

Upvotes: 1

jakob
jakob

Reputation: 227

I'm not 100% sure about this, but:

  • Parser generators like antlr require a grammar that is at least context-free
  • using length-fields in your data makes your grammar not context free (context-sensitive i think)

It is the latter point i'm not sure about - maybe you want to research some more on that.

You probably have to write a packet "parser" yourself (which then has to be a parser for your context-sensitive packet grammar)

Alternatively, you could drop the length field, and use something like s-expressions, JSON or xml; these would be parseable by something generated with antlr.

Upvotes: 0

Related Questions