词法分析器(3.主程序文件)

//
//     Fundamentals of Compiler
//project:  World analysis
//written by: kejie 03 computer science and techology 086
//create time: 2006.4.5
//modified:  2006.4.15
//file name: main.cpp
//note:   This file is the main program, useing to analysis the source file
//Copyright University of electronic science and technology of China, ZhongShan Institute.
//

//#include<iostream.h>
//#include<fstream.h>
#include "Analysis.h"
#include <stdio.h>

//文件路径
char * CharPath = "OperatorTable.txt";

extern char * KeyWorldPath;
extern char * SourcePath;
static int ChoseNum;

//变量表,用于保存扫描到的变量


//常数表,用于保存扫描到的常数


LEX WordAnalysis(SourcePath);    //词法分析器类
BSTree OperatorTable(CharPath,0x0);   //操作符从0x00 开始编码
BSTree KeyTable(KeyWorldPath,0x040);  //关键字从0x40 开始编码

//程序开始界面(由于来不及用MFC做一个程序界面,现在只可以在DOS中运行了!
void InterFace()
{
 cout<<"University of Electronic Science and Technology of China, ZhongShan Institute"<<endl
  <<"Computer Engineering Department"<<endl
  <<"03 Computer Science and Technology"<<endl<<endl;
 
 cout<<"Author: Kejie "<<endl<<endl<<endl;
 
 cout<<setw(59)<<"Foundamenation of Complieration: Word Analysis"<<endl
  <<setw(49)<<"1.Show the source of read"<<endl
  <<setw(51)<<"2.Run  the analysis program"<<endl
  <<setw(48)<<"3.Print the KeyWord Tree"<<endl
  <<setw(49)<<"4.Print the Operator Tree"<<endl
  <<setw(30)<<"5.Exit"<<endl<<endl
  <<"If your have any question about the program or want to learn more about me please mail to me!"<<endl
  <<"My Email address is:
kejieleung@163.com"<<endl
  <<"Waiting for you! Thank you!"<<endl
  <<"Please Chose an operation:";
  
}

void Choose( int num )
{
 //assert( num>= 1 && num<= 5);
 switch ( num )
 {
  case 1:
   cout<<"Follow is the souce read from the outer fiel source.txt."<<endl;
   WordAnalysis.PrintSource();
   break;
  case 2:
   cout<<"Follow is the result of the worl analysis:";
   WordAnalysis.Analysis();
   break;
  case 3:
   cout<<"Follow is the tree that the program code the key worlds in the KeyWord.text:"<<endl;
   KeyTable.PrintTree();
   break;
  case 4:
   cout<<"Follow is the tress that the program code the operators int the OperatorTable.txt"<<endl;
   OperatorTable.PrintTree();
   break;
  case 5:
   break;
  default:
   cout<<"Input Eorror !";
 }

 cout<<endl;
}
int main()
{
 while( ChoseNum != 5 )
 {
  system("cls");
  InterFace();
  cin>>ChoseNum;
  
  Choose(ChoseNum);
  cout<<"Press any key to continue!"<<endl;
  getchar();

 }

 cout<<endl;
 

 return 0;
}

//程序调试记录(Created 4.7 Update 4.13)

//1.字符串识别有问题,比如输出时"X..."应为全输出而不用考虑是否为关键字 (OK)
//2.二元操作符无法识别  (OK)

//3.编码出现负数   (OK)
//4.空格时无法正确确认  (OK)
//5.释放二叉树出错   (OK)
//6.变量未初始化(构造函数不能自己调用引起)  (OK)
//7.对关键字还是普通字符串的判断出现逻辑错误 (OK)
//8.缓冲指示 bufPos 值异常  (OK)

//9.操作符不完全
//10.变量重复(应该保存在符号表中,用指针指示)
//11.无法去除读入注释   (OK)
//12.错语输入选择是没有处理
//13.常量表没有做

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值