[antlr-interest] error locations: how to emulate #line functionality in Java?

Alexey Demakov demakov at ispras.ru
Thu Nov 25 08:56:50 PST 2004


Hi all, 

I need ideas.
After source to source translation, generated files are compiled
using, for example, Java compiler. If source file contains user-supplied
code in target language, it can cause compile time errors.
For example, it can be user actions in ANTLR grammar.
In compiler messages, error locations are in generated files.
So, often you need to look in generated parser to find out, what's wrong.
If it is not a bug in the translation tool, you see that problem is 
in your code and should be corrected in source file (*.g).
I suppose, if error location in compiler message was in source file,
you were able to correct it without having to look at generated files.
In C language there are preprocessor directive #line used by lex/yacc
that tell compiler which file name and line number should be used in error messages.
As far as I know, Java doesn't provide such functionality in any way.
So, I see the only method to emulate it is to store translation table with correspondence
between source and generated files and line numbers and translate compiler
error messages back at source level.
May be you have better ideas? If solution will be suitable not only for Java - it will be great.

Regards,
Alexey

-----
Alexey Demakov
TreeDL: Tree Description Language: http://treedl.sourceforge.net
RedVerst Group: http://www.unitesk.com




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 





More information about the antlr-interest mailing list