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

📄 main.cpp

📁 自己做的小编译程序,大家看看好不好用哦,是词法分析器
💻 CPP
字号:
#ifndef MAIN_CPP_INCLUDED
#define MAIN_CPP_INCLUDED

#include <stdio.h>
#include <string>
#include <iostream>
using namespace std; 

#include "mylist.h"
#include "scanner.h"

extern FILE* f;
extern char buffer[256];
extern string LexName[42];
extern CMyList<CToken> TokenList;
extern CMyList<string> identiferList;
extern CMyList<string> unsignedIntList;

int main()
{	
	f = fopen("test1.txt","r");
	if (f == NULL)
	{
		printf("File load fail\n");
	}
	else
	{
		printf("File load succeed\n");
		cout<<endl;

		TokenList = getTokenList(f,buffer);
		
		cout<<"There are  " << TokenList.Size() << "  tokens in the Tokenlist"<<endl;
      	if(TokenList.Size()!=0)
		{
		    cout<<"   lineShow        lex             sem " << endl;

			cout<<"   --------   -------------   -------------"<<endl;
			for(int i=0;i < (TokenList.Size()+100);i++)
			{
				Node<CToken>* ptr = TokenList.GetNode(i);
				if(ptr)
					{
						printf(" %8d  %14s   %12s \n",
						(ptr->data).lineShow,
					    LexName[(ptr->data).lex].c_str(),
						(ptr->data).sem.c_str());
					}
		
			}
		}


		cout<<endl;
	    cout<<"There are  " << identiferList.Size() << "  identifers in the Tokenlist"<<endl;
		if(identiferList.Size()!=0)
		{
				cout<<" They are " <<endl;
				for(int j=0;j < identiferList.Size();j++)
			{
					Node<string>* ptr = identiferList.GetNode(j);
					if(ptr)
						{
						printf("  %12s \n",
						(ptr->data).c_str());
						}
		
			}
		}

		cout<<endl;
		cout<<"There are  " << unsignedIntList.Size() << "  unsignedInts in the Tokenlist"<<endl;
		if(unsignedIntList.Size()!=0)
		{

				cout<<" They are " <<endl;
					for(int k=0;k< unsignedIntList.Size();k++)
				{
					Node<string>* ptr = unsignedIntList.GetNode(k);
					if(ptr)
						{
							printf("  %12s \n",
							(ptr->data).c_str());
						}
		
				}
		}
		
	}
	return 0;
}

#endif

⌨️ 快捷键说明

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