[antlr-interest] Token lookup crashing program.
doctlo-antlr at yahoo.com
doctlo-antlr at yahoo.com
Mon Jul 4 23:46:37 PDT 2005
I've included here a part of a grammar I am having trouble with.
The problem with is with the actions I've added.
Without the actions, ( well with the only actions being print
statements ),
( I've also include here a part of the lexer that you need to
understand the parser. )
The problem is that once the parser is run, the 3815th
time palpha is run,. I get an access violation. In particular
( explaining the reason for the commented out statement )
it is LT(0) which causes an access violation ( or a segment
violation).
This error happens on both WIndows and Linux. If it is caused
because some line of code corrupts memory, I have not been
able to find that line. Despite using three different memory
checking systems.
Tracing matches ( using actions that print, I know that
it does not fail because there is no more to parse. ) I know
that it does not finish reading data. The data at that
line is nearly identical to the data in other lines previously parsed.
Since I can't find any memory corruption happening, and
since this happens consistently on two platforms I have got to assume
there is something wrong with antlr, or I am doing something
incorrectly with antlr. Can someone suggest something?
protected psign returns [string value]
: SIGN
{
value=LT(0)->getText();
};
protected pnumber returns [string value]
: NUMBER
{
value=LT(0)->getText();
};
integer returns [int value=0]
{
string ps,ns;
}
: (ps=psign)? ns=pnumber
{
string s=ps+ns;
istringstream ss(s);
ss>>value;
};
protected palpha returns [string value]: ALPHA
{
// antlr::RefToken r=LT(0);
value=LT(0)->getText();
};
Lexer part.
WS: ( ' '| '\t' |'\f')+ {};
protected
DIGIT: '0'..'9';
NUMBER: ( DIGIT )+;
protected
LETTER: 'a'..'z'|'A'..'Z'|'_'|'#'|'('|')';
ALPHA: ( LETTER ) +;
SIGN: '-';
protected
BEOL: ( "\r\n" | "\n" ) {newline();};
EOL: BEOL ( WS BEOL | BEOL )*;
--
Thad
More information about the antlr-interest
mailing list