back

by dmitrygr·4mo ago·view on hn ↗
Many parts of this are clearly autogenerated, but that in no way diminishes the sickening impressiveness of it!
3 comments
It would be far more interesting to look at what this was "compiled" from; it looks like the output of a state-machine generator.
The source for BNF generator is here:

https://gist.github.com/alganet/4dfd501a3377a60f7825901114d6...

Roughly 70% of c89cc was generated from it (parser, emitter).

It can generate parsers for C, ES6 and XML for example (subsets but not missing a lot).

It's still a mess though and I have lots of work to do to a proper release.

It does make it a little hard to understand how the parser/ast_builder works.

But the rest seems easy enough to understand.

This is a hand-written parser for the shell itself (portable shell parsing portable shell):

https://gist.github.com/alganet/23df53c567b8a0bf959ecbc7b689...

It's an incomplete idea from around a year ago. The approach taken here (aliases as macro-like evals, AST generation using shell variables) became the backbone for the BNF parser generator.

This one is much simpler to understand. Simpler grammars tend to produce parser code that looks more like this one.

> It does make it a little hard to understand

Or much easier to backdoor...

Yes! The main parser and emitter come from a BNF parser generator, also written in portable shell (to be released though).