[antlr-interest] Reading contents of file using Antlr

Sharon Li hushlee83 at yahoo.com.sg
Wed Jan 22 16:03:14 PST 2003


Hi,

Thanks for th help. Below is the code for my grammer file.
/***********************************************************************/
class CSVParser extends Parser;
options { k=4; }
{
 LsystemsString ls = new LsystemsString();
 
 public LsystemsString getLsystemsString(){
  return ls;
 }
}
file   : ( line (NEWLINE line)*(NEWLINE)? EOF)
       {System.out.println("file matched");}
       ;
line   : ((record)+ )
       ;
record : ((r:KEYWORD) (sc: SEMICOLON)? (n:RECORD)*  (COMMENT)?)
       {
    System.out.println("attribute = " + r.getText());
        System.out.println("value = "+n.getText());
    ls.addNext(r.getText(),n.getText());
    System.out.println("LS size: "+ls.getArrayListSize());
    }
    ;
    
class CSVLexer extends Lexer;
options { 
 charVocabulary='\3'..'\377'; 
 k = 4;
}
RECORD  : ('a'..'z' | 'A'..'Z'| NUMERIC)(!~('\r'|'\n'|':'))+ ;
KEYWORD 
 : "angle factor"
 | "initial color"
 | "color increment"
 | "initial line width"
 | "line width increment"
 | "viewpoint"
 | "view reference point"
 | "twist"
 | "projection"
 | "front distance"
 | "back distance"
 | "scale factor"
 | "z buffer"
 | "cue range"
 | "shade mode"
 | "line style"
 | "light direction"
 | "diffuse reflection"
 | "tropism direction"
 | "initial elasticity"
 | "elasticity increment"
 | "render mode"
 ;
NUMERIC : ('0'..'9'|','|'.'|'-')+;
SEMICOLON : ':';
BRACKET : ('(' | ')');
COMMENT : "/*" (options {greedy=false;} :.)* "*/" ;
NEWLINE : ('\r''\n')=> '\r''\n' //DOS
        | '\r'                  //MAC
        | '\n'                  //UNIX
        { newline(); }
        ;
    
WS      : (' '|'\t') { $setType(Token.SKIP); } ;
/************************************************************************************/
 mzukowski at yci.com wrote:Lexical nondeterminism means you have two lexical rules that are in
conflict, meaning they have the same prefix. Post a small but complete
example which has the error message and we'll be able to help you. 

Monty


-----Original Message-----
From: Sharon Li [mailto:hushlee83 at yahoo.com.sg]
Sent: Tuesday, January 21, 2003 11:43 PM
To: Antlr Interest Group
Subject: [antlr-interest] Reading contents of file using Antlr


Hi, 
I'm a Java programmer and relatively new to Antlr. I need to write Antlr
code to read in a text file and extract only the necessary information. How
can I go about doing that? An example of the contents of the file might look
like that : 
angle focus : 0.0005
color : blue
line width : 12
I often get the error msg:
warning : lexical nondeterminism upon ...
Also when do we use the TreeParser and what is the different between a
Parser and a TreeParser? When do we define tokens and what is it for ? Pls
help! Thanks very much.
Yahoo! Travel
- Get the latest travel deals in town! 
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 



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


 Yahoo! Travel
- Get the latest travel deals in town!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20030123/dd95a8c4/attachment.html


More information about the antlr-interest mailing list