[antlr-interest] Newbie question on ANTLR

Neil Benn neil.benn at cambridgeantibody.com
Fri Nov 1 08:19:40 PST 2002


Hello,

	I am a new person to ANTLR.  I have made some progress but am
having some problems.  The code beneath is simply to tokenize a CSV
file.  However I am now attempting to recognise a token by splitting a
segment where a comma isn't there when it should be.

	The ANTLR code is:-

class CSVParser extends Parser;

startRule
: (k:KEEP
    {
       System.out.println(k.getText().trim());
    }
  )+
;
//------------------LEXER------------
class CSVLexer extends Lexer;

options{
  k=8;
}

tokens {
  COMMENT = "Comment";
}

DISCARD: ( '\t'
         | ','
         | ':'
         | '\n' {newline();}
         | '\r' '\n' {newline();}
         )+
         {$setType(Token.SKIP);}
;

KEEP: ('\u0020' .. '\u002B' //miss out the comma
      | '\u002D' .. '\u0039'//miss out the colon
      | '\u003B' .. '\u007E')+//go up to end of latin characters and
ASCII punctuation types
; 

	This is attempting to recognise the literal of "Commment"
however when I attempt to compile I get an error detailing:-

Error: line(17), expecting TOKEN_REF, found 'COMMENT'
Error: rule classDef trapped: line(19), expecting RCURLY, found ';'


	As far as I can see I have used the same syntax that comes in
the examples - however I'm not getting anywhere and am not sure what I'm
doing wrong.  

	Any help anyone could provide, I'd most appreciate it and can
return any information on laboratory automation strategy planning at the
same time!

P.S. I've attached the file (one of many formats) I'm trying to parse
(format is out of my control) for completeness - although it's probably
of no use!


Cheers,

Neil Benn
Senior Automation Informatics Scientist

Cambridge Antibody Technology
The Science Park
Melbourn
Cambridgeshire
SG8 6JJ, UK

Telephone: + 44 (0) 1763 263233
Facsimile + 44 (0) 1763 263413
Email: mailto:neil.benn at cambridgeantibody.com
http://www.cambridgeantibody.com

Cambridge Antibody Technology Limited *
Registered Office: The Science Park, Melbourn, Cambridgeshire, SG8 6JJ,
UK
Registered in England and Wales number 2451177
(* Cambridge Antibody Technology Limited is a member of the Cambridge
Antibody Technology Group of Companies)

Confidentiality Note: This information and any attachments is
confidential
and only for use by the individual or entity to whom it has been sent.
Any
unauthorised dissemination, distribution or copying of this message is
strictly prohibited. If you are not the intended recipient please inform
the
sender immediately by reply e-mail and delete this message from your
system.
Thank you for your co-operation.


 

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



More information about the antlr-interest mailing list