📄 pl0dlg.cpp
字号:
else
{
str.Format("错误号:%d %s 【 %s 】\r\n",
p[i]->value,ep[p[i]->value],p[i]->text);
m_cOut.AppendText(str.GetBuffer(0));
}
}
}
str.Format("\r\n 发现 %d 个错误!\r\n",ErrorCount);
m_cOut.AppendText(str.GetBuffer(0));
}
void CPL0Dlg::OnMenuitemYufa()
{
// TODO: Add your command handler code here
char buf[30003];
int sz=m_cIn.GetWindowText(buf,30000);
buf[sz]=0;
::strcpy(m_Compiler.GetTable()->SourseBuffer,buf);
m_Compiler.CiFaFengXi();
CifaResult * * cp=m_Compiler.GetTable()->LexicalDuad;
int s=0;
while ((cp[s]->type)>=0)
s++;
char (*ep)[100];
ep=m_Compiler.GetTable()->ErrorMessageTable;
for (int i=0;i<s;i++)
if (cp[i]->type==0)
if (AfxMessageBox("源程序有词法错误,仍要继续吗?"
,MB_YESNO|MB_ICONQUESTION)==IDNO)
return;
else break;
m_Compiler.YuFaFengXi();
//result to : cp,s,ep
m_cOut.SetWindowText("");
CString str;
str.Format("语法分析结果:\r\n\r\n");
m_cOut.AppendText(str.GetBuffer(0));
if (m_Compiler.GetTable()->ErrorNumber==0)
{
str.Format("源程序在语法上正确!\r\n");
m_cOut.AppendText(str.GetBuffer(0));
}
else
{
str.Format("源程序有语法错误!!\r\n");
m_cOut.AppendText(str.GetBuffer(0));
m_cIn.SetSel(cp[m_Compiler.GetTable()->ErrorAddress]->address,
cp[m_Compiler.GetTable()->ErrorAddress]->address
+::strlen(cp[m_Compiler.GetTable()->ErrorAddress]->text));
str.Format("\r\n错误号:%d %s\r\n",
m_Compiler.GetTable()->ErrorNumber,
ep[m_Compiler.GetTable()->ErrorNumber]);
m_cOut.AppendText(str.GetBuffer(0));
}
}
void CPL0Dlg::OnMenuitemYuyi()
{
// TODO: Add your command handler code here
m_cIn.GetWindowText(m_Compiler.GetTable()->SourseBuffer,30000);
m_Compiler.CiFaFengXi();
m_Compiler.YuYiFengXi();
m_cOut.SetWindowText("");
int i=0;CString str;
while (m_Compiler.GetTable()->LexicalDuad[i]->type>=0)
{
if (m_Compiler.GetTable()->LexicalDuad[i]->type==0)
{
str.Format("源程序有词法错误:\r\n\r\n");
m_cOut.AppendText(str.GetBuffer(0));
str.Format("错误号:%d %s\r\n",
m_Compiler.GetTable()->LexicalDuad[i]->value,
m_Compiler.GetTable()->ErrorMessageTable[m_Compiler.GetTable()->LexicalDuad[i]->value]);
m_cOut.AppendText(str.GetBuffer(0));
int se=m_Compiler.GetTable()->LexicalDuad[i]->address;
int sl=::strlen(m_Compiler.GetTable()->LexicalDuad[i]->text);
m_cIn.SetSel(se,se+sl);
return;
}
i++;
}
str.Format("语义分析结果:\r\n\r\n");
m_cOut.AppendText(str.GetBuffer(0));
if (m_Compiler.GetTable()->ErrorNumber!=0)
{
str.Format("错误号:%d %s\r\n\r\n",
m_Compiler.GetTable()->ErrorNumber,
m_Compiler.GetTable()->ErrorMessageTable[m_Compiler.GetTable()->ErrorNumber]);
m_cOut.AppendText(str.GetBuffer(0));
int se=m_Compiler.GetTable()->LexicalDuad[m_Compiler.GetTable()->ErrorAddress]->address;
int sl=::strlen(m_Compiler.GetTable()->LexicalDuad[m_Compiler.GetTable()->ErrorAddress]->text);
m_cIn.SetSel(se,se+sl);
if (AfxMessageBox("源程序有错误,要列出四元式吗?"
,MB_YESNO|MB_ICONQUESTION)==IDNO)
return;
}
if (!m_bSysEnable)
{
str.Format("输出格式:行号,四元式。\r\n\r\n");
m_cOut.AppendText(str.GetBuffer(0));
i=1;
while (m_Compiler.GetTable()->SemanticQuad[i].op!=0)
{
str.Format("%d\t(%s\t,(%d,%d),(%d,%d),(%d,%d))\r\n",i,
m_Compiler.GetTable()->QuadOpcodeTable[m_Compiler.GetTable()->SemanticQuad[i].op],
m_Compiler.GetTable()->SemanticQuad[i].arg1.fl,
m_Compiler.GetTable()->SemanticQuad[i].arg1.flvalue,
m_Compiler.GetTable()->SemanticQuad[i].arg2.fl,
m_Compiler.GetTable()->SemanticQuad[i].arg2.flvalue,
m_Compiler.GetTable()->SemanticQuad[i].result.fl,
m_Compiler.GetTable()->SemanticQuad[i].result.flvalue);
m_cOut.AppendText(str.GetBuffer(0));
i++;
}
}
else
{
str.Format("输出格式:行号,四元式(操作,操作数,操作数,结果)。\r\n\r\n");
m_cOut.AppendText(str.GetBuffer(0));
i=1;
while (m_Compiler.GetTable()->SemanticQuad[i].op!=0)
{
str.Format("%d\t(%s\t,",i,
m_Compiler.GetTable()->QuadOpcodeTable[m_Compiler.GetTable()->SemanticQuad[i].op]);
m_cOut.AppendText(str.GetBuffer(0));
switch (m_Compiler.GetTable()->SemanticQuad[i].arg1.fl)
{
case 0:
str.Format("__,");break;
case 1:
str.Format("%d,",m_Compiler.GetTable()->SemanticQuad[i].arg1.flvalue);break;
case 2:
str.Format("I%d,",m_Compiler.GetTable()->SemanticQuad[i].arg1.flvalue);break;
case 3:
str.Format("T%d,",m_Compiler.GetTable()->SemanticQuad[i].arg1.flvalue);break;
case 4:
str.Format("V%d,",m_Compiler.GetTable()->SemanticQuad[i].arg1.flvalue);break;
case 5:
str.Format("VV%d,",m_Compiler.GetTable()->SemanticQuad[i].arg1.flvalue);break;
default:
str.Format("P%d_%d,",
m_Compiler.GetTable()->SemanticQuad[i].arg1.fl-6,
m_Compiler.GetTable()->SemanticQuad[i].arg1.flvalue);
}
m_cOut.AppendText(str.GetBuffer(0));
switch (m_Compiler.GetTable()->SemanticQuad[i].arg2.fl)
{
case 0:
str.Format("__,");break;
case 1:
str.Format("%d,",m_Compiler.GetTable()->SemanticQuad[i].arg2.flvalue);break;
case 2:
str.Format("I%d,",m_Compiler.GetTable()->SemanticQuad[i].arg2.flvalue);break;
case 3:
str.Format("T%d,",m_Compiler.GetTable()->SemanticQuad[i].arg2.flvalue);break;
case 4:
str.Format("V%d,",m_Compiler.GetTable()->SemanticQuad[i].arg2.flvalue);break;
case 5:
str.Format("VV%d,",m_Compiler.GetTable()->SemanticQuad[i].arg2.flvalue);break;
default:
str.Format("P%d_%d,",
m_Compiler.GetTable()->SemanticQuad[i].arg2.fl-6,
m_Compiler.GetTable()->SemanticQuad[i].arg2.flvalue);
}
m_cOut.AppendText(str.GetBuffer(0));
switch (m_Compiler.GetTable()->SemanticQuad[i].result.fl)
{
case 0:
str.Format("__)\r\n");break;
case 1:
str.Format("%d)\r\n",m_Compiler.GetTable()->SemanticQuad[i].result.flvalue);break;
case 2:
str.Format("I%d)\r\n",m_Compiler.GetTable()->SemanticQuad[i].result.flvalue);break;
case 3:
str.Format("T%d)\r\n",m_Compiler.GetTable()->SemanticQuad[i].result.flvalue);break;
case 4:
str.Format("V%d)\r\n",m_Compiler.GetTable()->SemanticQuad[i].result.flvalue);break;
case 5:
str.Format("VV%d)\r\n",m_Compiler.GetTable()->SemanticQuad[i].result.flvalue);break;
default:
str.Format("P%d_%d)\r\n",
m_Compiler.GetTable()->SemanticQuad[i].result.fl-6,
m_Compiler.GetTable()->SemanticQuad[i].result.flvalue);
}
m_cOut.AppendText(str.GetBuffer(0));
i++;
}
str.Format("\r\n四元式说明:\r\n\r\n");
m_cOut.AppendText(str.GetBuffer(0));
str.Format("空:__\r\n常数:###\r\n指令入口:I###\r\n临时变量:T###\r\n直接访问变量:V###\r\n间接访问变量:VV###\r\n第i外层变量:Pi_###\r\n");
m_cOut.AppendText(str.GetBuffer(0));
str.Format("(###为数字)\r\n");
m_cOut.AppendText(str.GetBuffer(0));
}
}
void CPL0Dlg::OnMenuitemManual()
{
// TODO: Add your command handler code here
AfxMessageBox("没发现帮助文件,您使用的可能是盗版!");
}
void CPL0Dlg::OnCancel()
{
// TODO: Add extra cleanup here
// CDialog::OnCancel();
}
void CPL0Dlg::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
}
void CPL0Dlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
if (m_cIn.GetModify())
{
switch (AfxMessageBox("要保存修改吗?!",MB_YESNOCANCEL|MB_ICONQUESTION))
{
case IDYES:
OnMenuitemSave();
break;
case IDCANCEL:
return;
default:
;
}
}
if (IDNO==AfxMessageBox("真的要退出吗?",MB_YESNO|MB_ICONQUESTION))
{
return;
}
EndDialog(IDCANCEL);
CDialog::OnClose();
}
void CPL0Dlg::OnUpdateInctrl()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
char a[255];
int sz=GetWindowText(a,254);
if (a[sz-1]!='*')
{
::strcat(a," *");
SetWindowText(a);
}
}
void CPL0Dlg::OnButtonCifa()
{
// TODO: Add your control notification handler code here
OnMenuitemCifa();
}
void CPL0Dlg::OnButtonYufa()
{
// TODO: Add your control notification handler code here
OnMenuitemYufa();
}
void CPL0Dlg::OnButtonYuyi()
{
// TODO: Add your control notification handler code here
OnMenuitemYuyi();
}
void CPL0Dlg::OnUpdateMenuitemAll(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if ((m_cIn.GetFocus()==&m_cIn) || (m_cIn.GetFocus()==&m_cOut)) pCmdUI->Enable(TRUE);
else pCmdUI->Enable(FALSE);
}
void CPL0Dlg::OnUpdateMenuitemDel(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_cIn.GetFocus()==&m_cIn) pCmdUI->Enable(TRUE);
else pCmdUI->Enable(FALSE);
}
void CPL0Dlg::OnUpdateMenuitemPaste(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_cIn.GetFocus()==&m_cIn) pCmdUI->Enable(TRUE);
else pCmdUI->Enable(FALSE);
}
void CPL0Dlg::OnUpdateMenuitemCopy(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if ((m_cIn.GetFocus()==&m_cIn) || (m_cIn.GetFocus()==&m_cOut)) pCmdUI->Enable(TRUE);
else pCmdUI->Enable(FALSE);
}
void CPL0Dlg::OnUpdateMenuitemCut(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_cIn.GetFocus()==&m_cIn) pCmdUI->Enable(TRUE);
else pCmdUI->Enable(FALSE);
}
void CPL0Dlg::OnUpdateMenuitemUndo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_cIn.GetFocus()==&m_cIn) pCmdUI->Enable(TRUE);
else pCmdUI->Enable(FALSE);
}
void CPL0Dlg::OnMenuitemSys()
{
// TODO: Add your command handler code here
m_bSysEnable=!m_bSysEnable;
}
void CPL0Dlg::OnUpdateMenuitemSys(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_bSysEnable);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -