电子科技大学-计算机学院-编译原理实验-词法分析_第1页
电子科技大学-计算机学院-编译原理实验-词法分析_第2页
电子科技大学-计算机学院-编译原理实验-词法分析_第3页
电子科技大学-计算机学院-编译原理实验-词法分析_第4页
电子科技大学-计算机学院-编译原理实验-词法分析_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

include include include define MAX COUNT 1024 define ILLEGAL CHAR ERR 1 define UNKNOWN OPERATOR ERR 2 从标准输入读入第一个非空白字符 换行符除外 char getnbc char ch ch getchar while 1 if ch r ch t ch ch getchar else break return ch 判断 character 是否为字母 bool letter char character if character a else return false 词法分析函数 每调用一次识别一个符号 bool LexAnalyze static int lineNum 1 char character char token 17 character getnbc switch character case n output EOLN 24 lineNum break case EOF output EOF 25 return false false 表示已读到文件末尾 case a case b case c case d case e case f case g case h case i case j case k case l case m case n case o case p case q case r case s case t case u case v case w case x case y case z case A case B case C case D case E case F case G case H case I case J case K case L case M case N case O case P case Q case R case S case T case U case V case W case X case Y case Z while letter character digit character char s 2 character strcat token s character getchar retract character int num num reserve token if num 0 output token num else int val val symbol output token val break case 0 case 1 case 2 case 3 case 4 case 5 case 6 case 7 case 8 case 9 while digit character char s 2 character strcat token s character getchar retract character int val val constant output token val break case output 12 break case output 13 else if character output 14 else retract character output character getchar if character output 16 else retract character output 17 break case output 18 break case output 19 break case character getchar if character output 20 else error lineNum 2 输出 未知运算符 错误 break case output 21 break case output 22 break case output 23 break default error lineNum 1 输出 出现字母表以外的非法字符 错误 return true 获得路径 void getPath char in char out char name name strrchr in if name NULL strncpy out in strlen in strlen name 1 else strcpy out 获得文件名 不包括扩展 void getFilename char in char out char fullName char extension fullName strrchr in extension strrchr in if fullName NULL strncpy out fullName 1 strlen fullName 1 strlen extension else strncpy out in strlen in strlen extension 初始化函数 接收输入文件地址 并打开输入 输出 错误文件 将标准输入重定向到输入文件 将 标准输出重定向到输出文件 标准错误重定向到错误文件 bool init int argc char argv if argc 2 return false else char inFilename argv 1 argv 1 char outFilename MAX COUNT char errFilename MAX COUNT char filename MAX COUNT char path MAX COUNT 获得文件名 不包括扩展名 和路径 getFilename inFilename filename getPath inFilename path 生成输出文件全部路径 strcat outFilename path strcat outFilename strcat outFilename filename strcat outFilename dyd 生成错误文件全部路径 strcat errFilename path strcat errFilename strcat errFilename filename strcat errFilename err if freopen inFilename r stdin NULL else

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论