如何解析文件
好吧,我有一个作业,但我不知道如何解析该文件。字符串标记器是我的最佳选择吗? 该文件包含逗号、换行符和空格。 S 是起始状态,小 a 是输入,大 A 是下一个状态。我应该将文件解析为单独的变量并通过 switch case 运行它来模拟状态机吗?
这是文件,
‘Ends in a
2
S, a, A
S, b, S
A, a, A
A, b, S
F: A
aba
bbaabba
bbabab
aaaab
b
a
非常感谢你,因为我似乎无法开始......
Alright, i have an assignment and i dont know how to parse the file. Is string tokenizer my best option?
The file has commas, newlines and spaces. S is the starting state and small a is the input and the big A is the next state. Should i parse the file into seperate variables and run it through a switch case to simulate a state machine?
This is the file
‘Ends in a
2
S, a, A
S, b, S
A, a, A
A, b, S
F: A
aba
bbaabba
bbabab
aaaab
b
a
Thank you so much because i just cant seem to get started...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
与任何其他文本文件一样。网上有数百万个关于如何执行此操作的示例。
我会寻找使用 Scanner 类的示例。
通过练习,它会变得更容易。完成这项作业会有帮助。
该文件有分隔符,所以我不知道你为什么不这样做。
您的文件包含逗号、换行符和空格。
Java 是一种面向对象的编程语言。也许使用 Map 和 Objects 这样的集合是更好的选择。
我只是假设该文件的格式化程序正确,并且当您希望有一个数字时读取数字,当您希望有一个单词/令牌时读取字符串。
不确定这是否是一个考虑因素。
如果你的状态是用 Java 代码处理的,我会说是的。但是,您声明正在从文本文件中读取并存储在数据结构中。在这种情况下,不使用开关更简单。
读取它,将数据存储在结构中,处理输入。
这是您需要记录的信息,以确定 DFA 何时停止。
Like any other text file. There are literally millions of examples on how to do this on the web.
I would look for examples using the
Scanner
class.With practice it will get easier. Doing this assignment will help.
The file has delimiters so I don't why you wouldn't.
Your file has commas, newlines and spaces.
Java is an object orientated programming language. Perhaps using Collections like Map and Objects is a better choice.
I would just assume the file is formatter correctly and read numbers when you expect to have a number and strings when you expect to have a word/token.
Not sure if this is a consideration.
If your states were handled in Java code, I would say yes. However you states are being read from a text files and stored in a data structure. In this case its simpler not to use switches.
Read it, store the data in a structure, process the inputs.
This is information you need to record to determine when your DFA stops.
Java 是一种面向对象的语言,因此构建一系列反映现实世界的类。
例如:
你有什么?他们需要做什么才能
DFA
State
因此这些类型控制您应该如何布局您的类(成员和方法)。所以你应该创建一个DFA类,它应该有一个方法:public boolean process(String input)。
Java is an object-oriented language so build a series of classes that reflect the real world.
Example:
What do you have? And what do they need to be able to do
DFA
State
So these kind govern how you should lay out your classes (members and methods). So you should make a DFA class and it should have a method: public boolean process(String input).