example.c

来自「编译原理词法分析器实现四」· C语言 代码 · 共 47 行

C
47
字号
// exam.c : Defines the entry point for the console application.
#include <stdlib.h>
#include <stdio.h>
int linesCount=0;
int yaccVerbose=0;
int lexVerbose=0;
struct CSiYuan
{
	char m_op[30];
	char m_arg1[30];
	char m_arg2[30];
	char m_arg3[30];
};

extern struct CSiYuan JiLu[100];
extern int nCurrentPosition;
extern int yyparse();

void PrintAll();

int main(int argc, char* argv[])
{
	extern FILE *yyin;

	printf("Compiling...!\n");
	if((yyin=fopen("exprTest.txt","rt"))==NULL){
			perror("can not open file exprTest.txt\n") ;
			exit(1);
		}
	if (yyparse()){
		fprintf(stderr,"parser error\n");
		exit(1);
	}
	printf("yyparse() completed successfully!\n");
	PrintAll();
	return 0;
}

void PrintAll()
{
	int i;
	for(i=0; i<nCurrentPosition; ++i)
	{
		printf("  %d\t(%10s,%10s,%10s,%10s)\n", i, JiLu[i].m_op,
				JiLu[i].m_arg1, JiLu[i].m_arg2, JiLu[i].m_arg3);
	}
}

⌨️ 快捷键说明

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