[antlr-interest] Antlr v3 Cannot compile C++ generated grammar

Ivan Brezina ibre5041 at ibrezina.net
Fri Nov 23 19:56:04 PST 2012


On 11/23/2012 11:16 PM, Sebastien Van Cauwenberghe wrote:
> Hi All,
>
> I made a grammar for Antlr v3 C++ and I got lots of compile error regarding
> a non-existing type in the parser...
>
> Below, you will find the "config" part of my grammar and the errors I
> face...
> --------------
>
> grammar ccc;
>
> options
> {
> backtrack = true;
> memoize = true;
> language=Cpp;
> output=Ast;
> }
>
> @lexer::namespace{cccNs}
> @parser::namespace{cccNs}
>
> @lexer::traits
> {
>      class cccLexer;
>      class cccParser;
>      typedef antlr3::Traits< cccLexer, cccParser > cccLexerTraits;
>      typedef cccLexerTraits cccParserTraits;
> }
>
> ---------------------------
>
> In file included from cccParser.cpp:44:0:
> cccParser.hpp:97:9: error: ‘cccParserTraits’ does not name a type
> cccParser.hpp:116:15: error: ‘cccParserImplTraits’ has not been declared
> cccParser.hpp:176:1: error: ‘cccParserImplTraits’ has not been declared
> cccParser.hpp:176:22: error: expected ‘{’ before ‘BaseParserType’
> cccParser.hpp:177:1: error: invalid type in declaration before ‘,’ token
> cccParser.hpp:177:3: error: expected unqualified-id before ‘public’
> cccParser.cpp:125:43: error: invalid use of incomplete type ‘class
> cccNs::cccParser’
> In file included from cccParser.cpp:44:0:
> cccParser.hpp:175:7: error: forward declaration of ‘class cccNs::cccParser’
> cccParser.cpp:135:21: error: expected constructor, destructor, or type
> conversion before ‘(’ token
> cccParser.cpp:150:21: error: expected constructor, destructor, or type
> conversion before ‘(’ token
> cccParser.cpp:157:22: error: invalid use of incomplete type ‘class
> cccNs::cccParser’
> In file included from cccParser.cpp:44:0:
> cccParser.hpp:175:7: error: forward declaration of ‘class cccNs::cccParser’
> cccParser.cpp:157:22: error: ‘StreamType’ was not declared in this scope
> cccParser.cpp:157:34: error: ‘instream’ was not declared in this scope
> cccParser.cpp:172:18: error: invalid use of incomplete type ‘class
> cccNs::cccParser’
> In file included from cccParser.cpp:44:0:
> cccParser.hpp:175:7: error: forward declaration of ‘class cccNs::cccParser’
> cccParser.cpp:179:23: error: invalid use of incomplete type ‘class
> cccNs::cccParser’
> In file included from cccParser.cpp:44:0:
> cccParser.hpp:175:7: error: forward declaration of ‘class cccNs::cccParser’
> cccParser.cpp:207:9: error: ‘cccParserImplTraits’ does not name a type
> cccParser.cpp:210:9: error: ‘cccParserImplTraits’ does not name a type
>
> Did someone have the same problem with the C++ target or did I fail
> something ???
>
> Thank you in advance for your support...
> Cheers
> Sébastien
>
>
So far the option output=AST is not supported by the Gokul's C++ target.

You should also include some header for lexer and parser.
This header should define your traits.

Ivan



More information about the antlr-interest mailing list