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

  • 大小: 856KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發布日期: 2021-05-05
  • 語言: 其他
  • 標簽: 詞法分析??

資源簡介

相關博客請訪問https://blog.csdn.net/boss_crabe/article/details/80760252

資源截圖

代碼片段和文件信息

#include?
#include?
#include?
#include?
#include?
using?namespace?std;

const?int?MAX_SIZE?=?1000000;

set?reserved_words;

void?init_reserved_words()?{
??reserved_words.insert(“Const“);
??reserved_words.insert(“Var“);
??reserved_words.insert(“if“);
??reserved_words.insert(“then“);
??reserved_words.insert(“else“);
??reserved_words.insert(“while“);
??reserved_words.insert(“do“);
??reserved_words.insert(“begin“);
??reserved_words.insert(“end“);
}

bool?isdigit(char?c)?{?return?c?>=?‘0‘?&&?c?<=?‘9‘;?}

bool?isalpha(char?c)?{?return?(c?>=?‘a‘?&&?c?<=?‘z‘)?||?(c?>=?‘A‘?&&?c?<=?‘Z‘);?}

void?lexical_analysis(int?flag)?{
??freopen(“file_out.txt“?“w“?stdout);
??char?s[MAX_SIZE];
??char?tmp[105];
??int?len?tmp_len?pos?cnt?=?0;
??while(gets(s))?{
????len?=?strlen(s);
????cnt++;
????pos?=?0;
????while?(pos?????if?(flag)?printf(“%3d:“?cnt);
????if?(flag)?{
??????if?(pos?==?len)
????????puts(““);
??????else
????????printf(“?%s\n“?s?+?pos);
????}
????while?(pos???????while?(pos???????if?(pos?==?len)?break;
??????tmp_len?=?0;
??????if?(flag)?printf(“????%3d:?“?cnt);
??????if?(isdigit(s[pos]))?{
????????while?(pos???????????tmp[tmp_len++]?=?s[pos++];

????????tmp[tmp_len]?=?‘\0‘;
????????if?(flag)?printf(“Number?:?%s\n“?tmp);
????????else?printf(“%d?%s\n“?cnt?tmp);
??????}
??????else?if?(isalpha(s[pos]))?{
????????while?(pos???????????tmp[tmp_len++]?=?s[pos++];
????????tmp[tmp_len]?=?‘\0‘;
????????if?(flag)?{
??????????if?(reserved_words.count(tmp))
????????????printf(“Reserved?words?:?%s\n“?tmp);
??????????else
????????????printf(“Identifier?:?%s\n“?tmp);
????????}
????????else?{
??????????if?(reserved_words.count(tmp))
????????????printf(“%d?%s\n“?cnt?tmp);
??????????else
????????????printf(“%d?%s\n“?cnt?tmp);
????????}
??????}
??????else?{
????????while(pos???????????tmp[tmp_len++]?=?s[pos++];

????????tmp[tmp_len]?=?‘\0‘;
????????if?(flag)
??????????printf(“%s\n“?tmp);
????????else
??????????printf(“%d?%s\n“?cnt?tmp);
??????}
????}
??}
}

int?main()?{
??freopen(“file_in.txt“?“r“?stdin);
??init_reserved_words();
??lexical_analysis(0);
??return?0;
}

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-06-21?14:28??詞法分析\
?????文件??????????56??2017-12-14?20:23??詞法分析\file_in.txt
?????文件?????????152??2018-01-09?14:57??詞法分析\file_out.txt
?????文件?????????648??2018-01-09?14:56??詞法分析\file_show.txt
?????文件????????2448??2017-12-15?13:05??詞法分析\詞法分析.cpp
?????文件?????1899811??2018-01-09?14:57??詞法分析\詞法分析.exe
?????文件???????14519??2018-06-21?14:28??詞法分析\詞法分析_謝俊峰.docx
?????文件????????2975??2018-01-09?14:56??詞法分析\詞法分析展示.cpp
?????文件?????1899811??2018-01-09?14:56??詞法分析\詞法分析展示.exe

評論

共有 條評論