Integrating ANTLR 4 in a C++ application

后端 未结 4 1070
误落风尘
误落风尘 2021-01-05 09:40

Recently I picked up a copy of The Definitive ANTLR 4 Reference and since I am sophisticated when it comes to working with grammars and languages I wanted to wo

相关标签:
4条回答
  • 2021-01-05 10:13

    ANTLR v3 has various different targets, most notably Java (of course), C, C#, JavaScript and Python. For a full list, see: http://www.antlr.org/wiki/display/ANTLR3/Code+Generation+Targets

    ANTLR v4, however, only has a Java target at this moment.

    0 讨论(0)
  • 2021-01-05 10:16

    In case you are still interested, version 4.7 of antlr does have a c++ target.

    0 讨论(0)
  • 2021-01-05 10:24

    I found the ANTLR 3 C/C++ target almost unusable. It contains so many hacks to circumvent the lack of exceptions in C that it was recommended for experts only. Though it's Terr's call, I hope ANTLR 4 doesn't support target languages without native exceptions unless it can isolate whatever hackery is required to do so from end users. The ANTLR 2 C++ target is cleaner than ANTLR 3's, but ANTLR 2 itself has limitations, including extremely messy licensing (making it difficult to use in commercial products).

    0 讨论(0)
  • 2021-01-05 10:34

    To John G. answer

    • I agree that ANTLR3 C target is very hacking. Me, C/C++ expert with 20 years, was not able even guess how to use it without answers from author. Yes, ideas was quite good, but without docs near to impossible to understand.

    • I not agree that main trouble with exceptions. In times of ANTLR2 and C++ implementation fir v2, exceptions did exists ... And there was opinion that if to remove exceptions it will be faster. In v3 they have try do that, but ...

    • But speed have not became better. We was in hope switch from ANTRL2 to ANTLR3 in our Valentina Database engine, we have spend months re-writing to v3 grammar, and ... zero speed up. Just zero. So we use up to now v2 of ANTLR.

    • I think main issue if speed in ANTLR is the fact that for each rule it produce separate function. Yes this is its strong side, and this is its weak side.

    In the v4 Terrence have invent how to use state machines in Lexer. If we could get that for parsers also. I think in ideal, ANTLR could produce functions as now, while we develop grammar, and state machines for release. But this is a dream so far.

    0 讨论(0)
提交回复
热议问题