Java 词法分析器实验报告 --07111101 --奥特曼 一.词法分析器功能概述: 1. 使用DFA实现词法分析器的设计; 2. 实现对Java源程序中注释和空格(空行)的过滤; 3. 利用两对半缓冲区从文件中逐一读取单词; 4. 词法分析结果属性字流存放在独立文件(c:\words.txt)中; 5. 统计源程序所有单词数以、错误单词数、单词所在的行数; 6. 具有报告词法错误和出错位置(源程序行号)的功能; 二.源程序设计实现: //程序大部分参照网络,自己做了小部分改动 #include #include #include #include #include #include "const.h" using namespace std; char rbuf[RBUFSIZE]; //读文件缓冲区 int rp; //读文件缓冲区指针 char ch; //当前扫描到的字符 int type; //单词的类型 char sbuf[SBUFSIZE]; //单词字符串缓冲区 int sp; //单词字符串缓冲区指针 ifstream inFile; //输入文件 ofstream outFile; //输出文件 void clear_rbuf()//清空读文件缓冲区 { int i; for(i=0;i='0'&&c<='7') result = (int)(c - '0'); else if(c>='8'&&c<='9') { if (base > 8) result=(int)(c-'0'); else result = -1; } else if(c>='a'&&c<= 'f') { if (base>10) result=(int)(c-'a'+10); else result=-1; } else if (c>='A'&&c<='F') { if (base>10) result=(int)(c-'A'+10); else result=-1; } else result=-1; return result; } void scan_fraction()//扫描指数 { while(digit(10)>=0) { put_ch(ch); get_ch(); } if(ch=='e'||ch=='E') { put_ch(ch); get_ch(); if(ch=='+'||ch=='-')...