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!

asked Mar 16, 2014 at 21:29
1

1 Answer 1

0

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));
answered Mar 18, 2014 at 21:25

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.