admin 管理员组

文章数量: 1184232


2024年1月17日发(作者:getwriter)

__________________________________________________

计算机专业软件类课程实验报告

课程名称:

编译原理

正规式、NFA、DFA、MFA的转换

实验题目:

实验小组成员:

实验小组组长:

任课教师:

专业名称:

计算机科学与技术

班级名称:

计科1班

实验起止时间:

一、实验目的

1、理解什么是正规式

2014-5-19~2014-5-29

__________________________________________________

__________________________________________________

2、理解NFA、DFA、MFA的概念;

3、掌握正规式和NFA之间的等价变换;

4、掌握NFA和DFA之间的等价变换;

5、掌握DFA和MFA之间的等价变换;

6、了解程序设计语言Java的语言机制。

二、实验内容

程序的流程图如下所示:

1、根据用户输入的表达式,验证是否为合法的正规式

2、根据正规式,将其转换为NFA

3、根据NFA,将其转换为DFA

4、根据DFA,将其转换为MFA

三、实验需求

1、正规式验证

对输入的表达式能够做出正确的判断,如果是合法的正规式,则激活正规式转为NFA的功能;如果不是合法的正规式,则会弹出消息框进行提示

2、正规式转为NFA

对经过验证的正规式,根据算法,将其转换为NFA,得出开始符号集、终结符号集以及符号集,并激活NFA转为DFA的功能;也可以点击打开按钮,选择一个格式符合规范的NFA文件,同时激活NFA转为DFA的功能;也可以对得到的NFA进行保存

__________________________________________________

__________________________________________________

3、NFA转为DFA

对第一个文本框中的NFA,根据算法,将其转换为DFA,得出开始符号集、终结符号集以及符号集,并激活DFA转为MFA的功能;也可以点击打开按钮,选择一个格式符合规范的DFA文件,同时激活DFA转为MFA的功能;也可以对得到的DFA进行保存

4、DFA转为MFA

对第二个文本框中的DFA,根据算法,将其转换为MFA,得出开始符号集、终结符号集以及符号集;也可以点击打开按钮,选择一个格式符合规范MFA文件;也可以对得到的MFA进行保存

四、主要数据结构介绍

1、自定义一个JavaBean,这个类里只有三个属性,节点的开始符号,接受符号,终结符号,并有他们的get()、set()方法,将类名定义为Node

2、整个程序涉及到的NFA、DFA、MFA都存放在ArrayList中,每次通过迭代器Iterator进行迭代

3、在正规式转为NFA时,将创建一个开始符号栈和一个终结符号栈,分别用来存储开始符号和终结符号

4、在NFA转换为DFA时,创建一个对象数组Object[][2],每个数组单元第一列为__________________________________________________

__________________________________________________

ArrayList,存放的是节点号,第二列是一个Boolean,标记该状态T是否被访问过

5、在DFA转换为MFA时,创建一个对象数组Object[],每个数组单元为ArrayList,存放的是每次划分的节点信息

五、主要模块算法介绍

1、正规式验证

将输入的正规式使用toCharArray()转换成一个一个字符,然后对字符进行处理,主要是验证左右括号是否匹配正确,以及”|”,”.”,”*”等符号位置是否合法,输入的表达式中是否含有非法字符

2、正规式转为NFA

对经过验证的正规式进行一个字符一个字符的判断,其中”*”的优先级最高,其次是”.”,最后是”|”。在转换过程中,构造两个栈,一个栈是开始符号栈,用来存放创建的开始符号,一个是终结符号栈,用来存放创建的终结符号。通过对”|”,”.”,”*”优先级的的不同,对两个栈进行不同的处理,将产生的结点存入ArrayList

3、NFA转为DFA

将从第一个文本框中读出的NFA节点信息存入ArrayList,由迭代器进行迭代,算法的流程如下图所示:

__________________________________________________

__________________________________________________

开始

求开始状态闭包

标记F令它为集合C中的唯一成员

集合C中存在尚未被标记子集

标记T

结束对子集T中的每个输入字母求U=Ia子集

将U加入C中

4、DFA转为MFA

化简DFA的基本思想是指导它的状态分成一些互不相交的子集,每一个子集中的状态都不是等价的,不同子集中的状态可以由某个输入串来区别,最后将不能区别的每个子集用一个状态来做代表,这种方法称为“分割法”。具体过程是:

(1)将M的所有状态分成两个子集——终态集和非终态集;

(2)考察每一个子集,若发现某子集中的状态不等价,将其划分为两个集合;

(3)重复第(2)步,继续考察已得到的每一个子集,直到没有任何一个子集需要继续划分为止。这时DFA的状态被分成若干个互不相交的子集。

(4)从每个子集中选出一个状态做代表即可得到最简的DFA。

六、程序实现环境及使用说明

__________________________________________________

__________________________________________________

本次实验采用Eclipse进行代码的编写、编译及运行;

编写语言为java语言;

程序的运行环境为jdk1.8;

系统为windows 8.1

七、实验测试用例设计说明

1、正规式验证

(1)输入””,这是一个错误的输入

(2)输入”ab|b”,这是一个正确的输入

2、正规式转为NFA

(1)输入”ab|b”,这是一个不含闭包的例子

(2)输入”(a*|b)*”,这是一个含有闭包的例子

3、NFA转为DFA

(1)输入”ab|b”,这是一个不含闭包的例子

(2)输入”(a*|b)*”,这是一个含有闭包的例子

4、DFA转为MFA

(1)输入”ab|b”,这是一个不含闭包的例子

(2)输入”(a*|b)*”,这是一个含有闭包的例子

八、实验结果测试情况

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

__________________________________________________

九、小组对实验结果的自我评价

通过这次实验,我对正规式、NFA、DFA、MFA有了一定的了解,进一步的巩固了这部分的知识。懂得了他们之间转化的原理。在编程过程中,遇到了不少的问__________________________________________________

__________________________________________________

题,在同学的帮助下,问题一步一步的得到了解决。同时,实验期间,老师也对程序进行了测试评价,发现了一些错误,比如,在将正规式转为NFA时,连接运算符与或运算符之间的处理出现了一些问题;还有,在最后将DFA转为MFA时,在MFA中出现了没有对相同的两项进行冗余处理。这些问题也在实验后期进行了一一解决。由于编程能力和时间的不足,这个转换器还有待完善,可能还有没有测试出来的错误。对于出错处理也考虑得不够周到。望老师多多指教。

十、任课教师对实验结果的评分

源码

package view;

import Layout;

import ;

import alog;

import yout;

import ;

import yout;

import Pane;

import ard;

import avor;

import Selection;

import erable;

import Event;

import Listener;

import nt;

import dapter;

import vent;

import Adapter;

import Event;

import edReader;

__________________________________________________

__________________________________________________

import edWriter;

import ;

import ader;

import iter;

import ption;

import g;

import ;

import ;

import ar;

import tem;

import nPane;

import ;

import Menu;

import rea;

import oke;

import ntEvent;

import ntListener;

import leEditEvent;

import leEditListener;

import nager;

public class FrameView extends JFrame implements ActionListener,

JMenuBar bar = new JMenuBar();

JMenu file = new JMenu("文件");

JMenu edit = new JMenu("编辑");

JMenu analysis = new JMenu("词法分析");

JMenu help = new JMenu("帮助");

JFrame f = new JFrame("词法分析器");

ScrollPane jspa = new ScrollPane();

ScrollPane jspb = new ScrollPane();

ScrollPane jspc = new ScrollPane();

JPopupMenu pop = new JPopupMenu();

JTextArea ta = new JTextArea();

JTextArea tb = new JTextArea();

JTextArea tc = new JTextArea();

JPanel pa = new JPanel();

JPanel pb = new JPanel();

JOptionPane jop = new JOptionPane();

UndoManager um = new UndoManager();

DocumentListener, UndoableEditListener {

__________________________________________________

__________________________________________________

dowListener(new WindowAdapter() {

public void windowClosing(WindowEvent we) {

setup();

public FrameView() {

isSave = false;

change = false;

isLine = true;

JMenuItem sHelp = new JMenuItem("查看帮助");

JMenuItem about = new JMenuItem("关于");

JMenuItem back1 = new JMenuItem("撤销");

JMenuItem cut1 = new JMenuItem("剪切");

JMenuItem copy1 = new JMenuItem("复制");

JMenuItem paste1 = new JMenuItem("粘贴");

JMenuItem del1 = new JMenuItem("删除");

JMenuItem all1 = new JMenuItem("全选");

FileDialog openDia = new FileDialog(f, "打开", );

FileDialog saveDia = new FileDialog(f, "保存", );

AboutFile prompta;

File fe;

Clipboard clipboard = null;

boolean isSave, change, isLine;

String select;

JMenuItem open = new JMenuItem("打开");

JMenuItem save = new JMenuItem("保存");

JMenuItem saveNew = new JMenuItem("另存为");

JMenuItem exit = new JMenuItem("退出");

JMenuItem back = new JMenuItem("撤销");

JMenuItem cut = new JMenuItem("剪切");

JMenuItem copy = new JMenuItem("复制");

JMenuItem paste = new JMenuItem("粘贴");

JMenuItem del = new JMenuItem("删除");

JMenuItem all = new JMenuItem("全选");

JMenuItem lexical = new JMenuItem("词法分析器");

JMenuItem nfadfamfa = new JMenuItem("NFA_DFA_MFA");

__________________________________________________

__________________________________________________

}

}

if ((isSave == false) && (change == true)) {

Prompt dg = new Prompt(f, "词法分析器", true);

} else

(0);

});

t(new Font("宋体", 0, 20));

eWrap(true);

table(false);

table(false);

pack();

nds(300, 100, 750, 550);

ible(true);

public void setup() {

setLayout(new BorderLayout());

nuBar(bar);

(ta);

(tb);

(tc);

out(new GridLayout(2, 1));

(jspb);

(jspc);

out(new GridLayout(1, 2));

(jspa);

(pb);

(pa);

(file);

(edit);

(analysis);

(help);

(open);

(save);

(saveNew);

arator();

(exit);

(back);

arator();

(cut);

__________________________________________________

__________________________________________________

(copy);

(paste);

(del);

arator();

arator();

(all);

arator();

(lexical);

(nfadfamfa);

(sHelp);

(about);

(back1);

arator();

(cut1);

(copy1);

(paste1);

(del1);

arator();

(all1);

monic('O');

elerator(Stroke(_O,

_MASK));

monic('S');

elerator(Stroke(_S,

_MASK));

monic('A');

elerator(Stroke(_A,

_MASK));

monic('X');

elerator(Stroke(_X,

_MASK));

monic('Z');

elerator(Stroke(_Z,

_MASK));

monic('X');

elerator(Stroke(_X,

_MASK));

monic('C');

elerator(Stroke(_C,

_MASK));

__________________________________________________

__________________________________________________

monic('V');

elerator(Stroke(_V,

_MASK));

monic('L');

elerator(Stroke(_DELETE,

monic('A');

elerator(Stroke(_A,

_MASK));

monic('L');

elerator(Stroke(_L,

_MASK));

monic('N');

elerator(Stroke(_N,

_MASK));

monic('H');

elerator(Stroke(_H,

_MASK));

monic('B');

elerator(Stroke(_B,

_MASK));

monic('Z');

elerator(Stroke(_Z,

_MASK));

monic('X');

elerator(Stroke(_X,

_MASK));

monic('C');

elerator(Stroke(_C,

_MASK));

monic('V');

elerator(Stroke(_V,

_MASK));

monic('L');

elerator(Stroke(_DELETE,

monic('A');

elerator(Stroke(_A,

_MASK));

0));

0));

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

__________________________________________________

__________________________________________________

if (dirPath == null || fileName == null)

return;

t("");

fe = new File(dirPath, fileName);

try {

BufferedReader in = new BufferedReader(new FileReader(fe));

public void openFile() {

ible(true);

String dirPath = ectory();

String fileName = e();

}

seListener(new MouseAdapter() {

public void mousePressed(MouseEvent me) {

}

if (ton() == 3) {

}

(ta, (), ());

ument().addDocumentListener(this);

ument().addUndoableEditListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

ionListener(this);

});

__________________________________________________

__________________________________________________

}

}

String line = null;

while ((line = ne()) != null)

(line + "rn");

();

etPosition(0);

n(ioe);

} catch (IOException ioe) {

public void saveFile() {

}

public void undoableEditHappened(UndoableEditEvent ue) {

}

public void changedUpdate(DocumentEvent e) {

}

public void insertUpdate(DocumentEvent e) {

change = true;

change = true;

t(t());

if (fe == null) {

}

isSave = true;

change = false;

try {

}

BufferedWriter out = new BufferedWriter(new FileWriter(fe));

String text = t();

(text);

();

();

n(ioe);

ible(true);

String dirPath = ectory();

String fileName = e();

if (dirPath == null || fileName == null)

return;

t("");

File fe = new File(dirPath, fileName);

} catch (IOException ioe) {

__________________________________________________

__________________________________________________

}

public void removeUpdate(DocumentEvent e) {

}

public void actionPerformed(ActionEvent ae) {

if (t().equals(""))

change = false;

change = true;

if (rce() == open) {

}

if (rce() == save) {

}

if (rce() == saveNew) {

}

if (rce() == exit) {

}

if (rce() == back || rce() == back1) {

}

if (rce() == cut || rce() == cut1) {

try {

clipboard = getToolkit().getSystemClipboard();

select = ectedText();

if (() != 0) {

StringSelection text = new StringSelection(select);

if (o()) {

}

();

if ((isSave == false) && (change == true)) {

Prompt dg = new Prompt(f, "词法分析器", true);

} else

(0);

saveFile();

if (isSave == false)

saveFile();

openFile();

change = false;

__________________________________________________

__________________________________________________

}

}

}

tents(text, null);

eRange("", ectionStart(),

ectionEnd());

} catch (Exception e) {

n(e);

if (rce() == copy || rce() == copy1) {

}

if (rce() == paste || rce() == paste1) {

}

if (rce() == del || rce() == del1) {

}

if (rce() == all || rce() == all1) {

eSelection(null);

Transferable contents = tents(this);

DataFlavor flavor = Flavor;

if (FlavorSupported(flavor))

try {

}

String str;

str = (String) nsferData(flavor);

(str, etPosition());

n(e);

try {

clipboard = getToolkit().getSystemClipboard();

select = ectedText();

if (() != 0) {

}

StringSelection text = new StringSelection(select);

tents(text, null);

} catch (Exception e) {

}

n(e);

} catch (Exception e) {

__________________________________________________

__________________________________________________

}

All();

if (rce() == lexical) {

}

if (rce() == nfadfamfa) {

}

if (rce() == sHelp) {

nds(300, 300, 250, 150);

ssageDialog(null, "无法启动“Windows帮助和支持”", " _MESSAGE);

}

ible(true);

tackTrace();

try {

NDMdialog dialog = new NDMdialog("NFA_DFA_MFA");

bled(false);

aultCloseOperation(E_ON_CLOSE);

} catch (Exception e) {

查看",

}

}

}

if (rce() == about) {

AboutFile af = new AboutFile(f, "词法分析器", true);

}

public static void main(String[] args) {

}

FrameView fv = new FrameView();

package view;

import Layout;

import ;

__________________________________________________

__________________________________________________

import yout;

import ;

import Event;

import Listener;

import Adapter;

import Event;

import n;

import g;

import ;

import ;

public class Prompt extends JDialog implements ActionListener {

setBounds(450, 300, 250, 150);

kground();

kground();

kground();

out(new FlowLayout());

kground(_GRAY);

(ok);

(no);

(cancel);

JLabel lb = new JLabel("是否需要将更改保存?", );

setLayout(new BorderLayout());

setBackground();

JPanel pl = new JPanel();

add("South", pl);

add("Center", lb);

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent we) {

}

dispose();

JButton ok = new JButton("保存");

JButton no = new JButton("不保存");

JButton cancel = new JButton("取消");

public Prompt(Frame parent, String title, Boolean d) {

super(parent, title, true);

});

__________________________________________________

__________________________________________________

}

}

ionListener(this);

ionListener(this);

ionListener(this);

setVisible(true);

public void actionPerformed(ActionEvent e) {

}

if (rce() == ok) {

}

if (rce() == no)

(0);

FrameView my = new FrameView();

le();

if (rce() == cancel)

e();

package view;

import Layout;

import ;

import ;

import yout;

import Event;

import Listener;

import Adapter;

import Event;

import n;

import g;

import ;

import ;

import rea;

public class AboutFile extends JDialog implements ActionListener {

public AboutFile(Frame parent, String title, Boolean k) {

super(parent, title, true);

__________________________________________________

__________________________________________________

}

public void actionPerformed(ActionEvent e) {

}

dispose();

}

add("South", pla);

add("Center", plb);

JButton confirm = new JButton("确定");

(confirm);

JTextArea t = new JTextArea();

table(false);

setBounds(490, 300, 250, 150);

ionListener(this);

setVisible(true);

out(new GridLayout(3, 1));

(lba);

(lbb);

(lbc);

JPanel pla = new JPanel();

JPanel plb = new JPanel();

JLabel lba = new JLabel("感谢老师和各位队友的帮助", );

JLabel lbb = new JLabel("版权人:崔立志", );

JLabel lbc = new JLabel("出版日期:2014年", );

que(true);

setLayout(new BorderLayout());

setBackground();

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent we) {

}

dispose();

});

package view;

import Layout;

__________________________________________________

__________________________________________________

import alog;

import yout;

import n;

import g;

import hooser;

import ;

import nPane;

import ;

import order;

import Listener;

import Event;

import ;

import ield;

import yout;

import rea;

import de;

import lPane;

import Pane;

import ea;

import onstants;

import rder;

import ;

import edReader;

import edWriter;

import ;

import ader;

import iter;

import ption;

import Border;

import FA;

import siontoNFA;

import FA;

import ;

__________________________________________________

__________________________________________________

public class NDMdialog extends JDialog {

/**

* Launch the application.

*/

try {

}

NDMdialog dialog = new NDMdialog("NFA_DFA_MFA");

aultCloseOperation(E_ON_CLOSE);

ible(true);

tackTrace();

JLabel nfastart = new JLabel("开始状态集:");

JLabel nfaend = new JLabel("终结状态集:");

JLabel dfastart = new JLabel("开始状态集:");

JLabel dfaend = new JLabel("终结状态集:");

JLabel mfastart = new JLabel("开始状态集:");

JLabel mfaend = new JLabel("终结状态集:");

JButton nfa = new JButton("生成NFA");

JButton dfa = new JButton("生成DFA");

JButton mfa = new JButton("生成MFA");

private JFileChooser filechooser = new JFileChooser(

"D:Usersclz0730Desktop");

private int result;

File fe;

FileDialog openDia = new FileDialog(this, "打开", );

FileDialog saveDia = new FileDialog(this, "保存", );

JTextArea nfata = new JTextArea();

JTextArea dfata = new JTextArea();

JTextArea mfata = new JTextArea();

private final JPanel contentPanel = new JPanel();

private JTextField expression;

private String signString;

JDialog dialog = new JDialog();

// public static void main(String[] args) {

//

//

//

//

//

//

//

// }

public void openFile(JTextArea ta, JLabel startlabel, JLabel

} catch (Exception e) {

__________________________________________________

__________________________________________________

endlabel,

public void saveFile(JTextArea ta, JLabel startlabel, JLabel

String str) {

+ "rn" + str + "rn";

endlabel,

String temp = t() + "rn" + t()

result = veDialog(dialog);

if (result == E_OPTION) {

}

try {

if (fe != null) {

BufferedWriter out = new BufferedWriter(new

fe = ectedFile();

}

String str) {

result = enDialog(dialog);

t("");

if (result == E_OPTION) {

}

if (fe != null) {

}

try {

}

BufferedReader in = new BufferedReader(new

fe = ectedFile();

FileReader(fe));

String line = null;

if ((line = ne()) != null) {

}

if ((line = ne()) != null) {

}

if ((line = ne()) != null) {

}

while ((line = ne()) != null) {

}

();

etPosition(0);

n(ioe);

(line + "rn");

signString = line;

t(line);

t(line);

} catch (IOException ioe) {

__________________________________________________

__________________________________________________

FileWriter(fe));

/**

* Create the dialog.

*/

public NDMdialog(String title) {

setBounds(100, 100, 772, 496);

getContentPane().setLayout(new BorderLayout());

der(new EmptyBorder(5, 5, 5, 5));

getContentPane().add(contentPanel, );

out(new BorderLayout(0, 0));

{

JPanel panel = new JPanel();

TitledBorder(null, "表达式",

}

}

}

n(ioe);

String text = t();

(temp);

(text);

();

();

} catch (IOException ioe) {

der(new

G,

, null, ));

(panel, );

FlowLayout fl_panel = new FlowLayout(, 20,

out(fl_panel);

{

}

{

}

{

}

{

JLabel lblab = new JLabel("例如:(a*|b)*");

(lblab);

expression = new JTextField();

(expression);

umns(15);

JLabel lblNewLabel = new JLabel("输入一个正规式:");

(lblNewLabel);

5);

__________________________________________________

__________________________________________________

}

{

}

JButton verify = new JButton("验证正规式");

ionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

}

Verify vf = new

Verify(t().toString());

// n(tion());

if (tion()) {

}

bled(true);

JOptionPane jop = new JOptionPane();

nds(250, 300, 250, 150);

ssageDialog(null, "您输入的正规式错 "Compiler", G_MESSAGE);

} else {

误!!!",

}

{

});

(verify);

JButton exit = new JButton("退出");

ionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

}

(0);

});

(exit);

JPanel panel = new JPanel();

(panel, );

out(new GridLayout(1, 3));

{

JPanel panel_1 = new JPanel();

(panel_1);

panel_out(new BorderLayout(0, 0));

{

JPanel panel_2 = new JPanel();

panel_out(new GridLayout(2, 1));

JLabel lblNewLabel_1 = new JLabel("正规式->NFA");

JLabel lblNewLabel_3 = new JLabel("起始状态");

JLabel lblNewLabel_4 = new JLabel("接受符号");

JLabel lblNewLabel_5 = new JLabel("到达状态");

__________________________________________________

__________________________________________________

{

JPanel panel_3 = new JPanel();

panel_out(new GridLayout(1, 3));

panel_(lblNewLabel_3);

panel_(lblNewLabel_4);

panel_(lblNewLabel_5);

panel_(lblNewLabel_1);

panel_(panel_3);

lblNewLabel_izontalAlignment();

}

{

}

{

JPanel panel_2 = new JPanel();

panel_(panel_2, );

panel_out(new GridLayout(3, 1, 0, 0));

{

}

{

}

{

JPanel panel_3 = new JPanel();

panel_(panel_3);

panel_out(new

{

JButton nfaopen = new JButton("NFA文件");

ionListener(new ActionListener()

public void actionPerformed(ActionEvent

openFile(nfata, nfastart, nfaend,

signString);

bled(true);

5));

panel_(nfaend);

panel_(nfastart);

ScrollPane scrollPane = new ScrollPane();

panel_(scrollPane, );

{

}

s(10);

(nfata, );

panel_(panel_2, );

FlowLayout(, 5,

arg0) {

__________________________________________________

__________________________________________________

{

}

{

}

}

}

{

}

{

}

});

panel_(nfaopen);

ionListener(new ActionListener() {

public void actionPerformed(ActionEvent

}

ExpressiontoNFA

en = new

arg0) {

ExpressiontoNFA(

t().trim()

.toString());

y();

t(ng);

t(rtstr);

t(str);

signString = ring;

bled(true);

});

bled(false);

panel_(nfa);

JButton nfasave = new JButton("保存");

ionListener(new ActionListener()

}

public void actionPerformed(ActionEvent

}

saveFile(nfata, nfastart, nfaend,

signString);

arg0) {

});

panel_(nfasave);

JPanel panel_1 = new JPanel();

(panel_1);

panel_out(new BorderLayout(0, 0));

{

JPanel panel_2 = new JPanel();

__________________________________________________

__________________________________________________

{

panel_out(new GridLayout(2, 1));

JLabel lblNewLabel_2 = new JLabel("NFA->DFA");

JLabel lblNewLabel_3 = new JLabel("起始状态");

JLabel lblNewLabel_4 = new JLabel("接受符号");

JLabel lblNewLabel_5 = new JLabel("到达状态");

JPanel panel_3 = new JPanel();

panel_out(new GridLayout(1, 3));

panel_(lblNewLabel_3);

panel_(lblNewLabel_4);

panel_(lblNewLabel_5);

panel_(lblNewLabel_2);

panel_(panel_3);

lblNewLabel_izontalAlignment();

}

{

}

{

JPanel panel_2 = new JPanel();

panel_(panel_2, );

panel_out(new GridLayout(3, 1, 0, 0));

{

}

{

}

{

JPanel panel_3 = new JPanel();

panel_(panel_3);

panel_out(new

{

JButton dfaopen = new JButton("DFA文件");

ionListener(new ActionListener()

5));

panel_(dfaend);

panel_(dfastart);

ScrollPane scrollPane = new ScrollPane();

panel_(scrollPane, );

{

}

s(10);

(dfata, );

panel_(panel_2, );

FlowLayout(, 5,

__________________________________________________

__________________________________________________

{

}

{

}

{

public void actionPerformed(ActionEvent

}

openFile(dfata, dfastart, dfaend,

signString);

bled(true);

arg0) {

});

panel_(dfaopen);

bled(false);

ionListener(new ActionListener() {

public void actionPerformed(ActionEvent

}

String

String

String

str

ss1

ss2

=

=

=

arg0) {

t().toString();

t().toString();

t().toString();

NFAtoDFA nd = new NFAtoDFA(str, ss1,

signString);

ss2,

y();

t(ng);

t(tring);

t(ing);

signString = ring;

bled(true);

});

panel_(dfa);

JButton dfasave = new JButton("保存");

ionListener(new ActionListener()

public void actionPerformed(ActionEvent

}

saveFile(dfata, dfastart, dfaend,

signString);

arg0) {

});

panel_(dfasave);

__________________________________________________

__________________________________________________

}

{

}

}

}

JPanel panel_1 = new JPanel();

(panel_1);

panel_out(new BorderLayout(0, 0));

{

JPanel panel_2 = new JPanel();

panel_out(new GridLayout(2, 1));

JLabel lblNewLabel_3 = new JLabel("DFA->MFA");

JLabel lblNewLabel_2 = new JLabel("起始状态");

JLabel lblNewLabel_4 = new JLabel("接受符号");

JLabel lblNewLabel_5 = new JLabel("到达状态");

JPanel panel_3 = new JPanel();

panel_out(new GridLayout(1, 3));

panel_(lblNewLabel_2);

panel_(lblNewLabel_4);

panel_(lblNewLabel_5);

panel_(lblNewLabel_3);

panel_(panel_3);

lblNewLabel_izontalAlignment();

}

{

}

{

JPanel panel_2 = new JPanel();

panel_(panel_2, );

panel_out(new GridLayout(3, 1, 0, 0));

{

}

{

}

panel_(mfaend);

panel_(mfastart);

ScrollPane scrollPane = new ScrollPane();

panel_(scrollPane, );

{

}

s(10);

(mfata, );

panel_(panel_2, );

__________________________________________________

__________________________________________________

{

{

{

JPanel panel_3 = new JPanel();

panel_(panel_3);

panel_out(new

{

JButton mfaopen = new JButton("MFA文件");

ionListener(new ActionListener()

}

{

}

{

JButton mfasave = new JButton("保存");

ionListener(new ActionListener()

public void actionPerformed(ActionEvent

bled(false);

ionListener(new ActionListener() {

public void actionPerformed(ActionEvent

}

String ss = t().toString();

String

String

ss1

ss2

=

=

public void actionPerformed(ActionEvent

}

openFile(mfata, mfastart, mfaend,

signString);

5));

FlowLayout(, 5,

arg0) {

});

panel_(mfaopen);

arg0) {

t().toString();

t().toString();

DFAtoMFA dm = new DFAtoMFA(ss, ss1, ss2,

signString);

y();

t(ng);

t(rtstr);

t(str);

signString = ring;

});

panel_(mfa);

__________________________________________________

__________________________________________________

arg0) {

}

}

}

}

}

}

}

}

saveFile(mfata, mfastart, mfaend,

signString);

});

panel_(mfasave);

package operation;

public class Verify {

{

}

if ((ch[0] == '(') || (ch[0] >= 'a' && ch[0] <= 'z')

|| (ch[0] >= 'A' && ch[0] <= 'Z')

|| (ch[0] >= '0' && ch[0] <= '9')) {

find++;

return false;

public boolean validation() {

int find = 0;// 标记括号

boolean result = false;

// String ss = "(a*|b)*";//(a*|b)*

if (("")) {

}

char[] ch = Array();

if (ch[0] == '*' || ch[0] == ')' || ch[0] == '|' || ch[0] == '.')

return true;

public Verify(String tx) {

}

ss = tx;

String ss;

if (ch[0] == '(') {

__________________________________________________

__________________________________________________

}

}

for (int i = 1; i < - 1; i++) {

}

if (find == 0)

result = true;

return false;

if (find != 0)

if (ch[i] == '(') {

}

if (ch[i] == ')') {

}

if (ch[i] == '|') {

}

if (ch[i] == '*' || ch[i] == '.') {

}

if ((ch[i - 1] == ')'

|| (ch[i - 1] >= 'A' && ch[i - 1] <= 'Z')

|| (ch[i - 1] >= 'a' && ch[i - 1] <= 'z') || (ch[i

&& (i + 1 < )

&& (ch[i + 1] == '|' || ch[i + 1] == ')'

|| ch[i + 1] == '('

|| (ch[i + 1] >= 'A' && ch[i + 1] <= 'Z')

|| (ch[i + 1] >= 'a' && ch[i + 1] <= 'z')

if ((ch[i - 1] == '*' || ch[i - 1] == ')'

|| (ch[i - 1] >= 'A' && ch[i - 1] <= 'Z')

|| (ch[i - 1] >= 'a' && ch[i - 1] <= 'z') || (ch[i

&& (i + 1 < )

&& (ch[i + 1] == '('

|| (ch[i + 1] >= 'A' && ch[i + 1] <= 'Z')

|| (ch[i + 1] >= 'a' && ch[i + 1] <= 'z')

find--;

find++;

- 1] >= '0' && ch[i - 1] <= '9'))

|| (ch[i + 1] >= '0' && ch[i + 1] <= '9'))) {

result = true;

return false;

} else

- 1] >= '0' && ch[i - 1] <= '9'))

|| (ch[i + 1] >= '0' && ch[i + 1] <= '9'))) {

result = true;

return false;

} else

if (ch[ - 1] == ')' || ch[ - 1] == '*'

__________________________________________________

__________________________________________________

|| ch[ - 1] == '.'

|| (ch[ - 1] >= 'a' && ch[ - 1] <= 'z')

|| (ch[ - 1] >= 'A' && ch[ - 1] <= 'Z')

|| (ch[ - 1] >= '0' && ch[ - 1] <= '9'))

{

if (ch[ - 1] == ')') {

find--;

result = true;

}

} else {

return false;

}

return true;

}

// public static void main(String[] args) {

// // TODO Auto-generated method stub

// Verify vf = new Verify();

// n(tion());

// }

}

package operation;

public class Node {

private String start;

private String recive;

private String end;

public Node() {

super();

}

public Node(String start, String recive, String end) {

super();

= start;

= recive;

= end;

}

__________________________________________________

__________________________________________________

}

public String getStart() {

}

public void setStart(String start) {

}

public String getRecive() {

}

public void setRecive(String recive) {

}

public String getEnd() {

}

public void setEnd(String end) {

}

public String toString() {

}

return start + "t" + recive + "t" + end;

= end;

return end;

= recive;

return recive;

= start;

return start;

package operation;

import ist;

import or;

import ;

public class ExpressiontoNFA {

public ExpressiontoNFA(String expression) {

ch = Array();

char[] ch;

__________________________________________________

__________________________________________________

}

ArrayList nfanode = new ArrayList();

Stack startstack = new Stack();

Stack endstack = new Stack();

public String tastring = "";

public String nfastartstr = "开始状态集:";

public String nfaendstr = "终结状态集:";

public String signstring = "符号集:";

int index = 1;

public void init() {

}

public void display() {

convert();

Iterator it = or();

while (t()) {

}

if (!y()) {

}

if (!y()) {

}

// n(tastring);

// n(signstring);

// n(nfastartstr);

nfaendstr += () + ";";

nfastartstr += () + ";";

Node node = ();

tastring += node + "rn";

// String expression = "(a*|b)*";// (a*|b)*

// ch = Array();

ArrayList al = new ArrayList();

for (int i = 0; i < ; i++) {

}

Iterator it = or();

while (t()) {

}

signstring += () + ";";

if (ch[i] >= 'a' && ch[i] <= 'z') {

}

if (!ns(f(ch[i]))) {

}

(f(ch[i]));

__________________________________________________

__________________________________________________

}

// n(nfaendstr);

public void convert() {

init();

String startnode = "";

String recivenode = "";

String endnode = "";

String tempstack = "";

String nodetemp = "";

String endtemp = "";

int find = 0;//

for (int i = 0; i < ; i++) {

while (i < && ch[i] >= 'a' && ch[i] <= 'z') {

}

endtemp = endnode;

if (i < && ch[i] == '|') {

// find=1;

i++;

while (i < && ch[i] >= 'a' && ch[i] <= 'z') {

startnode = f(index++);

recivenode = f(ch[i]);

endnode = f(index++);

(new Node(startnode, recivenode,

startnode = f(index++);

recivenode = f(ch[i]);

endnode = f(index++);

(new Node(startnode, recivenode, endnode));

(startnode);

while (!y()) {

}

i++;

if (find == 1) {

}

(endnode);

();

find = 0;

find = 1;

tempstack = ();

(new Node(tempstack, "#",

()));

endnode));

(startnode);

i++;

__________________________________________________

__________________________________________________

}

}

}

}

}

(endnode);

// 将第二部分中的每个节点连接起来

nodetemp = ();

while (!().equals(endtemp)) {

}

(nodetemp);

startnode = f(index++);

while (!y()) {

}

(startnode);

endnode = f(index++);

while (!y()) {

}

(endnode);

tempstack = ();

(new Node(tempstack, "#", endnode));

tempstack = ();

(new Node(startnode, "#", tempstack));

endnode = ();

startnode = ();

(new Node(endnode, "#", startnode));

if (i < && ch[i] == '*') {

}

(new Node((), "#",

()));

startnode = f(index++);

(new Node(startnode, "#", ()));

(startnode);

endnode = f(index++);

(new Node((), "#", endnode));

(endnode);

(new Node(startnode, "#", endnode));

// public static void main(String[] args) {

// ExpressiontoNFA en = new ExpressiontoNFA();

// y();

// }

__________________________________________________

__________________________________________________

package operation;

import ist;

import tions;

import or;

import ;

public class NFAtoDFA {

ArrayList dfanode = new ArrayList();// 存储DFA中的节点信息

ArrayList movenode = new ArrayList();

Object[][] statuearray = new Object[30][2];// 存储T以及T中状态

// String start = "7";

String start = "";

// String[] end ;

// String[] end = {"8"};

// String[] sign = { "a", "b" };

public String tbstring = "";

ArrayList nfanode = new ArrayList();// 存储NFA中的节点信public NFAtoDFA(String nfatext, String starttemp, String endtemp,

}

String signstring) {

temp = ("t|rn");// (a*|b)*

start = ("[;:]")[1];

String[] str_temp = ("[;:]");

end = new String[str_ - 1];

for (int i = 1; i < str_; i++) {

}

String[] sign_temp = ("[;:]");

sign = new String[sign_ - 1];

for (int i = 1; i < sign_; i++) {

}

sign[i - 1] = sign_temp[i];

end[i - 1] = str_temp[i];

String temp[];

String[] end;

String[] sign;

__________________________________________________

__________________________________________________

public String startstring = "开始状态集:";

public String endstring = "终结状态集:";

public String signstring = "符号集:";

// 初始化数据

public void nfainit() {

// String nfatext =

//

"1tat2n3tbt4n2t#t3n5tbt6n7t#t5n7t#t1n6t#t8n4t#t8n";

public void display() {

firstnode();

String dfastart = "";

String dfaend = "";

String start1 = "";

String end1 = "";

Iterator dit = or();

while (t()) {

Node node = ();

dfastart = rt();

dfaend = ();

tbstring += node + "rn";

int finda = 0;

int findb = 0;

int find = 0;

start1 = "";

end1 = "";

Iterator it1 = or();

while (t()) {

Node node1 = ();

start1 = rt();

end1 = ();

if ((end1)) {

}

// temp = ("[tn]");

// n(temp[0]);

for (int i = 0; (i + 2) < ;) {

}

for (int i = 0; i < ; i++) {

}

signstring = signstring + sign[i] + ";";

(new Node(temp[i], temp[i + 1], temp[i + 2]));

i = i + 3;

__________________________________________________

__________________________________________________

}

}

}

}

finda = 1;

break;

if ((start1)) {

}

findb = 1;

break;

if (finda == 0) {

}

if (findb == 0) {

}

find = 0;

char[] ch = Array();

for (int i = 0; i < ; i++) {

}

if (find == 0) {

}

endstring = endstring + dfaend + ";";

if ((f(ch[i]))) {

}

find = 1;

break;

find = 0;

char[] ch = Array();

for (int i = 0; i < ; i++) {

}

if (find == 0) {

}

startstring = startstring + dfastart + ";";

if ((f(ch[i]))) {

}

find = 1;

break;

// n(tbstring);

// n(startstring);

// n(endstring);

public void convert(int statue) {

String temp = "";

for (int i = 0; (statue <= )

&& (i < ) && (statuearray[i][1] != null)

__________________________________________________

__________________________________________________

}

}

&& ((Boolean) statuearray[i][1] == false); i++) {

// 标记T

statuearray[i][1] = true;

// 循环每个输入字母

for (int j = 0; j < ; j++) {

}

temp = move(statuearray[i], sign[j]);

if (!("")) {

}

ArrayList listtemp = new ArrayList();

ArrayList statuetemp = new

ArrayList();

listtemp = closure(temp);

int find = 0;

for (int k = 0; k < && k < statue

}

if (find == 0) {

}

statue++;

if (statue < ) {

}

statuearray[statue][0] = listtemp;

statuearray[statue][1] = false;

(new

Node(f(i),

statuetemp = (ArrayList)

+ 1; k++) {

statuearray[k][0];

if (statuetemp != null) {

}

// 排序

(statuetemp);

(listtemp);

if ((listtemp)) {

}

find = 1;

(new Node(f(i),

sign[j], f(k)));

sign[j],

f(statue)));

public void firstnode() {

nfainit();

__________________________________________________


本文标签: 实验 状态 进行 子集 符号