简体   繁体   English

从文件中读取令牌,然后存储到数组中以进行输出

[英]Reading tokens from file then storing into an array for output

i have specification of a DFA in a text file as follows; 我在文本文件中指定了DFA,如下所示;

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 看看java.util.Scanner类API

You can use it to read a line as a String and use the toCharArray() method in the String class. 您可以使用它来读取一行作为String,并在String类中使用toCharArray()方法。

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. 根据您希望该DFA最终获得的深度,您可能需要查看Javacc ,它是针对此类内容而构建的,但是肯定存在学习上的困难 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. 它将产生有效的Java源代码,因此如果您的目标是始终将生成的类集成到应用程序中,但是如果您只想打印一些javacc可以直接处理的内容。 If you are interested in trying that you can check out this tuorial . 如果您有兴趣尝试,可以查看此葬礼

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM