Data structure generator and parser for a BNF protocol

Status
Not open for further replies.

levine

Ars Tribunus Militum
1,986
I have a protocol that's specified as an ABNF grammar. It describes a "message" of composite parts. I want to provide that BNF_spec.txt as input to <something>, and get as output:
  • Protocol.h[pp], containing a data structure in C or C++ that represents that "message": struct ProtocolMessage { ... };
  • Protocol.c[pp], containing a function to parse an input buffer and return a valid "message" structure: ProtocolMessage_t parse(char *buffer, size_t len) { ... }
The utility asn1c does exactly this for ASN.1 protocols. Unfortunately I haven't been able to find something similar for xBNF.

The flex/bison toolchain has me arse-deep in converting the grammar I have into the grammar it wants. Even if I were to slog through that nightmare, I'm still left with building the data structure myself, and then fiddling with manual memory management to fill it. And then, debugging the errors I'll inevitably (unknowingly) inject into the bison grammar would be nigh-impossible. No thanks. Antlr wants me to install forty Java build tools just to get it running, which is a long road I don't want to start going down if I can in any way avoid it. I can write a recursive descent parser myself from scratch, which I've done before for other similar protocols, but it's long and boring work that I sense can be avoided.

What are my options, here?
 

levine

Ars Tribunus Militum
1,986
Both Gold and Antlr help me avoid fucking up the xBNF-to-whatever translation, but (as far as I can tell, and correct me if I've got it wrong) they're not fundamentally different tools than flex/bison: I still have to rewrite the grammar, write action rules, manually build the structure, fill it, etc. If I'm going to do that I'll go the whole 9 yards and just write a parser manually; at least that way I'm just debugging straight C++ when I invariably get something wrong.

I'm looking for an entirely different class of utility. Which may or may not exist.
 
why write it manually when the fucking tool will do it for you. jesus, go back and look at gold. it fills in the structures for you already you just have to walk the fucking tree.

and no they are not fundamentally different from flex/bison coz you know what? they are all parser generators, holy cow, they are all the same kind of tool!

if you write the rules, gold will fill the structure for you.

Seems like you want a magic wand to do everything for you, so good luck, let me know when you find it, I could do with a magic wand too.
 
Status
Not open for further replies.