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

实验二 语法分析(算符优先)(2)

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

}

//查找 P->a... 和 P->Qa...

void CGrammarAnalysisDlg::SearchPForFirtVT(Find& f) {

CString* str; int nFrist = 0; int nLen = 0; { }

nFrist = nLen;

nLen = str->Find('|',nFrist+1);

if(IsNT(strProduce,0) && IsT(strProduce,1)) { }

if(IsT(strProduce,0)) { }

if(strProduce.GetAt(0) == f.m_strTerm) { }

if(!f.m_bIsVT) { }

f.m_bIsVT = TRUE; //CreateFristVT(f); m_stack.PushStack(f);

if(strProduce.GetAt(1) == f.m_strTerm) { }

if(!f.m_bIsVT) { }

f.m_bIsVT = TRUE; //CreateFristVT(f); m_stack.PushStack(f);

m_mapProdu.Lookup(f.m_strNTerm,(void*&)str); }

}

m_F[k].m_strTerm = m_strTElem[j]; m_F[k].m_bIsVT = FALSE; k++;

}

//判断产生式第nLocat位置的字符是否是非终结符 BOOL CGrammarAnalysisDlg::IsNT(CString strProduc,int nLocat) { }

BOOL CGrammarAnalysisDlg::IsT(CString strProduc, int nLocat) { }

//遍历所有的产生式 P->Q

void CGrammarAnalysisDlg::SearchQForFristVT(void) {

POSITION pos = m_mapProdu.GetStartPosition(); while(pos) {

m_mapProdu.GetNextAssoc(pos,strNT,(void*&)str); int nFrist = 0; int nLen = 0;

while(nLen+1 < str->GetLength()) {

Find Q; CString strNT; CString* str;

while(m_stack.m_nTop != 0) {

m_stack.PopStack(Q); for(int i=0;i

if(strProduc.GetAt(nLocat) == '#')

return 1; return 0;

if(strProduc.GetAt(nLocat) == m_strTElem[i])

return 1;

return 0;

for(int i=0;i

if(strProduc.GetAt(nLocat) == m_strNTElem[i])

return 1;

while(nLen+1 < str->GetLength())// P->a... P和 P->Qa... //判断产生式第nLocat位置的字符是否是终结符

CString strProduce = str->Mid(nFrist+1,nLen-nFrist-1); {

}

// //P->...aQ或P->...a

void CGrammarAnalysisDlg::SearchPForLastVT(Find& f) {

CString* str; int nFrist = 0; int nLen = 0; {

nFrist = nLen;

nLen = str->Find('|',nFrist+1); int nLocat = strProduce.GetLength(); if(nLocat-2>0)

m_mapProdu.Lookup(f.m_strNTerm,(void*&)str); }

}

}

}

}

}

nFrist = nLen;

nLen = str->Find('|',nFrist+1); if(IsNT(strProduce,0)) {

{

//Q.m_bIsVT = TRUE; {

{ }

}

{

break;

}

// //P->....Q

void CGrammarAnalysisDlg::SearchQForLastVT(void) {

POSITION pos = m_mapProdu.GetStartPosition(); while(pos) {

m_mapProdu.GetNextAssoc(pos,strNT,(void*&)str); int nFrist = 0; int nLen = 0;

while(nLen+1 < str->GetLength())

Find Q; CString strNT; CString* str;

while(m_stack.m_nTop != 0) {

m_stack.PopStack(Q); }

for(int i=0;i

{ }

if(IsT(strProduce,nLocat-1)) { }

{ }

if(!f.m_bIsVT) { }

f.m_bIsVT = TRUE; m_stack.PushStack(f);

if(IsNT(strProduce,nLocat-1) && IsT(strProduce,nLocat-2)) }

if(strProduce.GetAt(nLocat-2) == f.m_strTerm) { }

if(!f.m_bIsVT) { }

f.m_bIsVT = TRUE; m_stack.PushStack(f);

CString strProduce = str->Mid(nFrist+1,nLen-nFrist-1); {

if(strProduce.GetAt(0) == Q.m_strNTerm)

if(m_F[i].m_strNTerm == strNT &&

m_F[i].m_strTerm == Q.m_strTerm)

if(!m_F[i].m_bIsVT)

m_F[i].m_bIsVT = TRUE; if(strProduce.GetAt(nLocat-1) == f.m_strTerm)

m_stack.PushStack(m_F[i]);

while(nLen+1 < str->GetLength())// P->a... P和 P->Qa...

CString strProduce = str->Mid(nFrist+1,nLen-nFrist-1);

}

void CGrammarAnalysisDlg::OnBnClickedBtnAnsysic() { S);

CRect rc;

m_lst.GetClientRect(rc);

int nWidth = rc.Width()/(T_LEN+2); // TODO: 在此添加控件通知处理程序代码 //初始化列表控件

//m_lbResult.AddString(_T(\ }

}

}

}

}

}

{

nFrist = nLen;

nLen = str->Find('|',nFrist+1);

int i = 0;

m_lst.InsertColumn(i,_T(\for(i=1;i

m_lst.InsertColumn(i,_T(\for(i=0;i

//Find f(_T(\

SearchPForFirtVT(m_F[i]); m_lst.InsertItem(i,m_strTElem[i]);

m_lst.InsertColumn(i,m_strTElem[i-1],LVCFMT_CENTER,nWidth);

CString strProduce = str->Mid(nFrist+1,nLen-nFrist-1); { int nLocat = strProduce.GetLength(); if(IsNT(strProduce,nLocat-1)) {

{

//Q.m_bIsVT = TRUE; {

{ }

}

{

break;

//遍历产生式构造算符优先表 CString* str;

POSITION pos =m_mapProdu.GetStartPosition(); CString strNT; int nColumn; int nItem; while(pos) {

int nFrist = 0; int nLen = 0;

while(nLen+1 < str->GetLength()) {

nFrist = nLen;

//LastVT InitFind();

//Find f(_T(\for(int i=0;i

SearchPForLastVT(m_F[i]); SearchQForLastVT(); CreateLastVT(m_F);

for(int i=0;i

if(strProduce.GetAt(nLocat-1) == Q.m_strNTerm)

if(m_F[i].m_strNTerm == m_lst.InsertItem(i,_T(\strNT &&

m_F[i].m_strTerm == Q.m_strTerm)

if(!m_F[i].m_bIsVT) InitFind();

m_F[i].m_bIsVT = TRUE; for(int i=0;i

SearchQForFristVT(); CreateFristVT(m_F);

m_stack.PushStack(m_F[i]);

m_lst.SetExtendedStyle(LVS_EX_AUTOSIZECOLUMNS|LVS_EX_GRIDLINE m_mapProdu.GetNextAssoc(pos,strNT,(void*&)str);

nLen = str->Find('|',nFrist+1); int nLocat = strProduce.GetLength(); for(int i=0;i

{ }

if(i<=nLocat-2 { } { } {

} int int

&&

FindTLocat(m_strLastVT[nNTLocat].GetAt(j));

}

}

}

m_nPriSheet[nItem][nColumn] = 1;

nItem = FindTLocat(strProduce.GetAt(i)); nColumn = FindTLocat(strProduce.GetAt(i+1)); } m_nPriSheet[nItem][nColumn] = 0;

m_lst.SetItemText(nItem,nColumn+1,_T(\ }

//处理‘#',,行 wchar_t ch = '('; for(int i=0;i

IsT(strProduce,i) nItem = T_LEN; &&

CString strProduce = str->Mid(nFrist+1,nLen-nFrist-1);

m_lst.SetItemText(nItem,nColumn+1,_T(\

if(IsT(strProduce,i) && IsT(strProduce,i+1))

IsT(strProduce,i+2) && IsNT(strProduce,i+1))

nItem = FindTLocat(strProduce.GetAt(i)); {

nColumn = FindTLocat(strProduce.GetAt(i+2)); switch(m_nPriSheet[FindTLocat(ch)][i]) m_nPriSheet[nItem][nColumn] = 0;

nNTLocat

nVTLen

nColumn

{ }

break; break;

= m_nPriSheet[nItem][i] = -1;

m_lst.SetItemText(nItem,i+1,_T(\= break;

m_nPriSheet[nItem][i] = 1;

m_lst.SetItemText(nItem,i+1,_T(\= break;

m_lst.SetItemText(nItem,nColumn+1,_T(\ case 0:

case INFI:

if(IsT(strProduce,i) && IsNT(strProduce,i+1))

nItem = FindTLocat(strProduce.GetAt(i)); case -1:

FindNTLocat(strProduce.GetAt(i+1)); m_strFristVT[nNTLocat].GetLength();

for(int j=0;j

case 1:

FindTLocat(m_strFristVT[nNTLocat].GetAt(j));

m_nPriSheet[nItem][nColumn] = -1; }

//处理‘#’,,列 nColumn = T_LEN; ch = ')';

for(int i=0;i

switch(m_nPriSheet[i][FindTLocat(ch)])

m_lst.SetItemText(nItem,nColumn+1,_T(\

if(IsNT(strProduce,i) && IsT(strProduce,i+1)) {

nColumn = FindTLocat(strProduce.GetAt(i+1)); { int nNTLocat = FindNTLocat(strProduce.GetAt(i)); case 0: int nVTLen = m_strLastVT[nNTLocat].GetLength(); break; for(int j=0;j

nItem

case INFI:

break; case -1: =

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