[antlr-interest] why antlr not accept string as input stream?

Christopher Schultz christopher.d.schultz at comcast.net
Mon Jan 31 18:24:56 PST 2005


To whom it may concern,

> class MyParser extends Parser;

[snip]

> MyLexer lexer = new MyLexer("12+23-34");

[snip]

> C:\Documents and Settings\Administrator\1>javac Test.java
> Test.java:9: cannot resolve symbol
> symbol : constructor MyLexer (java.lang.String)
> location: class MyLexer
> MyLexer lexer = new MyLexer("12+23-34");;
> ^
> 1 error

That's because the method takes an InputStream or a Reader, not a 
String. This is pretty clear from the tutorials and JavaDoc.

If you want to use a String, try this:

MyLexer lexer = new MyLexer(new java.io.StringReader("12 + 23 - 34"));

That ought to work out better for you.

-chris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20050131/aedd68e0/signature.bin


More information about the antlr-interest mailing list