[antlr-interest] bug with composite grammars in C runtime?
Robert Soule
robert.soule at gmail.com
Tue Mar 3 14:16:36 PST 2009
Hi Jim,
I am trying to follow your suggestion of defining literals in a
separate lexer grammar,
and then importing them into my main grammar. I am getting a runtime
error, and I'm
not sure if I specified something wrong. Below are the files that
generate the error.
Here is the Helper.g:
lexer grammar Helper;
options {language = C;}
SEMI : ',';
and my A.g:
grammar A;
options { language=C; output=AST; }
import Helper;
tokens { PROGRAM; }
accept : SEMI EOF -> PROGRAM;
WHITE_SPACE : (' '|'\t'|'\r'|'\n')+ {
$channel = HIDDEN; };
When I run this, I get a bus error:
0x00000000 in ?? ()
(gdb) where
#0 0x00000000 in ?? ()
#1 0x000239cf in setCharStream ()
#2 0x00023abe in antlr3LexerNewStream ()
#3 0x00002868 in A_HelperNewSSD (instream=0x100180, state=0x100570,
gA=0x100460) at A_Helper.cpp:318
#4 0x00001a14 in ALexerNewSSD (instream=0x100180, state=0x0) at ALexer.cpp:352
#5 0x00001a45 in ALexerNew (instream=0x100180) at ALexer.cpp:285
#6 0x000029df in main (argc=2, argv=0xbffff110) at AtoB.cpp:30
(gdb)
The line A_Helper.cpp:318:
ctx->pLexer = antlr3LexerNewStream(ANTLR3_SIZE_HINT, instream, state);
And the driver:
#include <iostream>
#include <antlr3.h>
#include <AParser.h>
#include <ALexer.h>
int main(int argc, char* argv[])
{
pANTLR3_INPUT_STREAM input;
pALexer lex;
input = antlr3AsciiFileStreamNew((pANTLR3_UINT8)argv[1]);
lex = ALexerNew(input);
}
Am I using the import wrong?
thanks,
Robert
More information about the antlr-interest
mailing list