[antlr-interest] C target difficulties
M. C.
thats_me23 at live.nl
Thu Dec 18 04:48:20 PST 2008
Hi all,
I have been working with ANTLR for some weeks now, but I'm having some difficulties getting the generated code to work.
I'm using ANTLRworks 1.2.2 under Fedora linux 8. and installed the runtime library "libantlr3c-3.1.1", which works perfectly.
I generate code for the C target, and made my own main.c using the example on the ANTLR website, this code compiles well without errors (and some warnings about not used variables, but that isn't harmfull I guess)
Whats the problem then? Well I've got a question about the section just above the main, "int ANTLR3_CDECL" what is it good for? when I comment this part out, the source compiles well, but if I don't it generates the following error:
"main.c:8: Warning: two or more data types in declaration specifiers"
Then I've got a somewhat more serious problem, my code hangs when feeding an input file. I checked with some printf statements where it hangs, but it doesn't do anything after the " psr = testParserNew(tstream); " line. The program doesn't shutdown, but also doesn't do anything else.
And is psr->program(psr); the right way to invoke the parser?
So that the outputs I made in the .g file (like detecting a number and then printf("number found"); actually get printed in the terminal?
I've been trying things for some time now, but really can't find the problem. Does someone else maybe know what i'm doing wrong?
Thanx in advance!!
Here is a copy of my main.c
---------------------------------------
#include "testLexer.h"#include "testParser.h"
int ANTLR3_CDECL
int main(int argc, char *argv[]){ pANTLR3_UINT8 fName; // filename in char 8 format pANTLR3_INPUT_STREAM input; // input stream ptestLexer lxr; pANTLR3_COMMON_TOKEN_STREAM tstream; ptestParser psr;
if (argc < 2 || argv[1] == NULL) { fName =(pANTLR3_UINT8)"./input"; } else { fName = (pANTLR3_UINT8)argv[1]; }
input = antlr3AsciiFileStreamNew(fName);
if ( input == NULL) { fprintf(stderr, "Failed to open file %s\n", (char *)fName); exit(1); }
lxr = testLexerNew(input); // CLexerNew is generated by ANTLR
if ( lxr == NULL ) { fprintf(stderr, "Unable to create the lexer due to malloc() failure1\n"); exit(1); }
tstream = antlr3CommonTokenStreamSourceNew(ANTLR3_SIZE_HINT, TOKENSOURCE(lxr));
if (tstream == NULL) { fprintf(stderr, "Out of memory trying to allocate token stream\n"); exit(1); }
psr = testParserNew(tstream); // CParserNew is generated by ANTLR3
// SOFTWARE HANGS HERE........
if (psr == NULL) { fprintf(stderr, "Out of memory trying to allocate parser\n"); exit(ANTLR3_ERR_NOMEM); }
psr->program(psr);
-----------------------------------------------------
_________________________________________________________________
Download de nieuwste emoticons voor in je Messenger
http://www.msnmessengerexperience.nl/chuck/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081218/26c8ed7d/attachment.html
More information about the antlr-interest
mailing list