- 4
- 0
- 约1.68万字
- 约 13页
- 2021-01-21 发布于天津
- 举报
精品文档
实 验 报 告
学号: 姓名: 专业:计算机科学与技术 班级: 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 /
和方 read (
identifier(1 or more
法) write )
letters)
;
:=
.
精品文档
二、构造 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 )
原创力文档

文档评论(0)