0

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!

4

1 に答える 1

0

あなたが望む最も簡単な方法はStringReader、 を使用することです。これは、ジャンプする他のフープなしで String からリーダーを作成します。単純に使用します:

Yylex scanner = new Yylex(new StringReader(myString));
于 2014-03-18T21:25:32.923 に答える