第一范文网 - 专业文章范例文档资料分享平台

词法分析器设计实验报告

来源:用户分享 时间:2025/5/29 6:41:35 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

}

public struct S_GOTO {

public int s_num;//状态号 public Char Terminator; public int Goto; }

public S_ACTION []Action=new S_ACTION[100]; public S_GOTO []Goto=new S_GOTO[50];

public Stack S_Stack = new Stack { };//状态栈 public String Sym_Stack;//符号栈 public String In_Stack;//输入串栈

public S_PRODUCTION[] Production = new S_PRODUCTION[6]; public String ACTION(int s_num, Char Terminator) {

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

if (Action[i].s_num==s_num&&Action[i].Terminator==Terminator) {

return Action[i].Action; } }

return null; }

public int GOTO(int s_num, Char Terminator) {

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

if (Goto[i].s_num == s_num && Goto[i].Terminator == Terminator) {

return Goto[i].Goto; } }

return -1; }

public Form1() {

InitializeComponent();

this.dataGridView1.ColumnHeadersHeight = 40; this.dataGridView1.ColumnHeadersHeightSizeMode DataGridViewColumnHeadersHeightSizeMode.DisableResizing;

this.dataGridView1.AddSpanHeader(1, 6, \动作)\ this.dataGridView3.ColumnHeadersHeight = 40; this.dataGridView3.ColumnHeadersHeightSizeMode DataGridViewColumnHeadersHeightSizeMode.DisableResizing;

=

=

this.dataGridView3.AddSpanHeader(0, 3, \转换)\ textBox1.Text = \ }

private void InitProduction() { Production[0].num = 1;

Production[0].Nonterminal = 'E'; Production[0].Production = \

Production[1].num = 2;

Production[1].Nonterminal = 'E'; Production[1].Production = \

Production[2].num = 3;

Production[2].Nonterminal = 'T'; Production[2].Production = \

Production[3].num = 4;

Production[3].Nonterminal = 'T'; Production[3].Production = \

Production[4].num = 5;

Production[4].Nonterminal = 'F'; Production[4].Production = \

Production[5].num = 6; Production[5].Nonterminal = 'F'; Production[5].Production = \ }

private void addActionData(){

DataTable dt = new DataTable(); dt.Columns.Add(\ dt.Columns.Add(\ dt.Columns.Add(\ dt.Columns.Add(\ dt.Columns.Add(\ dt.Columns.Add(\ dt.Columns.Add(\ for (int i = 0; i <12; i++) {

for (int j = 0; j < Action.Length-6; j++) {

if (Action[j].s_num==i&&Action[j].Terminator=='i') {

dt.Rows.Add(i.ToString(), Action[j].Action, Action[j+1].Action,

Action[j+2].Action, Action[j+3].Action, Action[j+4].Action, Action[j+5].Action); break; } } }

this.dataGridView1.DataSource = dt; }

private void addGotoData(){

DataTable dt = new DataTable(); dt.Columns.Add(\ dt.Columns.Add(\ dt.Columns.Add(\ String data1,data2,data3;

for (int j = 0; j < Goto.Length - 6; j++) if (Goto[j].Terminator == 'E') {

data1 = Goto[j].Goto.ToString(); data2=Goto[j+1].Goto.ToString(); data3 = Goto[j + 2].Goto.ToString(); if (Goto[j].Goto == 0) data1 = \

if (Goto[j+1].Goto == 0) data2 = \

if (Goto[j+2].Goto == 0) data3 = \ dt.Rows.Add(data1, data2, data3); }

this.dataGridView3.DataSource = dt; }

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 InitStack(){ S_Stack.Clear(); S_Stack.Push(0); Sym_Stack = \

In_Stack = textBox1.Text+\

}

private int getStringInt(String s) { int num = 0; String str=\ if (s != null) {

for (int i = 1; i < s.Length; i++) str = str + s[i]; try {

num = int.Parse(str); }

catch (Exception) {

error = 1;

MessageBox.Show(\输入字符串有错误,请检查错误!\ } } else {

error = 1;

MessageBox.Show(\输入字符串有错误,请检查错误!\ }

return num; }

private void addData(String s1,String s2,String s3,String s4,String s5){ DataGridViewRow dgr = new DataGridViewRow(); DataGridViewTextBoxCell dgc1 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dgc2 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dgc3 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dgc4 = new DataGridViewTextBoxCell(); DataGridViewTextBoxCell dgc5 = new DataGridViewTextBoxCell(); dgc1.Value = s1; dgc2.Value = s2; dgc3.Value = s3; dgc4.Value = s4; dgc5.Value = s5; dgr.Cells.Add(dgc1); dgr.Cells.Add(dgc2); dgr.Cells.Add(dgc3); dgr.Cells.Add(dgc4); dgr.Cells.Add(dgc5);

dataGridView2.Rows.Add(dgr); }

private String getStackString(Stack stack) {

搜索更多关于: 词法分析器设计实验报告 的文档
词法分析器设计实验报告.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c1dolg1f4jy072ie1ycam_9.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top