计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx

上传人:b****2 文档编号:18486240 上传时间:2023-08-18 格式:DOCX 页数:20 大小:19.49KB
下载 相关 举报
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第1页
第1页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第2页
第2页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第3页
第3页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第4页
第4页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第5页
第5页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第6页
第6页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第7页
第7页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第8页
第8页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第9页
第9页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第10页
第10页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第11页
第11页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第12页
第12页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第13页
第13页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第14页
第14页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第15页
第15页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第16页
第16页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第17页
第17页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第18页
第18页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第19页
第19页 / 共20页
计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx_第20页
第20页 / 共20页
亲,该文档总共20页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx

《计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx》由会员分享,可在线阅读,更多相关《计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx(20页珍藏版)》请在冰点文库上搜索。

计算机编译原理编译程序构造实践第二版 附录三 文法输入输出系统的部分程序代码.docx

计算机编译原理编译程序构造实践第二版附录三文法输入输出系统的部分程序代码

附录三在VisualC++开发平台上开发文法输入输出系统的部分程序代码

本附录给出的是在VisualC++开发平台上所开发应用系统中与用户添加部分相关的的部分可执行程序,请读者注意在程序中何处给出用户添加部分。

建议读者结合实际操作,进行对照,以熟练VisualC++开发平台的应用。

/******Mainfrm.h******/

//MainFrm.h:

interfaceoftheCMainFrameclass

//

/////////////////////////////////////////////////////////////////////////////

#if!

defined(AFX_MAINFRM_H__CA8C9B0D_82A4_4D43_BD70_6B3DC428B2FF__INCLUDED_)

#defineAFX_MAINFRM_H__CA8C9B0D_82A4_4D43_BD70_6B3DC428B2FF__INCLUDED_

#if_MSC_VER>1000

#pragmaonce

#endif//_MSC_VER>1000

classCMainFrame:

publicCFrameWnd

{protected:

//createfromserializationonly

CMainFrame();

DECLARE_DYNCREATE(CMainFrame)

//Attributes

public:

//Operations

public:

//Overrides

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CMainFrame)

virtualBOOLPreCreateWindow(CREATESTRUCT&cs);

//}}AFX_VIRTUAL

//Implementation

public:

virtual~CMainFrame();

#ifdef_DEBUG

virtualvoidAssertValid()const;

virtualvoidDump(CDumpContext&dc)const;

#endif

protected:

//controlbarembeddedmembers

CStatusBarm_wndStatusBar;

CToolBarm_wndToolBar;

//Generatedmessagemapfunctions

protected:

//{{AFX_MSG(CMainFrame)

afx_msgintOnCreate(LPCREATESTRUCTlpCreateStruct);

afx_msgvoidOnGread();/*用户定义,自动生成*/

afx_msgvoidOnGstore();

afx_msgvoidOnAppExit();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}

//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.

#endif//!

defined(AFX_MAINFRM_H__CA8C9B0D_82A4_4D43_BD70_6B3DC428B2FF__INCLUDED_)

/******Maingfrm.cpp******/

//MainFrm.cpp:

implementationoftheCMainFrameclass

#include"stdafx.h"

#include"文法输入输出系统.h"/*用户定义,自动生成*/

#include"MainFrm.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

#include"GREAD.h"/*用户添加*/

GREADDlg1;

#include"DISPG.h"

DISPGDlg2;

CStringStartSymbol;/*用户添加*/

CStringProducts;

CStringVNC;

CStringVTC;

/////////////////////////////////////////////////////////////////////////////

//CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame,CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame,CFrameWnd)

//{{AFX_MSG_MAP(CMainFrame)

ON_WM_CREATE()

ON_COMMAND(ID_GREAD,OnGread)/*用户定义,自动生成*/

ON_COMMAND(ID_GSTORE,OnGstore)

ON_COMMAND(ID_APP_EXIT,OnAppExit)

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

staticUINTindicators[]=

{ID_SEPARATOR,//statuslineindicator

ID_INDICATOR_CAPS,

ID_INDICATOR_NUM,

ID_INDICATOR_SCRL,

};

/////////////////////////////////////////////////////////////////////////////

//CMainFrameconstruction/destruction

CMainFrame:

:

CMainFrame()

{

//TODO:

addmemberinitializationcodehere

}

CMainFrame:

:

~CMainFrame()

{

}

intCMainFrame:

:

OnCreate(LPCREATESTRUCTlpCreateStruct)

{if(CFrameWnd:

:

OnCreate(lpCreateStruct)==-1)

return-1;

if(!

m_wndToolBar.CreateEx(this,TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_TOP

|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC)||

!

m_wndToolBar.LoadToolBar(IDR_MAINFRAME))

{TRACE0("Failedtocreatetoolbar\n");

return-1;//failtocreate

}

if(!

m_wndStatusBar.Create(this)||

!

m_wndStatusBar.SetIndicators(indicators,

sizeof(indicators)/sizeof(UINT)))

{

TRACE0("Failedtocreatestatusbar\n");

return-1;//failtocreate

}

//TODO:

Deletethesethreelinesifyoudon'twantthetoolbarto

//bedockable

m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);

EnableDocking(CBRS_ALIGN_ANY);

DockControlBar(&m_wndToolBar);

return0;

}

BOOLCMainFrame:

:

PreCreateWindow(CREATESTRUCT&cs)

{if(!

CFrameWnd:

:

PreCreateWindow(cs))

returnFALSE;

//TODO:

ModifytheWindowclassorstylesherebymodifying

//theCREATESTRUCTcs

returnTRUE;

}

/////////////////////////////////////////////////////////////////////////////

//CMainFramediagnostics

#ifdef_DEBUG

voidCMainFrame:

:

AssertValid()const

{CFrameWnd:

:

AssertValid();

}

voidCMainFrame:

:

Dump(CDumpContext&dc)const

{CFrameWnd:

:

Dump(dc);

}

#endif//_DEBUG

/////////////////////////////////////////////////////////////////////////////

//CMainFramemessagehandlers

voidCMainFrame:

:

OnGread()/*用户定义,自动生成*/

{//TODO:

Addyourcommandhandlercodehere

Dlg1.DoModal();/*用户添加*/

}

voidCMainFrame:

:

OnGstore()/*用户定义,自动生成*/

{//TODO:

Addyourcommandhandlercodehere

Dlg2.m_SSV=StartSymbol;/*用户添加*/

Dlg2.m_RulesV=Products;

Dlg2.m_VTSV=VTC;

Dlg2.m_VNSV=VNC;

Dlg2.DoModal();

}

voidCMainFrame:

:

OnAppExit()/*用户定义,自动生成*/

{//TODO:

Addyourcommandhandlercodehere

CMainFrame:

:

OnClose();/*用户添加*/

}

/******GREAD.h******/

#if!

defined(AFX_GREAD_H__F0B82C30_67C6_42C1_9CE2_F10546EB47CF__INCLUDED_)

#defineAFX_GREAD_H__F0B82C30_67C6_42C1_9CE2_F10546EB47CF__INCLUDED_

#if_MSC_VER>1000

#pragmaonce

#endif//_MSC_VER>1000

//GREAD.h:

headerfile

//

/////////////////////////////////////////////////////////////////////////////

//GREADdialog

classGREAD:

publicCdialog/*用户定义,自动生成*/

{

//Construction

public:

GREAD(CWnd*pParent=NULL);//standardconstructor

//DialogData

//{{AFX_DATA(GREAD)

enum{IDD=IDD_INPUTG};

CEditm_RuleV;/*用户定义,自动生成*/

CEditm_SV;

//}}AFX_DATA

//Overrides

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(GREAD)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

//Generatedmessagemapfunctions

//{{AFX_MSG(GREAD)

virtualvoidOnOK();/*用户定义,自动生成*/

virtualvoidOnCancel();

afx_msgvoidOnReinput();

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

//{{AFX_INSERT_LOCATION}}

//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.

#endif//!

defined(AFX_GREAD_H__F0B82C30_67C6_42C1_9CE2_F10546EB47CF__INCLUDED_)

/******GREAD.CPP******/

//GREAD.cpp:

implementationfile

//

#include"stdafx.h"

#include"文法输入输出系统.h"/*用户定义,自动生成*/

#include"GREAD.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

externGREADDlg1;/*用户添加的自定义的外部数据对象*/

externCStringStartSymbol;

externCStringProducts;

externCStringVNC;

externCStringVTC;

charInput[30][30];/*用户添加的自定义的数据类型和数据对象*/

typedefstruct

{charLeftSym;

charRightpart[20];

intRightLength;

}RuleT;

RuleTGrammarC[20];

charVT[20];

charVN[20];

intNVN=0,NVT=0;

typedefstruct

{intLeftSymNum;

intRightpartNum[20];

intRightLength;

}RuleType;

RuleTypeGrammar[20];

intRuleN;

charStartSym;

intLineNumofG;

intInputLength;

/////////////////////////////////////////////////////////////////////////////

//GREADdialog

GREAD:

:

GREAD(CWnd*pParent/*=NULL*/)/*用户定义,自动生成*/

:

CDialog(GREAD:

:

IDD,pParent)

{//{{AFX_DATA_INIT(GREAD)

//}}AFX_DATA_INIT

}

voidGREAD:

:

DoDataExchange(CDataExchange*pDX)

{CDialog:

:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(GREAD)

DDX_Control(pDX,IDC_RULEV,m_RuleV);/*用户定义,自动生成*/

DDX_Control(pDX,IDC_SV,m_SV);

//}}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(GREAD,CDialog)

//{{AFX_MSG_MAP(GREAD)

ON_BN_CLICKED(IDC_REINPUT,OnReinput)/*用户定义,自动生成*/

//}}AFX_MSG_MAP

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//GREADmessagehandlers

/*用户自定义的函数*/

voidGetGrammar()/*从过渡文法转换到文法的存储表示*/

{charLeftS,Sym;

intk,j,m;

StartSym=GrammarC[1].LeftSym;

for(k=1;k<=RuleN;k++)

{LeftS=GrammarC[k].LeftSym;

for(j=1;j<=NVN;j++)

if(LeftS==VN[j])

{Grammar[k].LeftSymNum=j+100;

break;

}

for(j=1;j<=GrammarC[k].RightLength;j++)

{Sym=GrammarC[k].Rightpart[j];

for(m=1;m<=NVN;m++)

if(Sym==VN[m])

{Grammar[k].RightpartNum[j]=m+100;

break;

}

if(m<=NVN)continue;

for(m=1;m<=NVT;m++)

if(Sym==VT[m])

{Grammar[k].RightpartNum[j]=m;

break;

}

}

Grammar[k].RightLength=GrammarC[k].RightLength;

}

}

voidGetInput()/*把界面键入的数据存入Input中*/

{intk,len,row=1,colum;charc;

Input[0][0]='\0';

colum=0;

len=Products.GetLength();

for(k=0;k<=len-1;k++)

{c=Products[k];

if(c=='\n'||c=='\012')

{Input[row][colum]='\0';

++row;colum=0;

}elseif(c=='\015')

continue;

elseif(c=='\0')

{Input[row][colum]='\0';

break;

}else/*c!

='\n'&&c!

='\0'*/

Input[row][colum++]=c;

}

LineNumofG=row;

}

voidStoreG()/*把Input中的输入转换为字符型过渡文法*/

{introw,colum,k,j,m;

charsym,U;

StartSym=StartSymbol[0];

GetInput();

RuleN=0;

row=1;NVN=NVT=0;

while(row<=LineNumofG)

{colum=0;

sym=Input[row][colum];

for(k=1;k<=NVN;k++)

if(sym==VN[k])

break;

if(k>NVN)

VN[++NVN]=sym;

GrammarC[++RuleN].LeftSym=sym;

colum=colum+4;

/*规则行中放过符号“:

:

=”*/

j=0;/*规则右部位置*/

while(Input[row][colum]!

='\0')/*规则右部未完)*/

{sym=Input[row][colum++];

if(sym=='|')

{GrammarC[RuleN].Rightpart[j+1]='\0';

GrammarC[RuleN].RightLength=j;

U=GrammarC[RuleN].LeftSym;

RuleN=RuleN+1;

GrammarC[RuleN].LeftSym=U;j=0;

continue;/*继续while循环*/

}else

if(sym=='\n'||sym=='\0')

break;

j=j+1;GrammarC[RuleN].Rightpart[j]=sym;

for(k=1;k<=NVT;k++)/*判sym是否在VT中*/

if(sym==VT[k])/*多字符符号时需用函数strcmp*/

break;

if(k>NVT)/*sym不在VT中*/

VT[++NVT]=sym;/*多字符符号时需用函数strcpy*/

}/*处理一行规则while结束*/

GrammarC[RuleN].RightLength=j;

row=row+1;

}/*处理文法while结束*/

/*从VT中删除出现在VN中的符号,求得VT基数*/

for(m=1;m<=NVT;m++)

{for(k=1;k<=NVN;k++)

if(VT[m]==VN[k])/*是非终结符号*/

{VT[m]='';

break;

}

}

for(m=1;m<=NVT;m++)

if(VT[m]=='')

{for(j=m+1;j<=NVT;j++)

VT[j-1]=VT[j];/*删除VT[m],把其后的元素上移*/

NVT=NVT-1;

if(VT[m]=='')

m=m-1;

continue;

}

GetGrammar();/*转换成存储表示的文法*/

}

voidSetG()/*为输出显示,置好界面全局数据对象*/

{inti,k,j,m;charVNTmp[20],VTTmp[20],RuleTmp[100];

j=0;

for

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2