📄 lexanalyser.h
字号:
#ifndef _LEXANALYSER_H
#define _LEXANALTSER_H
#include <stdio.h>
#include "literal.h"
#include "table.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
void InitLex(){ //词法分析主程序,初始化相关变量及调用相关函数
char words[63];
int i,j,line,intype,retype,length;
FILE *fp;
char currentch,nextch,filename[10];
array_state = 0;
func_id = 0;
func_var = 0;
func_match = 0;
nodenum = 0;
j = 0;
line = 0;
clear (words);
notes = 1;
length = 0;
i = 0;
initWord();
printf("Please enter the filename \n");
scanf("%s",filename);
if((fp = fopen(filename,"r")) == NULL)
{
printf ("cannot open file \n");
}
currentch = fgetc(fp);
nextch = fgetc (fp);
while (currentch != EOF)
{
if (currentch == '\n')
{
currentch = nextch;
nextch = fgetc(fp);
line++;
continue;
}
if (currentch == ' ')
{
currentch = nextch;
nextch = fgetc(fp);
continue;
}
if ((currentch == '}') && (notes == 0))
notes = 1;
if (notes == 0)
{
currentch = nextch;
nextch = fgetc(fp);
continue;
}
words[j] = currentch;
retype = oftype(currentch,nextch,words,j,retype);
switch(retype){ //判断类型,进行不同处理.
case -2:
printf("error!\n");
break;
case -1:
j++;
break;
case 0: //id
intype = id;
insertl(Lhead,intype,1,words,line,j);
clear(words);
j = 0;
break;
case 1: //num
intype = num;
insertl(Lhead,intype,1,words,line,j);
clear(words);
j = 0;
break;
case 47 : //digit;
intype = rw_digits;
insertl(Lhead,intype,1,words,line,j);
clear(words);
j = 0;
break;
case 42: //{
clear(words);
j = 0;
break;
case 43: //}
clear(words);
j = 0;
break;
default:
{//关键字或是操作符.
insertl (Lhead,retype,0,words,line,j);
clear(words);
j = 0;
} //end_default
} //end_case
currentch = nextch;
nextch = fgetc(fp);
}//end_while
retype = DOLLAR;
insertl(Lhead,retype,0,words,line,j);
printf("The Label stream is : \n");
displayl(Lhead);
printf ("\n");
printf("The symbol table is : \n");
displays(Shead);
}//end_main
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -