[antlr-interest] Places where Antlr can be used ....

Chris Black chris at lotuscat.com
Thu Jun 23 12:08:28 PDT 2005


Prashant Deva wrote:

>What situations other than the normal compiler and translator
>construction can you come up with where Antlr can be used?
>  
>
I use ANTLR almost exclusively for parsing data output by scientific 
instruments. Many instruments generate the same data (such as a curve of 
some value over time for example) but they all export it in their own 
non-standard, usually undocumented format. Some file formats group by 
sample, some by type of data, some by time, etc. I use antlr to get the 
information I actually want to look at into my own standardized data 
structures so the analysis can work the same on any instrument. 
Instrument output files tend to be of the form:
Some: foo
Header: bar
Fields: baz

Stanza Header wibble
column,headers,here
datavalue,datavalue,datavalue
.
.
.

Stanza Header pootie
column,headers
datavalue,datavalue

And are almost always field-based with a delimiter of a comma or a tab 
(sometimes it is column based or uses spaces).

Complications are that often different versions of the instrument 
software slightly change the format, but I want to be able to use the 
same parser for all versions. So I have alternatives in the parser that 
build the same type of AST, then the AST walker doesn't need to change 
for slight variations in input file (such as changing the names of 
header fields, etc). I use generic CSV and Tab separated value lexers 
that are shared across all parsers, these lexers generate a stream of 
FIELDs, DELIMs, and NEWLINEs and also handle double-quoted values. All 
real complexity is handled in the parser and treeparser.

If anyone has any advice or insight on this type of ANTLR grammer let me 
know :)

Chris


More information about the antlr-interest mailing list