[antlr-interest] Implementing 'include' directive and giving coherent filenames when parsing

Jim Idle jimi at temporal-wave.com
Mon Jun 25 09:29:24 PDT 2007


I am pleased that your sample of Terrence worked well :-)

Realizing that there was no particularly easy way to auto track this sort of thing, I added a "name" field to the input stream for the C target. Hence while filename is not always a useful concept, some identification may well be and it usually WILL be a file name. 

In the Java version you can either accumulate your own table/map using the input object as some sort of key, or make you own input stream that extends the ANTLR one and contains this info, then the token containing a reference to its input stream will allow you to find the file name.

Jim

> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of amartinez at atc.ugr.es
> Sent: Monday, June 25, 2007 8:40 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Implementing 'include' directive and giving
> coherent filenames when parsing
> 
> Hello,
> I'm implementing the include directive for a simple assembler using
> ANTLR V3.
> 
> Everything goes right except that I don't know how to calculate at the
> parser, which filename (from include "filename") gives the error.
> 
> At the Parser level, I know how to work with the line, column,
> StartIndex
> and StopIndex (of a IToken) attributes for every parsing error. How
> could
> I retrieve the filename?
> 
> Note:
> I had successfull when translating into C# the Terence sample:
> http://www.antlr.org/wiki/pages/viewpage.action?pageId=557057
> I'm interested on this ANTLR target.
> 
> Regards.
> 
> --
> Antonio Martínez


More information about the antlr-interest mailing list