- 0
- 0
- 约1.19万字
- 约 20页
- 2020-08-22 发布于福建
- 举报
实 验 报 告
学号: 姓名: 专业:计算机科学与技术 班级: 2 班 第 9 周
课程
编译原理课程设计 实验课时 8
名称
实验
手工构造 Tiny 语言的词法分析器 实验时间 7-10 周
项目
实验 熟悉 Tiny 语言词法;构造 DFA;设计数据类型、数据结构;用 C++实现 Tiny 语
目的 言的词法分析器
Windows 10 专业版
实验
环境
Microsoft Visual Studio 2013
一、 Tiny 语言记号
Reserved words Special Symbols Other
实验
if +
内容
(算
then -
法、
else * number(1 or more digits)
程
序、
end
步骤
repeat =
和方
法)
until /
identifier(1 or more
letters)
read (
write )
;
:=
二、构造 Tiny 语言 DFA
ID :letter(letter)*
Number: digit(digit)*
三、根据 DFA编写词法分析器
#include fstream
#include string
#include iostream
using namespace std;
static int rowCounter = 1; // 静态变量,用于存储行数
static bool bracketExist = false ; // 判断注释存在与否, false 为不存在
class Lex
{
public :
ofstream output;
string line = ;
Lex( string inputLine )
{
line = inputLine ;
scan(Trim(line));
rowCounter++;
}
string Trim( string str ) // 函数用于去除每行前后空格
{
int s = ( \t );
int e = ( \t );
str = (s, e - s + 1);
str += \0 ;
return str ;
}
void scan( string inputLine )
{
ofstream output;
( , ios ::app);
string line = inputLine ;
您可能关注的文档
最近下载
- 新职业英语职业综合英语2(第三版)VR版Unit+1+PPT课件.pptx VIP
- 2026年部编版新教材语文小学二年级下册全册教案(含教学计划).pdf
- 计算机应用基础教程(Windows10+Office2016)PPT全套完整教学课件.pptx VIP
- 烹饪原理课件.pptx VIP
- 眩晕晕厥意识障碍(共48张PPT).pptx VIP
- 军工科研院所基于组织变革的科技创新体系构建与实施.pptx VIP
- 在学习贯彻党的二十届四中全会精神研讨会上的讲话.doc VIP
- 电缆价格详细计算表.xls VIP
- 生产制造过程管理汇报.pptx VIP
- 部编编人教版四年级下册小学道德与法治全册精品课件PPT.pptx
原创力文档

文档评论(0)