Reading tokens from file then storing into an array for output
i have specification of a DFA in a text file as follows;
DFA = (
{q1,q2},
{0,1},
开发者_如何学运维 {(q1,0)-> q1, (q1,1)-> q2, (q2,0)-> q1, (q2,1)-> q2},
q1,
{q2}
)
What piece of code could help me read each token (character) and store the tokens into an array then printout contents of the array
Take a look at the java.util.Scanner class API
You can use it to read a line as a String and use the toCharArray() method in the String class.
Depending on how in depth you want this DFA to eventually get you may want to check out Javacc, it was built for this type of stuff but there is definitely a learning curve. It will produce valid java source code so you could always integrate the generated classes into your application if that is what your goal is, but if you just want to print a few things javacc can handle that directly. If you are interested in trying that you can check out this tuorial.
精彩评论