HIT_SZ计算理论project
所有实验均在Ubuntu下编写和测试,亲测在Windows下结果不正确。
一、project 1
实验一
实验内容:编写程序实现利用正则表达式匹配IP地址。要求能够正确匹配合法的IP地址格式。
很简单,没什么好说的。但听说有很多同学用“调包”的方法,但我至今也没弄清楚调的是什么包。(手动笑哭emoj)
直接放上实验报告里的Design部分。
A. Design
In this experiment, I construct a program to read a regular a ipv4 address and check it if it is a correct one. Specially, we regard those ipv4 address which consist of four number between and 255 and separated by three dots as correct addresses.
So I just read characters into a buffer until meeting a dot, then transform them to corresponding integers and check it if in the range of 0 to 255. If so, go and check the next integer. Otherwise, it’s not a correct ipv4 address. When reading the ‘\0’ means it has been the end of this string, if now exactly 4 integers and 3 dots have been checked, then we say this string is a correct ipv4 address. Otherwise, it’s not.
实验二
实验内容:编写程序实现从正则表达式到非确定性有穷自动机(NFA)的转换。输入数据从文件读取。正则表达式的形式化定义可参考中文课本(第二版)P38相关内容。NFA的形式化定义可参考中文课本(第二版)P32相关内容,并设计数据结构以在计算机中表示。
NFA的数据结构:
// The item of Transition Function List.
typedef struct func{