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

📄 ca.h

📁 该词法分析程序用VC++ 6.0编写
💻 H
字号:
#if !defined(AFX_CA_H__94C75FF6_0E29_4E5C_BF4E_B625D38EE396__INCLUDED_)
#define AFX_CA_H__94C75FF6_0E29_4E5C_BF4E_B625D38EE396__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CA.h : header file
//
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>

/////////////////////////////////////////////////////////////////////////////
// CCA command target
class CCA : public CObject
{

public:	CCA();
// Attributes
public:
// Operations
public:
void FENXI();
CString strFileName;
FILE *file_in,*file_out;
char cbuffer;
char *key[55];
char *border[11];
char *arithmetic[14];
char *relation[9];
char *consts[200];
char *label[200];
int constnum,labelnum;
int search(char searchchar[],int wordtype)
{
	int i=0;
	switch(wordtype) 
	{
	case 1:                                          //关键字
		for(i=0;i<55;i++)
		   {
			   if(strcmp(key[i],searchchar)==0)
				   return(i+1);
		   }
		return 0;
	case 2:                                          //界限符号		
			for(i=0;i<11;i++)
			{
			   if (strcmp(border[i],searchchar)==0)
				   return(i+1);
			}
			return 0;
	case 3:                                          //算术运算符		
       		for(i=0;i<14;i++)
			{
			   if (strcmp(arithmetic[i],searchchar)==0)
			   {
				   return(i+1);
			   }
			}
			return 0;
	case 4:                                         //关系运算符
			for (i=0;i<9;i++)
			{
			   if (strcmp(relation[i],searchchar)==0)
			   {
				   return(i+1);
			   }
			}
			return 0;
	case 5:                                          //常量
			for(i=0;i<constnum;i++)
			{
			   if (strcmp(consts[i],searchchar)==0)
			   {
				   return(i+1);
			   }
			}
		consts[constnum]=(char *)malloc(sizeof(searchchar));
		strcpy(consts[constnum],searchchar);
		constnum++;
		return(constnum);	
	case 6:                                         //变量
			for(i=0;i<labelnum;i++)
			{
			   if (strcmp(label[i],searchchar)==0)
			   {
				   return(i+1);
			   }
			}
		label[labelnum]=(char *)malloc(sizeof(searchchar));
		strcpy(label[labelnum],searchchar);
		labelnum++;
		return(labelnum);
	}
}

	char alphaprocess(char buffer)
	{
		int atype;
		int i=-1;
		char alphatp[20];
		while ((isalpha(buffer))||(isdigit(buffer)))
		{
			alphatp[++i]=buffer;
			buffer=fgetc(file_in);
		}
		alphatp[i+1]='\0';
		if (atype=search(alphatp,1))
		{
			fprintf(file_out,"%s (1,%d)\n",alphatp,atype-1);
		}
		else
		{
			atype=search(alphatp,6);
			fprintf(file_out,"%s (6,%d)\n",alphatp,atype-1);
		}

		return(buffer);
	}
	
	char digitprocess(char buffer)
	{
		int i=-1;
		char digittp[20];
		int dtype;
		while ((isdigit(buffer)))
		{
			digittp[++i]=buffer;
			buffer=fgetc(file_in);
		}
		digittp[i+1]='\0';
		dtype=search(digittp,5);
		fprintf(file_out,"%s (5,%d)\n",digittp,dtype-1);
		return(buffer);
	}
	
	char otherprocess(char buffer)
	{
		int i=-1;
		char othertp[20];
		int otype,otypetp;
		othertp[0]=buffer;
		othertp[1]='\0';
		if (buffer=='/')
		{
	    ag:buffer=fgetc(file_in);
            if (buffer=='/')
			{
				fputs("// (2,9)\n",file_out);
				goto ag;
			}
			buffer=fgetc(file_in);
			goto out;
		}
		if (otype=search(othertp,3))
		{
			fprintf(file_out,"%s (3,%d)\n",othertp,otype-1);
			buffer=fgetc(file_in);
			goto out;
		};
		
		if (otype=search(othertp,4))
		{
			buffer=fgetc(file_in);
			othertp[1]=buffer;
			othertp[2]='\0';
			if (otypetp=search(othertp,4))
			{
				fprintf(file_out,"%s (4,%d)\n",othertp,otypetp-1);
				goto out;
			}
			else
				othertp[1]='\0';
			fprintf(file_out,"%s (4,%d)\n",othertp,otype-1);
			goto out;
		};
		
			if (otype=search(othertp,2))
			{
				fprintf(file_out,"%s (2,%d)\n",othertp,otype-1);
				buffer=fgetc(file_in);
				goto out;
			}
		
		if ((buffer!='\n')&&(buffer!=' '))
		{
			fprintf(file_out,"%c error,not a word\n",buffer);
		}
		buffer=fgetc(file_in);
        out: 
		return(buffer);
	}

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CCA)
	//}}AFX_VIRTUAL

// Implementation

//	virtual ~CCA();

	// Generated message map functions
	//{{AFX_MSG(CCA)
		// NOTE - the ClassWizard will add and remove member functions here.
	//}}AFX_MSG

};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CA_H__94C75FF6_0E29_4E5C_BF4E_B625D38EE396__INCLUDED_)

⌨️ 快捷键说明

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