[antlr-interest] access to filename
Mark Wright
markwright at internode.on.net
Sun May 2 16:48:45 PDT 2010
On Sun, May 02, 2010 at 08:49:13PM +0200, Joep Suijs wrote:
> Hi guys,
>
> For error reporting, I need access to the origination of a token when
> I walk through the tree after it is parsed. This works okay for line
> number and position on the line, but fails for the filename. A piece
> of the code used:
>
> ANTLR3_UINT32 TokenType = child->getType(child);
> CIndent(Level);
> printf("%s (%d, %s from ",child->toString(child)->chars,
> TokenType, jalParserTokenNames[TokenType]);
>
> ANTLR3_INPUT_STREAM *is = Token->input;
> printf("input stream %x,",is);
> // printf("input stream %d,",is->fileName);
Hi Joep,
You might be able to workaround this by obtaining
the file name from a pointer to your lexer that
was generated by ANTLR, something like:
jalLexer *lexer;
// Need to initialize lexer somehow
printf("file name %s,",lexer->pLexer->input->fileName->chars);
Regards, Mark
> printf("Line %d:%d)",Token->getLine(Token),
> Token->getCharPositionInLine(Token));
>
> The input stream print shows a non-zero pointer, but uncommenting the
> last line triggers an exception. The next line prints the line &
> postion as expected.
> What am I doing wrong?
>
> Joep
>
> 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