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

📄 globals.h

📁 编译原理课程设计 词,语法分析器 用C++手工编写
💻 H
字号:
#ifndef _GLOBALS_H_
#define _GLOBALS_H_


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

#define MAXRESERVED 6

typedef enum
{
	/*	book-keeping tokens		*/
	ENDFILE, ERROR,
	/*	reserved word			*/
	ELSE, IF, INT, RETURN, VOID, WHILE,
	/*	multicharacter token	*/
	ID, NUM,
	/*	special symbols			*/
	PLUS,	MINUS,	TIMES,	DIV,	LT,		LEQ,	GT,		GEQ,
//	+		-		*		/		<		<=		>		>=	
	EQ,		NEQ,	ASSIGN,	SEMI,	COMMA,	LPAREN,	RPAREN,	LSPAREN,	RSPAREN,
//	==		!=		=		;		,		(		)		[			]	
	LBPAREN,	RBPAREN,	LNOTE,	RNOTE
//	{			}			/*		*/
}TokenType;

extern FILE* source;
extern FILE* listing;
extern FILE* code;
extern int lineno;


/************************************************************/
/**********		Syntax tree for parsing		*****************/
/************************************************************/

    typedef enum {DeclarK,ParamK,StmtK,ExpK} NodeKind;

typedef enum {VarK,ArrayK,FuncK} DeclarKind;
typedef enum {Var,Array,Null} ParamKind;
typedef enum {IfK,WhileK,ReturnK,ExpressionK,CompoundK} StmtKind;
typedef enum {OpK,ConstK,IdVarK,IdArrayK,CallK} ExpKind;


     #define MAXCHILDREN 3
typedef struct treeNode
   { struct treeNode * child[MAXCHILDREN];
     struct treeNode * sibling;
     int lineno;
     NodeKind nodekind;
     union { DeclarKind declar;
	         ParamKind param;
	         StmtKind stmt; 
			 ExpKind exp;} kind;
     union { TokenType op;
             int val;
             char * name; } attr;
      char type[10]; /* for type checking of exps */
   } TreeNode;

/***************************************/
/****		Flags for tracing	********/
/***************************************/

/*	EchoSource = TRUE causes the source program to 
 *	printed to the listing file in linearized form
 *	(using indents for children)
 */
extern int EchoSource;

extern int TraceScan;

extern int TraceParse;

extern int TraceAnalyze;

extern int TraceCode;

extern int Error;


#endif

⌨️ 快捷键说明

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