ANTLR 4 Integration in a C ++ Application

I recently took a copy The Definitive ANTLR 4 Reference, and since I'm sophisticated when it comes to working with grammars and languages ​​that I would like to use on my DSL, I somehow wrote using yaccand bison. The general idea is to write a translator (including an included security check of type (1) ) that translates the DSL into JavaScript at runtime, which is then run by v8.

Although ANTLR was intended to be included in Java applications, I would like to stay with native C ++. Can ANTLR 4 create such a C-parser / lexer (2) that I can include in the C ++ style shell? And how to do it?


(1) There are some good examples in the book that I will use as a template.
(2) I'm not sure, but I think I read somewhere that ANTLR does not support output in C ++, am I right?

+5
source share
4 answers

ANTLR v3 has different goals, primarily Java (of course), C, C #, JavaScript and Python. The full list is below: http://www.antlr.org/wiki/display/ANTLR3/Code+Generation+Targets

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

+3
source

ANTLR 3 C/++ . , C, . , , ANTLR 4 , , . ANTLR 2 ++ , ANTLR 3, ANTLR 2 , ( ).

+8

, 4.7 antlr ++.

+3

.

  • , ANTLR3 C . , C/++ 20 , , . , , .

  • , . ANTLR2 ++ fir v2 ... , , . v3 , ...

  • . ANTRL2 ANTLR3 Valentina, v3 ... . . , v2 ANTLR.

  • I think the main problem if the speed in ANTLR is that a separate function is created for each rule. Yes, this is his strong point, and this is her weak point.

In v4 Terrence came up with how to use the end machines in Lexer. If we could get this for parsers as well. I think that ideally ANTLR can create functions as it is now, while we are developing grammar and state machines for release. But this is still a dream.

+1
source

All Articles