[antlr-interest] ANTLR3C - includes section causes syntax error

lin q linq936 at gmail.com
Fri Nov 2 07:31:05 PDT 2012


I figured out the problem is I need to move the includes section after a
scope declaration:

options
{
     language = C;
}


scope Common_Param_Vec {
   pANTLR3_HASH_TABLE common_params;
}

@parser::includes
{
#include <map>
}

Previously the includes section was before the scope, I cannot see any
mentioning of this requirement at http://www.antlr.org/api/C/atsections.html
.


Could you elaborate the following point - "better to export your c++ fun a
as c linkage and just call functions from the actions." ?

My interpretation is I write my C++ code in another file and it expects
being called by the actions in C of the antlr grammar file; the other point
is I need to use extern "C" to guard my C++ code or at least the part
interfacing with C action code.

If there is no misunderstanding, I wonder what is the advantage here of
using extern C, not I oppose it, just I am not familiar with it. Is there
any antlr3c known issue on C++? Since C++ is superset of C, why not just
treat the whole as C++, action and post-parsing.

Thanks.



On Fri, Nov 2, 2012 at 6:22 AM, Jim Idle <jimi at temporal-wave.com> wrote:

> Read the docs about the other @ sections so you can include in the
> correct place. But better to export your c++ fun a as c linkage and
> just call functions from the actions.
>
> Jim
>
> On Nov 2, 2012, at 20:30, lin q <linq936 at gmail.com> wrote:
>
> > Hi,
> >
> > I am using the C target and like to use C++ standard library, so I add
> the
> > includes section:
> >
> > grammar tryit;
> >
> > options
> > {
> >     language = 'C';
> > }
> >
> > @parser::includes
> > {
> >   #include <vector>
> > }
> >
> >
> > But this causes antlr compile error:
> > error(100): busif.g:13:1: syntax error: antlr:
> > org.antlr.runtime.EarlyExitException
> > error(150):  grammar file tryit.g has no rules
> > error(100): busif.g:0:1: syntax error: assign.types:
> > org.antlr.runtime.EarlyExitException
> > org\antlr\grammar\v3\DefineGrammarItemsWalker.g: node from line 96:28
> > required (...)+ loop did not match anything at input ';'
> >
> > If I remove the includes section, the compile is good.
> >
> > Do you see what is wrong about this includes section?
> >
> > Another question - my target application is in C++, as far as I can see,
> I
> > can just use the C target,  write C++ program and use g++ to compile the
> > generated files. I do not plan to use C++ features like exception in
> > parsing side. Is my assumption good?
> >
> > Any pointer of example C++ usage of antlr3c is greatly appreciated!
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> http://www.antlr.org/mailman/options/antlr-interest/your-email-address
>


More information about the antlr-interest mailing list