编译原理课程设计报告
课题名称: 词法分析器
小组成员:
陈锋: 姚珂:
王自然: 王力:
丁昭岩: 周德娇: 李文莉: 庄黎:
2008221105110010
2008221104210527
CString wordArray[N];
public:
CEditData(CString fileText);
virtual ^CEditData();
BOOL readText ();
BOOL judgeProperty ();
};
文件CEditDate. cpp代码如下:
文件util, c代码如下:
// EditData. cpp: implementation of the CEditData class.
//
//////////////////////////////////////////////////////////////////////
ttinclude ^stdafx. h〃
ttinclude zzEditProject. h〃
ttinclude "EditData. h〃
ttinclude zzWordStruct. h〃
using namespace std;
ttifdef _DEBUG
Sundef THIS_FILE
static char THIS_FILE[]= FILE ;
ttdefine new DEBUG_NEW
Sendif
////////////////////////〃〃〃〃〃〃〃〃〃/〃〃〃〃〃〃〃〃〃〃〃〃〃/
// Construction/Destruction
////////////////////////〃〃〃〃〃〃〃〃〃/〃〃〃〃〃〃〃〃〃〃〃〃〃/
CEditData::CEditData(CString fileText)
{
this->fileText 二 fileText;
}
CEditData::^CEditData()
(
}
bool isDigit(char ch)
if (ch>- 0, &&ch〈='9')
}
else
return false;
}
bool isLetter (char ch)
(
if (ch>二'a &&ch<=,z \ \ ch>二'A' &&ch<- 71)
(
return true;
}
else
return false;
}
int n;
BOOL CEditData::readText ()
{
char ch;
n=0;
for (int i=0; i<fileText. GetLength() ; i++)
(
ch = fileText. GetAt(i);
if (ch二二,,| | ch=13 | | ch==10 | | ch=,\t')
{
continue;
}
else if (isDigit(ch))
{
wordArray[n]=ch;
ch=fileText. GetAt(i+1);
while (isDigit (ch) || ch二二,.,)
wordArray[n]+=ch;
i++; 二力夕二•
ch=fileText. GetAt (i+1);
}
n++;
}
else if (isLetter (ch) | | ch二二'#,| | ch==,J ) (
wordArray[n]=ch;
ch=fileText. GetAt(i+1);
while(isLetter(ch)||isDigit(ch))
(
wordArray[n]+=ch;
i++;
ch=fileText. GetAt (i+1);
}
n++;
}
else if (ch二二'%')
(
wordArray[n]=ch;
ch =fileText. GetAt(i+1);
if (ch =='二')
{
ch=fileText. GetAt(++i);
wordArray[n]+=ch;
}
else
while(fileText. GetAt (i+1) !二','&& fileText. GetAt (i+1) !='\〃'
fileText. GetAt (i+1) !二'%')
{ ch=fileText. GetAt (++i); wordArray[n]+=ch;
}
}
n++;
}
else if (ch=二'+' && fileText. GetAt (i+1) 二二'二’ | | ch二二'+'
file
编译原理课程设计语言编译器 来自淘豆网m.daumloan.com转载请标明出处.