0
votes

I am new to antlr.

Can somebody provide a working example for any simple grammar in antlr for C++ target. I tried antlrworks and created the lexer and parser. But am not able to proceed while getting it compiled. Searched in codeproject also for a working sample, but dint find any.

I am planning to use Visual Studio 2013. Thanks in advance...

2

2 Answers

0
votes

I've used ANTLR3 in a C++ application for years already, but actually used the C target, not C++. The latter proved to be a problem both in terms of compilation speed (for a highly complex parser) and complexity (all based on templates). So I settled on the C target, which is easy to integrate into C++ application. You only need a small C++ wrapper for your app and you will get a really fast parser.

0
votes

In case of C++ target try this branch: https://github.com/ibre5041/antlr3/tree/master/runtime/Cpp/tests. This is more up to date version, including various performance bug fixes, memory leak fixes and also AST generation.

In the tests directory you find some examples.

  • Now I'm not sure whether it will work with MSVC 2013, I recall I used some C++11.
  • It would be best if you compiled the whole tool from these sources, not only the runtime is different, but also generated source codes slightly differ.
  • No not use Java 8 to compile and run antlr tool. For some mysterious reason JRE8 generates different sources then JRE7, when using the same tool .jar.
  • When having your grammar compiled (sources are generated), then you have to create, a traits class to be used as "configuration" for generated sources.