91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 791.86 KB
    文件類型: .rar
    金幣: 1
    下載: 0 次
    發布日期: 2024-09-13
  • 語言: 其他
  • 標簽: sample??c++??

資源簡介

a) 啟動程序后,先輸出作者姓名、班級、學號(可用漢語、英語或拼音);
b) 請求輸入測試程序名,鍵入程序名后自動開始詞法分析并輸出結果;
c) 輸出結果為單詞的二元式序列(樣式見樣板輸出1和2);
d) 要求能發現下列詞法錯誤和指出錯誤性質和位置:
非法字符,即不是SAMPLE字符集的符號;
字符常數缺右邊的單引號(字符常數要求左、右邊用單引號界定,不能跨行);
注釋部分缺右邊的界符*/(注釋要求左右邊分別用/*和*/界定,不能跨行)。

資源截圖

代碼片段和文件信息

#include?
#include???
#include?
#include?
#include?
#include?

using?namespace?std;



int?error[1024]; //記錄出錯行
int?i?=?0;?//出錯行數組下標
//---------------------------------------------------------------------------------------------------------------------

struct?Node?//表節點
{
int?number;
char?*str;
Node?*next;
static?int?count;
};
int?Node::count?=?0;

Node*?head?=?NULL;
Node*?tail?=?NULL;

void?insert?(char*?var)?//插入表
{
int?n?=?strlen(var);
Node::count++;
Node*?s?=?new?Node;
s->number?=?Node::count;
s->str?=?new?char[n];
strcpy_s(s->str?n+1?var);
if?(!head)
{
head?=?s;
tail?=?s;
head->next?=?NULL;
tail->next?=?NULL;
}
else
{
tail->next?=?s;
tail?=?s;
tail->next?=?NULL;
}
}

int?search?(char?*var)
{
Node*?p?=?head;
while?(p)
{
if?(!_stricmp(p->str?var))?break;
else?p?=?p->next;
}
if?(p)?return?p->number;
return?0;
}
//---------------------------------------------------------------------------------------------------------------------
char?getWord?(ifstream&?infile)?//從infile中讀取一個字符
{
char?word;
infile.get(word);
return?word;
}

char?ignoreSpace?(ifstream&?infile)?//從infile中讀取空格后的第一個字符
{
char?word;
infile.get(word);
while?(word?==?‘?‘)?infile.get(word);
return?word;
}

int?Reserve?(char*?str)?//判斷是否是保留字
{
char*?reserve[35]?=?{
“and“?“array“?“begin“?“bool“?“call“
“case“?“char“?“constant“?“dim“?“do“
“else“?“end“?“false“?“for“?“if“
“input“?“integer“?“not“?“of“?“or“
“output“?“procedure“?“program“?“read“?“real“
“repeat“?“set““stop“?“then“?“to“
“true“?“until“?“var“?“while“?“write“?};
for?(int?i?=?0;?i? {
if?(!(_stricmp(reserve[i]?str)))?return?i?+?1;
}
return?0;
}

int?isChar?(char?ch)
{??
if?((ch?>=?‘a‘)?&&?(ch?<=?‘z‘)?||?(ch?>=?‘A‘)?&&?(ch?<=?‘Z‘))?return?1;
return???0;??
}??

int?isDigit?(char?ch)
{??
if?((ch?>=?‘0‘)?&&?(ch?<=?‘9‘))?return?1;
return?0;??
}??
???
int?isOther?(char?ch)
{??
if?(isChar(ch))?return?0;
if?(isDigit(ch))?return?0;
return???1;
}???

void?charAdd?(char*?str?char?ch)
{
int?length?=?strlen(str);
str[length]?=?ch;
str[length?+?1]?=?‘\0‘;
}

char?Retract(ifstream&?infile)??
{
infile.seekg(-1?ios::cur);?//從當前文件指針讀寫位置向回退1個字節?
return?‘\0‘;
}??

void?analyzer?(ifstream&?infile)
{
int?line?=?1; //記錄行標
int?n?=?1;?//格式控制
while?(!infile.eof())
{
char?buffer[1024]?=?““;?//緩存讀入的字符
char?ch?=?ignoreSpace?(infile);
if?(isChar?(ch)?||?ch?==?‘_‘)
{
while?(isChar(ch)?||??isDigit(ch)?||?ch?==?‘_‘)
{
charAdd?(buffer?ch);
ch?=?getWord?(infile);
}
ch?=?Retract(infile);
if?(Reserve(buffer))?//保留字
{
cout?< if?(?n?%?5?==?0)?cout?< ++n;
}
else//標識符
{
if?(!search?(buffer))
{
insert(buffer);
}
co

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????7039??2008-10-21?14:53??Compiler\Compiler\Analyzer.cpp

?????文件???????3646??2008-10-20?19:10??Compiler\Compiler\Compiler.vcproj

?????文件???????1411??2008-11-02?22:29??Compiler\Compiler\Compiler.vcproj.YUE-T60.Administrator.user

?????文件??????72013??2008-11-02?22:28??Compiler\Compiler\Debug\Analyzer.obj

?????文件???????5332??2008-11-02?22:28??Compiler\Compiler\Debug\BuildLog.htm

?????文件????????621??2008-11-02?22:28??Compiler\Compiler\Debug\Compiler.exe.intermediate.manifest

?????文件?????????67??2008-11-02?22:28??Compiler\Compiler\Debug\mt.dep

?????文件?????232448??2008-11-02?22:28??Compiler\Compiler\Debug\vc90.idb

?????文件?????233472??2008-10-21?19:45??Compiler\Compiler\Debug\vc90.pdb

?????文件????????301??2008-10-20?19:14??Compiler\Compiler\q.txt

?????文件?????568011??2008-10-21?14:53??Compiler\Compiler\Release\Analyzer.obj

?????文件???????6010??2008-10-21?14:53??Compiler\Compiler\Release\BuildLog.htm

?????文件????????616??2008-10-21?14:53??Compiler\Compiler\Release\Compiler.exe.intermediate.manifest

?????文件?????????67??2008-10-21?14:53??Compiler\Compiler\Release\mt.dep

?????文件?????142336??2008-10-21?14:53??Compiler\Compiler\Release\vc90.idb

?????文件?????208896??2008-10-21?14:53??Compiler\Compiler\Release\vc90.pdb

?????文件????????129??2008-10-21?14:51??Compiler\Compiler\w.txt

?????文件????1928192??2008-11-02?22:29??Compiler\Compiler.ncb

?????文件????????890??2008-10-20?17:24??Compiler\Compiler.sln

????..A..H.??????8704??2008-11-02?22:29??Compiler\Compiler.suo

?????文件??????46592??2008-11-02?22:28??Compiler\Debug\Compiler.exe

?????文件?????440504??2008-11-02?22:28??Compiler\Debug\Compiler.ilk

?????文件?????568320??2008-11-02?22:28??Compiler\Debug\Compiler.pdb

?????文件????????129??2008-10-21?14:51??Compiler\Debug\w.txt

?????文件??????14336??2008-10-21?14:53??Compiler\Release\Compiler.exe

?????文件?????379904??2008-10-21?14:53??Compiler\Release\Compiler.pdb

?????文件????????129??2008-10-21?14:52??Compiler\Release\w.txt

?????目錄??????????0??2008-11-02?22:28??Compiler\Compiler\Debug

?????目錄??????????0??2008-10-21?14:53??Compiler\Compiler\Release

?????目錄??????????0??2008-10-21?14:53??Compiler\Compiler

............此處省略6個文件信息

評論

共有 條評論