7

I have a yacc grammar that I want to convert to ANTLR. Is there any Bison to
ANTLR converter available? Can someone help?

Thanks, Prasanth

Prasanth
  • 101
  • 2
  • 5
  • An interesting read about the problems with your task is [this question and its answers](http://stackoverflow.com/questions/212900/advantages-of-antlr-versus-say-lex-yacc-bison). – DarkDust Aug 07 '14 at 09:39
  • 1
    @DarkDust Note that the accepted answer of that question is outdated, as ANTLR v4 can handle left-recursion. – Lucas Trzesniewski Aug 07 '14 at 09:43

1 Answers1

4

Let's compare these parser generators:

  • ANTLR v4 is an ALL(*) parser generator, a variant of LL(*)
  • Yacc is a LALR parser generator.
  • Bison is a LALR/GLR parser generator.

LL and LALR are incompatible:

The LALR(k) parsers are incomparable with LL(k) parsers: for any j and k both greater than 0, there are LALR(j) grammars that are not LL(k) grammars and conversely. In fact, it is undecidable whether a given LL(1) grammar is LALR(k) for any k > 0.

GLR is a variant of LR. An LR parser is a bottop-up parser, while an LL parser is a top-down parser. Those are fundamentally different parsing strategies.

Conclusion: you won't find any reliable automatic converter any time soon.

Lucas Trzesniewski
  • 50,214
  • 11
  • 107
  • 158
  • Your answer is basically correct, yet Google turns up this: https://github.com/dowlingw/bison-antlr (whether it's reliable is another matter; and due to LL's inability to cope with left-recursion the grammar to parse needs to be modified first). – DarkDust Aug 07 '14 at 09:38
  • 1
    Interesting. But it looks like it's been made for ANTLR v2, which is pretty old now. – Lucas Trzesniewski Aug 07 '14 at 09:41