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

📄 analyse.h

📁 此法分析器代码。从测试文件读入输入字符
💻 H
字号:
#ifndef _SCAN_H_
#define _SCAN_H_
#include <iostream>
using namespace std;

/* MAXTOKENLEN is the maximum size of a token */
#define MAXTOKENLEN 40
/* MAXRESERVED = the number of reserved words */
#define MAXRESERVED 6


/* tokenString array stores the lexeme of each token */
extern char tokenString[MAXTOKENLEN+1];

/* states in scanner DFA */
typedef enum 
    /* book-keeping tokens */
 //    错误注释          错误不等于 
	{WRONGCOMMENT,ERROR,WRONGDIF,ENDFILE,
    /* reserved words */ 
    IF,ELSE,INT,RETURN,VOID,WHILE,
    /* multicharacter tokens */
    ID,NUM,
    /* special symbols */
//  =     ,==,< ,<= ,> ,>= , +  , -   ,  *  , /  ,       ( , ) ,          [ , ] ,         { , } ,     ;  ,  ',', !=   
    ASSIGN,EQ,LT,LTE,GT,GTE,PLUS,MINUS,MULTIP,DIVIDE,LPARENl,RPAREN1,LPAREN2,RPAREN2,LPAREN3,RPAREN3,SEMI,COMMA,DIF
   } TokenType;

/* BUFLEN = length of the input buffer for
   source code lines */
#define BUFLEN 256


class CToken
{
public:
	CToken(FILE *InFile,FILE * OutFile);
	void getToken(void);
	~CToken();
	bool EOF_flag; /* corrects ungetNextChar behavior on EOF */
private:
	FILE *source,*listing;
	char tokenString[MAXTOKENLEN+1];
	char lineBuf[BUFLEN]; /* holds the current line */
	int linepos; /* current position in LineBuf */
	int bufsize; /* current size of buffer string */
	char getNextChar(void);
	int lineno;
	void ungetNextChar(void);
	TokenType reservedLookup(char * s);
};


#endif

⌨️ 快捷键说明

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