云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 词法分析器设计实验报告

词法分析器设计实验报告

  • 62 次阅读
  • 3 次下载
  • 2025/5/2 12:18:07

dataGridView2.Rows.Add(dgr); } }

catch (Exception) {

; } }

private void addData2(String s1,String s2,String s3,String s4,String s5) { DataGridViewRow dgr = new DataGridViewRow();

DataGridViewTextBoxCell dgt1 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dgt2 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dgt3 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dgt4 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dgt5 = new DataGridViewTextBoxCell(); dgt1.Value = s1; dgt2.Value = s2; dgt3.Value = s3; dgt4.Value = s4; dgt5.Value = s5; dgr.Cells.Add(dgt1); dgr.Cells.Add(dgt2); dgr.Cells.Add(dgt3); dgr.Cells.Add(dgt4); dgr.Cells.Add(dgt5);

dataGridView1.Rows.Add(dgr); }

private Char getStackBottom(String s) { if (s == \ return '\\0';

else if ((s[0] > 'a') && s[0] <= 'z') return 'i'; else

return s[0]; }

private void Error() {

MessageBox.Show(\出现错误\ }

private PLACE SearchSheet(String[,] sheet,Char c,Char a){ PLACE place = new PLACE();

for (int i = 0; i < Terminator.Length; i++) { if (Terminator[i] == a)

place.y = i; }

for (int i = 0; i < nonterminal.Length; i++) {

if (nonterminal[i] == c) place.x = i; }

if (sheet[place.x, place.y] != \ place.flag = true; else

place.flag = false; return place; }

private String Reverse(String s) { String str = \

for (int i = 0; i < s.Length; i++) {

str = str + s[s.Length - i - 1]; }

return str; }

private void mainControlProgram(String[,] sheet,String s) {

bool FLAG = true; Char c=' ';//符号栈顶 Char a=' ';//输入串栈底 String temStack = \ String temS = \

String action = \初始化\ int k = 0;

STACK = \ a=getStackBottom(s); while (FLAG) {

c = STACK[STACK.Length - 1]; if (!(temStack == STACK)) {

PLACE place = new PLACE(); place = SearchSheet(sheet, c, a);

addData2(k.ToString(), STACK, s, temS,action); action = \

if (sheet[place.x, place.y] != null place.y].Contains('@'))

temS = sheet[place.x, place.y]; else

&& sheet[place.x,

temS = \ k++; }

STACK = STACK.Remove(STACK.Length-1); action = action + \ if (terminator.Contains(c)) {

if (c == a){

s = Reverse(s).Remove(s.Length-1); action = \ s = Reverse(s);

a = getStackBottom(s); } else

Error(); }

else if (c == '#') { if (c == a)

FLAG = false; else

Error(); }

else if(SearchSheet(sheet,c,a).flag){ PLACE place = new PLACE(); place=SearchSheet(sheet, c, a); String str =Reverse(sheet[place.x, place.y]+\ str=str.Remove(str.Length-3); if (!(str == \

STACK = STACK + str;

action = action + \)\ temStack = STACK;

addData2(k.ToString(), STACK, s, sheet[place.x, place.y], action); action = \ k++; } } } }

private void button1_Click(object sender, EventArgs e) {

String first_s=\

String follow_s=\

terminator = getTerminator((richTextBox1.Text+\ nonterminal = getNonterminal((richTextBox1.Text + \ production = getProductions((richTextBox1.Text + \ FIRST[] first = new FIRST[20];

FOLLOW[]follow=new FOLLOW[20]; for (int i = 0; i < nonterminal.Length; i++) {

first[i] = getFirst(nonterminal[i]);

first_s = first_s + first[i].noter + \的First集为:\ }

richTextBox2.Text = first_s;

for (int i = 0; i < nonterminal.Length; i++) {

follow[i] = getFollow(nonterminal[i]);

follow_s = follow_s + follow[i].noter + \的Follow集为:\+ '\\n';

}

richTextBox4.Text = follow_s; String [,]sheet=new String[20,20]; sheet=getAnalysis_Sheet(first, follow); addData(sheet);

mainControlProgram(sheet,richTextBox3.Text);//进入主控程序 } } }

七、实验总结

本次实验经过多个文法进行测试,能够正确的构造FIRST集和FOLLOW集以及 LL(1)分析表。能够做到完全自动化。通过上次实验的C#的编程学习,为这次编写LL(1)分析器做好了充分的铺垫。能够熟练的掌握C#的编程技巧。为下次实验打下基础。

搜索更多关于: 词法分析器设计实验报告 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

dataGridView2.Rows.Add(dgr); } } catch (Exception) { ; } } private void addData2(String s1,String s2,String s3,String s4,String s5) { DataGridViewRow dgr = new DataGridViewRow(); DataGridViewTextBoxCell dgt1 = new DataGr

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com