⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cifa.cpp

📁 简单的词法分析器,真的很简单,优点是容易看懂,适合于初学者
💻 CPP
字号:
#include <stdio.h>
#include <string.h>
#include <process.h>
#define MAX 50
void main()
{
	FILE *in,*out;/*存放输入字符串和输出单词串的文件*/
	char arr[MAX];/*arr数组存放单词符号*/
	char currentchar;/*currentchar存放当前输入字符*/
	int i=0;/*arr数组的一个指针*/
	/*以读方式打开输入文件*/
	if((in=fopen("infile.txt","r"))==NULL)
	{
		printf("can not open file\n");
		exit(0);
	}
	/*以写方式打开输出文件*/
	if((out=fopen("outfile.txt","w"))==NULL)
	{
		printf("cannout open outfile\n");
		exit(1);
	}
	//去掉开头空格
	currentchar=fgetc(in);
	while(currentchar==' ')
	{
		currentchar=fgetc(in);
	}
	int ch;


	while(currentchar!='@')//结束符号
	{
		/*常数部分判断*/
		if((currentchar>='a'&&currentchar<='z')||(currentchar>='A'&&currentchar<='Z')||
		(currentchar>='0'&&currentchar<='9')||currentchar=='('||currentchar==')'||
		currentchar=='{'||currentchar=='}'||currentchar=='>'||currentchar=='<'||
		currentchar==';'||currentchar==':'||currentchar=='+'||currentchar=='-'||
		currentchar=='*'||currentchar=='/'||currentchar=='='||currentchar=='!'||
		currentchar=='&'||(ch=currentchar)=='\n'||currentchar==' '||currentchar=='['||currentchar==']')
		{
			i=0;//清空arr字符数

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -