[antlr-interest] Generate AST from C runtime

Sergiy Dubovik sergiy.dubovik at gmail.com
Sun Mar 25 09:30:38 PDT 2012


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


More information about the antlr-interest mailing list