• 大小: 35KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-07-22
  • 语言: 其他
  • 标签:

资源简介

我的编译原理课程设计,请大家多多指教!!!

资源截图

代码片段和文件信息

// GrammerAnalysis.cpp: implementation of the GrammerAnalysis class.
//
//////////////////////////////////////////////////////////////////////

#include “stdafx.h“
#include “PL0.h“
#include “GrammerAnalysis.h“


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////


GrammerAnalysis::GrammerAnalysis(CString set_of_token[])
{
int itr = 0;
while(set_of_token[itr] != “200“ && set_of_token[itr] != ““)
{
// ::AfxMessageBox(set_of_token[itr++]);
this->set_of_token[itr] = set_of_token[itr];
itr++;
}

//测试代码
// itr = 0;
// while(this->set_of_token[itr] != ““ && strcmp(set_of_token[itr]“200“) != 0)
// {
// ::AfxMessageBox(this->set_of_token[itr++]);
// }

this->StartAnalysis();

}

GrammerAnalysis::~GrammerAnalysis()
{

}

token_type GrammerAnalysis::GetToken()
{
CString str_tmp_token = set_of_token[token_itr++];
int int_tmp_token = atoi(str_tmp_token);
return current_token = (token_type)int_tmp_token; //当前token
}

void GrammerAnalysis::error(int line_num CString str_msg)
{

}

void GrammerAnalysis::StartAnalysis()
{
this->GetToken();
this->loop();
}

void GrammerAnalysis::loop()
{
if(current_token != ENDFILE)
{
// ::AfxMessageBox(“己到文件尾“);
if(current_token == KEYID_CONST) //如果是CONST常量变量则必须初始化赋值
{
const_match();
}
else if(current_token == KEYID_VAR) //VAR变量不必初始化
{
var_match();
}
else if(current_token == KEYID_PROCEDURE)
{
this->procedure_match();
}

Statement(); //继续语句匹配
}
return;

}

void GrammerAnalysis::MATCH(token_type token)
{
if(this->current_token == token)
{
if(this->current_token == SEMI)
{
cur_line++;
}
this->GetToken();
}
else
{
this->error(cur_line“不匹配的TOKEN“);
}
}

void GrammerAnalysis::const_match()
{
this->GetToken();
if(this->current_token == ID)
{
MATCH(EQ);
MATCH(NUM);
MATCH(SEMI);
::AfxMessageBox(“CONST 匹配成功“);
}
else
{
::AfxMessageBox(“CONST 匹配失败“);
}
}

void GrammerAnalysis::var_match()
{
this->GetToken();
MATCH(ID);
while(this->current_token == COMMA)
{
::AfxMessageBox(“var“);
this->GetToken();
MATCH(ID);
}
MATCH(SEMI);
}

void GrammerAnalysis::procedure_match()
{
this->GetToken();
MATCH(ID);
MATCH(SEMI);
this->GetToken();
this->loop();
}

void GrammerAnalysis::Statement()
{
while(this->current_token == ENDFILE)
{
this->loop();
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      24576  2007-11-30 10:56  语法分析结构.doc

     文件        470  2007-12-04 11:25  PL0\cffxjg.txt

     文件       2710  2007-12-04 11:25  PL0\GrammerAnalysis.cpp

     文件        983  2007-12-04 10:56  PL0\GrammerAnalysis.h

     文件      20348  2007-11-29 11:08  PL0\PL0.APS

     文件        932  2007-11-30 11:10  PL0\PL0.clw

     文件       2021  2007-11-10 20:21  PL0\PL0.cpp

     文件       4370  2007-11-30 11:10  PL0\PL0.dsp

     文件        531  2007-11-10 20:21  PL0\PL0.dsw

     文件       1291  2007-11-10 20:21  PL0\PL0.h

     文件      66560  2007-12-04 11:25  PL0\PL0.ncb

     文件      53760  2007-12-04 11:25  PL0\PL0.opt

     文件      19308  2007-12-04 11:25  PL0\PL0.plg

     文件       5088  2007-11-29 10:26  PL0\PL0.rc

     文件      11187  2007-12-04 10:45  PL0\PL0Dlg.cpp

     文件       2747  2007-12-04 10:47  PL0\PL0Dlg.h

     文件       3525  2007-11-10 20:21  PL0\ReadMe.txt

     文件       1078  2007-11-10 20:21  PL0\res\PL0.ico

     文件        395  2007-11-10 20:21  PL0\res\PL0.rc2

     文件        773  2007-11-29 10:26  PL0\resource.h

     文件        205  2007-11-10 20:21  PL0\StdAfx.cpp

     文件       1054  2007-11-10 20:21  PL0\StdAfx.h

     文件        338  2007-12-04 11:16  PL0\test.pl0

     文件        838  2007-11-29 10:25  PL0\XEdit.cpp

     文件       1162  2007-11-29 10:22  PL0\XEdit.h

     目录          0  2007-12-04 11:34  PL0\res

     目录          0  2007-12-04 11:35  PL0

----------- ---------  ---------- -----  ----

               226250                    27



............此处省略0个文件信息

评论

共有 条评论