[antlr-interest] ANTLR and runtime token assigning - URGENT

berserksangr berserksangr at poczta.onet.pl
Thu Jun 19 06:51:19 PDT 2003


Hello,

I have two problems with my ANTLR - generated Parser/Lexer (I'm new in this things).  Please, help me... I'm stuck.

(At the end there is a part of grammar file that this questions are about)

1. How can I set "SEPARATOR" token value from my grammar file in produced CSVLexer/CSVParser?
I mean, I wrote class that uses this Parser/Lexer but I want the class' user to have ability to set SEPARATOR to ';'
instead of ",". How is it possible to define variable SEPARATOR in Parser/Lexer that will be used to process input
without running antlr.Tool again?
I wonder why ANTLR hard-code tokens instead of exposing them in easy-to-modify variables...

2. In my grammar I tried to put
RECORD  : (~('"'|SEPARATOR|'\r'|'\n'))+;
instead of
RECORD  : (~('"'|','|'\r'|'\n'))+;

but antlr.Tool throws error:
csv.g:119:13: This subrule cannot be inverted.  Only subrules of the form:
     (T1|T2|T3...) or
     ('c1'|'c2'|'c3'...)
 may be inverted (ranges are also allowed).
 Exiting due to errors.

How can I do that?

******************************************************

Part of my grammar file:
---------------------------------------
class CSVLexer extends Lexer;
options 
{
    defaultErrorHandler=false;
    k=2; 
    charVocabulary = '\3'..'\377';
}
RECORD  : (~('"'|','|'\r'|'\n'))+;
SEPARATOR : ',';                //
QRECORD : '"'!('"''"'|~('"'))+'"'!;
NEWLINE : '\r''\n' //DOS
                | '\r'                  //MAC
                | '\n'                  //UNIX
                { newline(); };
--------------------------------------

  --
Best regards,
 Przemyslaw Jakierski


 

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




More information about the antlr-interest mailing list