[antlr-interest] How to read input from a file?
Hitakshi Buch
hbuch06 at hotmail.com
Fri Apr 21 13:13:24 PDT 2006
I want to read a series for strings from a file and parse them. My program only parses the first line in the input file though. How can I have it parse the whole file?
My input file contents:
'Hello''ORACLE.dbs''Jackie''s raincoat''09-MAR-98'
I'm trying to read all strings that begin and end with a quote ('). So, my output should consist of the following:
Hello
ORACLE.dbs
Jackie's raincoat
09-MAR-98
INSTEAD, I only get the following:
Hello
My Main file looks like the following:
import java.io.*;
class Main { public static void main(String[] args) { try { L lexer = new L(new FileInputStream("input2.inp")); P parser = new P(lexer); parser.setFilename("input2.inp"); parser.startRule(); } catch(Exception e) { System.err.println("exception: "+e); } }
My .g file looks like:
class P extends Parser;
startRule
: n:DEFAULT_QUOTE {System.out.println("Matched default quote with: "+n.getText());} ;
class L extends Lexer;
options { k=2;}
// one-or-more letters followed by a newlineDEFAULT_QUOTE: ( '\''! (~('\'') )+ '\''! ) ;
protectedLINETERMINATOR : '\r' '\n' // DOS | '\n' // UNIX ; WHITESPACE : LINETERMINATOR | ' ' | '\t' | '\f' ;}
Any help will be greatly appreciated. Thank you.
_________________________________________________________________
It’s the future of Hotmail: Try Windows Live Mail beta
http://www2.imagine-msn.com/minisites/mail/Default.aspx?locale=en-us
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20060421/ab5ae0a3/attachment.html
More information about the antlr-interest
mailing list