[antlr-interest] Generate AST from C runtime

Sergiy Dubovik sergiy.dubovik at gmail.com
Sun Mar 25 09:55:41 PDT 2012


Are you referring to this example
https://github.com/antlr/examples-v3/blob/master/C/treeparser/main.c ?
I checked all examples. Half of them do not generate AST, another half has
a walker.
I know how to walk the tree, as I mentioned I got it working with some
version of antlr and runtime, it just doesn't seem to generate proper ast
anymore.
Though toStringTree prints correctly.

:sergiy

On Sun, Mar 25, 2012 at 7:39 PM, Jim Idle <jimi at temporal-wave.com> wrote:

> Compile the runtime in debug mode and single step - explained in the API
> docs.
>
> Download the example tar and find the tree example in C. This shows that
> you get a pointer (pANTLR3_BASE_TREE) and the super pointer of such a node
> is pANTLR3_COMMON_TREE. The code in the runtime that generates a .dot file
> is a good example of how to walk the tree. This is also explained in the
> API docs. This is also talked about many times in antlr.markmail.org
>
>
> Jim
>
>
>
>
> > -----Original Message-----
> > From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> > bounces at antlr.org] On Behalf Of Sergiy Dubovik
> > Sent: Sunday, March 25, 2012 9:31 AM
> > To: AN TLR
> > Subject: Re: [antlr-interest] Generate AST from C runtime
> >
> > Uff, sorry for posting unfinished email. Tab and space have special
> > meaning in browser.
> >
> > Could someone help me to generate AST from a grammar using C with a
> > minimum amount of C code?I just want to get a pointer to an AST root. I
> > don't need tree walker. I have a grammar which generates nice AST in
> > AntlrWorks. Can I have the same from C? Isn't it so that Antlr
> > generates AST if I specify options=AST;?
> >
> >     pANTLR3_UINT8 fileName = (pANTLR3_UINT8) "example.rpp";
> > >
> > >     pANTLR3_INPUT_STREAM input = antlr3FileStreamNew(fileName,
> > > ANTLR3_ENC_8BIT);
> > >
> > >     pRppLexer lexer = RppLexerNew(input);
> > >
> > >     pANTLR3_COMMON_TOKEN_STREAM tokenStream =
> > > antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT,
> > > TOKENSOURCE(lexer));
> > >
> > >     pRppParser parser = RppParserNew(tokenStream);
> > >
> > >      RppParser_prog_return prog;
> > >
> > >     prog = parser->prog(parser);
> > >
> > >
> > I found that prog.tree should point to a root AST and it's not NULL,
> > however when I try to get token, it returns NULL.
> > Some months ago, I think I was getting proper pointer but now for some
> > reason (I updated antlr) it doesn't work anymore. C Runtime API makes
> > it very difficult to debug anything :(
> >
> > Thanks.
> >
> > br,
> > Sergiy
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-
> > email-address
>
> 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