[antlr-interest] newbie question

tsipaggiedad garyf at austinaggies.com
Tue Oct 26 07:21:12 PDT 2004




I'm trying to write *very* simple csv parser in antlr.  My antlr .g
file is included below.  My problem is this... I need to allow for CSV
files where the fields may or may not be quoted (which works just
fine), but which may also be empty.  I get the dreaded 

"../antlr/csv.g:25:25: warning:nondeterminism between alts 1 and 2 of
block upon k==1:COMMA"

message.  I believe I understand why (and increasing lookahead to 2 or
more doesn't resolve the warning message).  

The odd thing is.. the parser *seems* to work (at least for all of the
test cases I have).

My questions are:

1)  How do I eliminate the warning message (and/or is there something
I should be doing different)

2)  Is there a way to increase the performance of this parser?

Obviously, any help greatly appreciated.

// CSV parser definition
header {
#include <iostream>
#include <vector>
#include <string>
#include <antlr/Token.hpp>
using namespace antlr;
using namespace std;
typedef vector<string *>        StringVector;

}
options {
        language="Cpp";
}

class CSVParser extends Parser;
options { k=1; }
line returns [StringVector *strVector]
       {strVector = new StringVector(); string *recordData;}
       : ( ( (recordData=record {strVector->push_back(recordData);})+
NEWLINE) | EOF )
       ;

record returns [string *recordData]
       {recordData = new string(); }
       : ( (rec:RECORD) (COMMA)? )
       {(*recordData)+=(rec->getText()); }
       | (COMMA)
       ;

class CSVLexer extends Lexer;
options { k=1; charVocabulary='\3'..'\377'; }
protected QUOTE : '"';
protected DATA  :  (~(','|'|'|'"'|'\r'|'\n'))+ ;
protected QUOTEDATA : (~('"'|'\r'|'\n'))+ ;
RECORD  : QUOTE! QUOTEDATA QUOTE!
                | DATA;
COMMA   : (','|'|') ;
NEWLINE : ('\r''\n')=> '\r''\n' //DOS
        | '\r'                  //MAC
        | '\n'                  //UNIX
        { newline(); }
        ;


// WS      : (' '|'\t') { $setType(Token::SKIP); } ;









 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

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





More information about the antlr-interest mailing list