词法分析器实验报告597.pdfVIP

  • 3
  • 0
  • 约9.17千字
  • 约 11页
  • 2023-08-11 发布于上海
  • 举报
词法分析器实验报告 词法分析器实验报告 1.实验平台: visual studio 2010 2.实验⽬的 设计、编制、调试⼀个词法分析⼦程序-识别单词,加深对词法分析原理的理解。 3.数字状态转换图: 4本程序⾃⾏规定: (1)关键字begin,end,if,then,else,while,write,read, do, call,const,char,until,procedure,repeat (2)运算符:+,-,*,/,= (3)界符:{,},[,],;,,,.,(,),: (4)其他标记 如字符串,表⽰以字母开头的标识符。 (5)空格、回车、换⾏符跳过。 5.程序源代码: 源⽂件主要放在三个⽂件中:stdafx.h主要存放头⽂件stdafx.cpp主要存放函数的定义Compilertest.cpp :主函数定义 // stdafx.h : 标准系统包含⽂件的包含⽂件, // 或是经常使⽤但不常更改的 // 特定于项⽬的包含⽂件 #pragma once #include targetver.h #include stdio.h #include tchar.h #include iostream #include fstream #include string #include compiler.h using namespace std; int const keyLength=26; //定义关键字数组的⼤⼩ int const OPLENGTH1=8; //定义运算符数组⼤⼩ int const JLENGTH=9; //定义界符数组的⼤⼩ int const BFLENGTH=640; //定义双缓冲数组⼤⼩ //函数声明 char firstRead(); //⾸次读取 char getChar(); //读取⼀个字符 bool isLetter(char C); //判断字符串 bool isDigit(char C); //判断数字 bool isUnderLine(char C); //判断是否为下划线 bool isKeyLetter(string str); //判断关键字 bool isJieFu(char C); //判断界符 bool isOperator(char C); //判断运算符 void back(); //当前指针向前退⼀个 void myPrint(string s1,string s2); //⾃定义⽂件输出函数 char ciFaFenXi(char now); //词法分析函数 void readFBiao( ); //读取符号表 bool inGuanJianBiao(string fuhaobiao[2][600],string str); bool inBainLiangBiao(string fuhaobiao[2][600],string str); stdafx.cpp : // stdafx.cpp : 只包括标准包含⽂件的源⽂件 // Compilertest.pch 将作为预编译头 // stdafx.obj 将包含预编译类型信息 #include stdafx.h char buffer1[BFLENGTH]; //双缓冲1 char buffer2[BFLENGTH]; //双缓冲2 //定义符号表的当前⼤⼩ int fcount1=0; int fcount2=0; //定义关键字数组 string keyStr[keyLength]={cout,cin,this,if,else,while,true,false,iostream,new,main,infile,std,endl, using,namespace,char,int,double,float,bool,return,include,public,class,void}; //定义变量 char myOperator1[OP

文档评论(0)

1亿VIP精品文档

相关文档