5

When I was working in C#, I found the gppg and gplex parser/lexer generators to be perfect for my needs. I'm wondering if there's something similar for the D programming language (i.e. a utility that, given a grammar in BNF or EBNF, outputs D code that lexes/parses that language into a abstract syntax tree).

The closest I've found is Goldie, but I'm having so much trouble understanding it that I'm not able to get anything up and running.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mark LeMoine
  • 4,478
  • 3
  • 31
  • 52
  • 1
    I'm not sure you really want it to output *code*. That was for the C era, when metaprogramming wasn't possible. I think a better choice might be to have it be a template instead, to be instantiated by the user code. – user541686 Jul 05 '11 at 23:00
  • This sounds intriguing, I'll look into it. – Mark LeMoine Jul 05 '11 at 23:33

2 Answers2

2

I have found Goldie pretty awesome for context-insensitive grammars, are you sure about it? Also, http://www.wikiservice.at/d/wiki.cgi?GrammarParsers lists some, no idea which are still developed. If ANTLR-D still works, it is probably on of the best choices.

Mihails Strasuns
  • 3,783
  • 1
  • 18
  • 21
  • 1
    FWIW, the template-based parser listed is mine and it worked under D1 for many cases last time I checked, but that was over a year ago. – BCS Jul 12 '11 at 14:04
1

Goldie is probably your best bet, but there's also ragel which can emit D. It's not exactly what you asked for (composable state machines) though it might suffice for many cases and it's really nice.

Trunk version can compile to D2 code with the undocumented -E switch, I'm not sure yet how mature that is.

http://www.complang.org/ragel/

Lutger
  • 962
  • 1
  • 6
  • 10