如何解析文件

发布于 2024-12-10 03:46:16 字数 279 浏览 0 评论 0原文

好吧,我有一个作业,但我不知道如何解析该文件。字符串标记器是我的最佳选择吗? 该文件包含逗号、换行符和空格。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

陌伤浅笑 2024-12-17 03:46:16

我最大的问题是如何解析该文件?

与任何其他文本文件一样。网上有数百万个关于如何执行此操作的示例。

我会寻找使用 Scanner 类的示例。

我不太擅长解析文件。尤其是在这种情况下。

通过练习,它会变得更容易。完成这项作业会有帮助。

我应该使用直径计吗?

该文件有分隔符,所以我不知道你为什么不这样做。

逗号和换行符?

您的文件包含逗号、换行符和空格。

并将状态放入一个数组并将输入(a,b)放入第二个数组?

Java 是一种面向对象的编程语言。也许使用 Map 和 Objects 这样的集合是更好的选择。

我应该检查数字吗,isaplha?

我只是假设该文件的格式化程序正确,并且当您希望有一个数字时读取数字,当您希望有一个单词/令牌时读取字符串。

小写字母和大写字母?

不确定这是否是一个考虑因素。

我想我需要一个开关和几个案例来处理状态转换?

如果你的状态是用 Java 代码处理的,我会说是的。但是,您声明正在从文本文件中读取并存储在数据结构中。在这种情况下,不使用开关更简单。

有人可以解释一下我应该如何处理这个文件以便我可以处理它吗?

读取它,将数据存储在结构中,处理输入。

我也对如何处理该文件中的 :FA 感到困惑..

这是您需要记录的信息,以确定 DFA 何时停止。

My biggest question is how can i parse the file?

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.

I am not very good at parsing files. Especially in this situation.

With practice it will get easier. Doing this assignment will help.

Should i use dilimeters?

The file has delimiters so I don't why you wouldn't.

comma and newline?

Your file has commas, newlines and spaces.

and put the states into an array and the inputs ( a,b) into a second array?

Java is an object orientated programming language. Perhaps using Collections like Map and Objects is a better choice.

Should i check for digits, isaplha?

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.

lower case and uppercase alpha?

Not sure if this is a consideration.

i am thinking i need a switch and a couple of cases to handle the state transitions?

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.

Can someone explain how i should go about handling this file so i can process it?

Read it, store the data in a structure, process the inputs.

I am also confused on how to handle the :F A in that file..

This is information you need to record to determine when your DFA stops.

没有心的人 2024-12-17 03:46:16

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

    • has a series of states
    • needs to be able to accept/reject input strings
  • State

    • has a collection of inputs to look for and states to transition to based on input
    • needs to be able to check for a token and transition to a new 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文