编译原理课程设计报告.doc_第1页
编译原理课程设计报告.doc_第2页
编译原理课程设计报告.doc_第3页
编译原理课程设计报告.doc_第4页
编译原理课程设计报告.doc_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

青岛农业大学信息科学与工程学院编 译 原 理 课 程 设 计 报 告 设 计 题 目 递归下降分析器 学生专业班级 计本05.4 学生姓名(学号) 赵传文(08050323) 指 导 教 师 于仁施 完 成 时 间 2008-9-19 实 习(设计)地点 信息楼139机房 2008 年 9月 19日一、 课程设计目的和任务 设计一个递归下降分析器,此分析器能够实现文法的输入、导入、清除、保存并能够求出文法的FIRST集、FOLLOW集,构造LL1预测分析表。程序的用户交互界面友好。二、分析与设计1. 设计任务分析要完成一个递归下降分析器,首先要清楚递归下降分析器的构造原理,要知道FIRST集、FOLLOW集的求法及LL(1)预测分析表的构造方法。根据我对编译原。理知识的学习,这点还是够的。所谓这些,就是编程的思想,接下来就是编程的技术和技巧,尽可能的使用户交互界面友好,会使用户使用起来更舒服些。构造一个比较简单的VC应用程序还是比较容易的。2. 设计方案论证根据构造递归下降分析器的原理,在程序中只需实现输入、导入、清除、保存文法以及显示出文法的分析结果来便可达到程序设计的目的,因此构造一个有交互界面的递归下降分析器是可行的。3. 详细设计(1)首先分析程序要实现的功能,要构造一个递归下降分析器就要实现文法的输入、编辑、清除、保存以及语法的分析功能,在本次设计中实现的是求出FIRST集、FOLLOW积和LL(1)预测分析表。(2)根据分析构造程序界面,要使界面看起来直观、易于使用。(3)根据要实现的功能,在基于交互界面上的各个功能模块进行编程,最终完成整个程序。4. 源代码清单(部分程序源代码)#include stdafx.h#include LL1ForWin.h#include LL1ForWinDlg.h#include TableDlg.h#include stringusing namespace std;#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE = _FILE_;#endif/ CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialogpublic:CAboutDlg();/ Dialog Data/AFX_DATA(CAboutDlg)enum IDD = IDD_ABOUTBOX ;/AFX_DATA/ ClassWizard generated virtual function overrides/AFX_VIRTUAL(CAboutDlg)protected:virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV support/AFX_VIRTUAL/ Implementationprotected:/AFX_MSG(CAboutDlg)/AFX_MSGDECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialog(CAboutDlg:IDD)/AFX_DATA_INIT(CAboutDlg)/AFX_DATA_INITvoid CAboutDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CAboutDlg)/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CAboutDlg, CDialog)/AFX_MSG_MAP(CAboutDlg)/ No message handlers/AFX_MSG_MAPEND_MESSAGE_MAP()/ CLL1ForWinDlg dialogCLL1ForWinDlg:CLL1ForWinDlg(CWnd* pParent /*=NULL*/): CDialog(CLL1ForWinDlg:IDD, pParent)/AFX_DATA_INIT(CLL1ForWinDlg)/AFX_DATA_INIT/ Note that LoadIcon does not require a subsequent DestroyIcon in Win32m_hIcon = AfxGetApp()-LoadIcon(IDR_MAINFRAME);void CLL1ForWinDlg:DoDataExchange(CDataExchange* pDX)CDialog:DoDataExchange(pDX);/AFX_DATA_MAP(CLL1ForWinDlg)DDX_Control(pDX, IDC_VTLIST, m_vtlist);DDX_Control(pDX, IDC_VTEDIT, m_vtedit);DDX_Control(pDX, IDC_VNLIST, m_vnlist);DDX_Control(pDX, IDC_STARTEDIT, m_startedit);DDX_Control(pDX, IDC_PLIST, m_plist);DDX_Control(pDX, IDC_PEDIT, m_pedit);DDX_Control(pDX, IDC_VNEDIT, m_vnedit);/AFX_DATA_MAPBEGIN_MESSAGE_MAP(CLL1ForWinDlg, CDialog)/AFX_MSG_MAP(CLL1ForWinDlg)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_VNADD, OnVnadd)ON_BN_CLICKED(IDC_CLEAR, OnClear)ON_BN_CLICKED(IDC_GTABLE, OnGtable)ON_BN_CLICKED(IDC_IMPORT, OnImport)ON_BN_CLICKED(IDC_PADD, OnPadd)ON_BN_CLICKED(IDC_PDEL, OnPdel)ON_BN_CLICKED(IDC_SAVE, OnSave)ON_BN_CLICKED(IDC_VNDEL, OnVndel)ON_BN_CLICKED(IDC_VTADD, OnVtadd)ON_BN_CLICKED(IDC_VTDEL, OnVtdel)/AFX_MSG_MAPEND_MESSAGE_MAP()/ CLL1ForWinDlg message handlersBOOL CLL1ForWinDlg:OnInitDialog()CDialog:OnInitDialog();/ Add About. menu item to system menu./ IDM_ABOUTBOX must be in the system command range.ASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX AppendMenu(MF_SEPARATOR);pSysMenu-AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ Set the icon for this dialog. The framework does this automatically/ when the applications main window is not a dialogSetIcon(m_hIcon, TRUE);/ Set big iconSetIcon(m_hIcon, FALSE);/ Set small iconreturn TRUE; / return TRUE unless you set the focus to a controlvoid CLL1ForWinDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialog:OnSysCommand(nID, lParam);/ If you add a minimize button to your dialog, you will need the code below/ to draw the icon. For MFC applications using the document/view model,/ this is automatically done for you by the framework.void CLL1ForWinDlg:OnPaint() if (IsIconic()CPaintDC dc(this); / device context for paintingSendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);/ Center icon in client rectangleint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_CYICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;/ Draw the icondc.DrawIcon(x, y, m_hIcon);elseCDialog:OnPaint();HCURSOR CLL1ForWinDlg:OnQueryDragIcon()return (HCURSOR) m_hIcon;void CLL1ForWinDlg:OnOK() / TODO: Add extra validation here/CDialog:OnOK();void CLL1ForWinDlg:OnCancel() / TODO: Add extra cleanup hereCDialog:OnCancel();void CLL1ForWinDlg:OnVnadd() / TODO: Add your control notification handler code hereCString string;m_vnedit.GetWindowText(string);if(string.GetLength()!=1)MessageBox(您输入的非终结符有误,请检查!,错误, MB_OK | MB_ICONSTOP);elseif(m_vnlist.FindStringExact(-1, string) = LB_ERR) & (string!=)m_vnlist.AddString(string);m_vnedit.SetFocus();m_vnedit.SetSel(0, -1);void CLL1ForWinDlg:OnClear() / TODO: Add your control notification handler code herem_vtlist.ResetContent();m_vnlist.ResetContent();m_plist.ResetContent();m_vtedit.SetWindowText();m_vnedit.SetWindowText();m_pedit.SetWindowText();m_startedit.SetWindowText();void CLL1ForWinDlg:OnGtable() / TODO: Add your control notification handler code hereCTableDlg dlg;dlg.SetControlInfo(IDC_EXPLORER1, RESIZE_BOTH);dlg.SetControlInfo(IDOK, ANCHORE_BOTTOM | ANCHORE_RIGHT);dlg.SetControlInfo(IDC_EXPORT, ANCHORE_BOTTOM | ANCHORE_RIGHT);dlg.SetControlInfo(IDC_ANALYZE, ANCHORE_BOTTOM | ANCHORE_RIGHT);string temp = ;CString t;for(int i = 0; i m_vtlist.GetCount(); i+)m_vtlist.GetText(i,t);/temp.push_back(t.GetAt(0);temp += t.GetAt(0);dlg.g.SetVt(temp);temp = ;for(i = 0; i m_vnlist.GetCount(); i+)m_vnlist.GetText(i,t);/temp.push_back(t.GetAt(0);temp += t.GetAt(0);dlg.g.SetVn(temp);m_startedit.GetWindowText(t);if (t = )MessageBox(输入的文法有误,请检查!, 错误,MB_OK | MB_ICONSTOP);return;dlg.g.SetStart(t.GetAt(0);temp = ;for(i = 0; i m_plist.GetCount(); i+)temp = ;m_plist.GetText(i,t);for(int j = 0; j ) = -1)MessageBox(您输入的生成式不合法,请检查!,错误, MB_OK | MB_ICONSTOP);elseif(m_plist.FindStringExact(-1, string) = LB_ERR)&(string!=)m_plist.AddString(string);m_pedit.SetFocus();m_pedit.SetSel(0, -1);void CLL1ForWinDlg:OnPdel() / TODO: Add your control notification handler code hereint iPos;if (iPos = m_plist.GetCurSel() != LB_ERR) m_plist.DeleteString(iPos);m_pedit.SetFocus();m_pedit.SetSel(0, -1);void CLL1ForWinDlg:OnSave() / TODO: Add your control notification handler code herechar szFilters= 文法文件 (*.txt)|*.txt|All Files (*.*)|*.*|;CFileDialog fdlg (FALSE, txt, *.txt, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilters, this);if(fdlg.DoModal()=IDOK)CString pathName = fdlg.GetPathName();CStdioFile OutFile;OutFile.Open(pathName,CFile:modeCreate | CFile:modeWrite);CString t;OutFile.WriteString(Terminatorn);for(int i = 0; i m_vtlist.GetCount(); i+)m_vtlist.GetText(i,t);t += n;OutFile.WriteString(t);OutFile.WriteString(nNonTerminatorn);for(i = 0; i m_vnlist.GetCount(); i+)m_vnlist.GetText(i,t);t += n;OutFile.WriteString(t);OutFile.WriteString(nStartern);m_startedit.GetWindowText(t);t += nnPreceptn;OutFile.WriteString(t);for(i = 0; i m_plist.GetCount(); i+)m_plist.GetText(i,t);t += n;OutFile.WriteString(t);OutFile.Close();void CLL1ForWinDlg:OnVndel() / TODO: Add your control notification handler code hereint iPos;if (iPos = m_vnlist.GetCurSel() != LB_ERR) m_vnlist.DeleteString(iPos);m_vnedit.SetFocus();m_vnedit.SetSel(0, -1);void CLL1ForWinDlg:OnVtadd() / TODO: Add your control notification handler code hereCString string;m_vtedit.GetWindowText(string);if(string.GetLength()!=1)Messa

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论