[antlr-interest] Parsing tab delimited datamatrix
Martin Eklund
martin.eklund at farmbio.uu.se
Mon May 15 08:48:10 PDT 2006
Hi,
I'm a complete newbie when it comes to ANTLR and would be very thankful
to get a few pointers. I would like to parse a file containing a tab
delimited datamatrix. The first row of the file contains column headers,
whereas all the other rows contain first an identifier and then doubles
separated by tabs. Ex:
I'd like to parse
this 12.3 1.2 3
type 1.54 5 21.1
of 12.3 1 4
file 7 1 4.9
During the parsing I would like to put the column header identifiers
into a array of string, the row "header" identifiers into another aray
of strings and the doubles into a jama matrix (basically just a
double[][]). My idea is that the wee parser and lexer below is pretty
much what I need. However, I suppose I need to add some actions where
the start are (please see below). The problem is what to add... How do I
for instance know how big to make the String[] and the double[][]..?
============================================================
class pcmParser extends Parser;
// Match one-or-more column headers
columnHeaders
: (TEXT)+ NEWLINE
***** What goes here? *****
;
rows
:TEXT (NUM)+
***** And what goes here? *****
;
class pcmLexer extends Lexer;
TEXT options { testLiterals = true;}
:('a'..'z'|'A'..'Z'|'0'..'9'|'_')+
;
DIGIT : '0'..'9' ;
NUM : (DIGIT)+ ('.' (DIGIT)+ )? ;
WS
: ( ' '
| '\t'
)
{$setType(Token.SKIP);}
;
NEWLINE
: '\r' '\n' // DOS
| '\n' // UNIX
;
============================================================
Thank you in advance for any help!
Cheers,
Martin.
--
========================================
Martin Eklund
PhD Student
Department of Pharmaceutical Biosciences
Uppsala University, Sweden
Ph: +46-18-4714281
========================================
More information about the antlr-interest
mailing list