Recently i've been working with Jflex and i noticed that when i try to construct the Yylex object it only accepts java.io.Reader
and java.io.InputStream
. How could i do if i just want to build the object by using only a String?, like this:
String myString = "Hello world";
String token;
Yylex scanner = new Yylex(myString);
while ((token = scanner.yylex()) != null) {
//do something
}
In the system i'm trying to build i want the user to write something and then apply the Yylex method to it. In the models i saw that were similar to my idea the user inputs an String and then it is written into a file from where the Yylex will read.
Is it possible to do that? or i'm misunderstanding something?. Is there any other tool you would reccomend instead of Jflex?
Thanks!
-
Check stackoverflow.com/questions/837703/…SJuan76– SJuan762014年03月16日 21:31:45 +00:00Commented Mar 16, 2014 at 21:31
1 Answer 1
The simplest way to do want you want would be to use a StringReader
, which creates a reader from a String without any other hoops to jump through. Simply use:
Yylex scanner = new Yylex(new StringReader(myString));