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

词法分析器设计实验报告

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

}

index++; } }

return productions; }

//获取单一字符串

private String getSingleString(String s) {

String str = \

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

if (!str.Contains(s[i])) str = str + s[i]; }

return str; }

private FIRST getFirst(Char c){ FIRST First = new FIRST(); First.noter = c;

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

if (production[i].noter == c) {

if (terminator.Contains(production[i].production[0])) {

First.first = First.first + production[i].production[0]; if (production[i].production[0] == '@') {

flag = 1; } }

else if (nonterminal.Contains(production[i].production[0])) {

First.first = First.first + getFirst(production[i].production[0]).first; if(flag==1){ flag = 0; First.first = First.first + getFirst(production[i].production[1]).first; }

} } }

First.first = getSingleString(First.first); return First; }

private int getIndexOfString(String s,Char c) { for (int i = 0; i < s.Length; i++) {

if (s[i] == c) return i; }

return 0; }

private FOLLOW getFollow(Char c) {

FOLLOW Follow = new FOLLOW(); Follow.noter = c;

if (nonterminal[0] == c)

Follow.follow = Follow.follow + '#'; for (int i = 0; i < 20; i++) {

if (production[i].production != null) { if (production[i].production.Contains(c)) {

int index = getIndexOfString(production[i].production,c); if ((index+1)

if (terminator.Contains(production[i].production[index + 1])) Follow.follow = Follow.follow + production[i].production[index + 1].ToString().Replace(\

else if (nonterminal.Contains(production[i].production[index + 1])) {

if (getFirst(production[i].production[index + 1]).first.Contains('@') && production[i].noter!=c) Follow.follow = Follow.follow + getFollow(production[i].noter).follow; ;

Follow.follow = Follow.follow + getFirst(production[i].production[index + 1]).first.Replace(\ } } else {

if (production[i].noter!=c) Follow.follow = Follow.follow +

getFollow(production[i].noter).follow; } } } }

Follow.follow = getSingleString(Follow.follow); return Follow; }

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

if (s==null||s.Length<1) ;

else if (terminator.Contains(s[0])) str = str + s[0];

else if (nonterminal.Contains(s[0])) {

if (getFirst(s[0]).first.Contains('@')) {

str = str + getFirst(s[0]).first.Replace(\getStringFirst(s.Replace(s[0].ToString(), \ } else

str = str + getFirst(s[0]).first; }

return str; }

private String [,]getAnalysis_Sheet(FIRST []First, FOLLOW []Follow){ String [,]sheet=new String[20,20];

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

if (First[i].first.Contains(Terminator[j])) {

for (int m = 0; m < production.Length; m++) {

if (production[m].noter != nonterminal[i]) ;

else if (getStringFirst(production[m].production) == null) ; else

(getStringFirst(production[m].production).Contains(Terminator[j])) {

sheet[i, j] = production[m].noter + \

+

if

+

production[m].production;

} } } if

(First[i].first.Contains('@')&&Follow[i].follow.Contains(Terminator[j])) {

sheet[i, j] = nonterminal[i] + \ } }

return sheet; }

private void addData(String[,] sheet) { try {

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

DataGridViewTextBoxColumn dgc = DataGridViewTextBoxColumn();

dgc.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dgc.HeaderText=Terminator[i]+\ dataGridView2.Columns.Add(dgc); }

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

DataGridViewRow dgr = new DataGridViewRow(); for (int j = 0; j < Terminator.Length+1; j++)

{

if (j == 0) {

DataGridViewTextBoxCell dgt = DataGridViewTextBoxCell();

dgt.Value = nonterminal[i]; dgr.Cells.Add(dgt); } else {

DataGridViewTextBoxCell dgt = DataGridViewTextBoxCell();

dgt.Value = sheet[i,j-1]; dgr.Cells.Add(dgt); } }

new new new

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