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

📄 globals.h

📁 SIP软件开发记录 由于通信网的封闭性
💻 H
字号:
/* globals.h
 * Global types and vars for TINY compiler
 * must come before other include files
 *
 * Compiler Construction: Principles and Practice
 * Kenneth C. Louden
 * 编译原理及实践
 * (美) Kenneth C. Louden 著
 * 冯博琴 冯岚 等译
 * 机械工业出版社 IBSN 7-111-07703-2
 * 源代码:郑卫飞编辑并修订
 * Code Modify: zwf 2004.05
 */

#ifndef _GLOBALS_H_
#define _GLOBALS_H_

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

#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

//#define CHINESE /* Use Chinese GB2312 */

#ifndef isname					/* This is a Chinese char */
//#define isname(c) isalpha(c)
#define isname(c) ((((c)>='a') && ((c)<='z')) \
		|| (((c)>='A') && ((c)<='Z')) \
		|| ((c)=='_') \
		|| (((c)>=(char)0xA1) && ((c)<=(char)0xFE)))
#endif
#ifndef isnum
//#define isnum(c) isdigit(c)
#define isnum(c) (((c)>='0') && ((c)<='9'))
#endif

/* MAXRESERVED = the number of reserved words */
//#define MAXRESERVED 8
#define MAXRESERVED 16

typedef enum {
/* book-keeping tokens */
	ENDFILE, ERROR,
/* reserved words */
	IF, THEN, ELSE, END, REPEAT, UNTIL, READ, WRITE,
/* multicharacter tokens */
	ID, NUM,
/* specical symbols */
	ASSIGN, LT, LE, GT, GE, EQ, NE, PLUS, MINUS, TIMES, OVER, LPAREN,
		RPAREN, SEMI
} TokenType;

extern FILE *source;			/* source code text file */
extern FILE *listing;			/* listing output text file */
extern FILE *code;				/* code text file for TM simulator */

extern int lineno;				/* source line number for listing */

/* Syntax tree for parsing */
typedef enum {
	StmtK, ExpK
} NodeKind;

typedef enum {
	IfK, RepeatK, AssignK, ReadK, WriteK
} StmtKind;

typedef enum {
	OpK, ConstK, IdK
} ExpKind;

/* ExpType is used for type checking */
typedef enum {
	Void, Integer, Boolean
} ExpType;

#define MAXCHILDREN 3

typedef struct treeNode {
	struct treeNode *child[MAXCHILDREN];
	struct treeNode *sibling;
	int lineno;
	NodeKind nodekind;
	union {
		StmtKind stmt;
		ExpKind exp;
	} kind;
	union {
		TokenType op;
		int val;
		char *name;
	} attr;
	ExpType type;				/* for type checking of exps */
} TreeNode;

/* Flags for tracing */

/* EchoSource = TRUE causes the source program to
 * be echoed to the listing file with line numbers
 * during parsing
 */
extern int EchoSource;

/* TraceScan = TRUE causes the information to be
 * printed to the listing file as each token is
 * recognized by the scanner
 */
extern int TraceScan;

/* TraceParse = TRUE causes the syntax tree to be
 * printded to the listing file in linearized form
 * (using indents for children)
 */
extern int TraceParse;

/* TraceAnalyze = TRUE causes symbol table inserts
 * and lookups to be reported to the listing file
 */
extern int TraceAnalyze;

/* TraceCode = TRUE causes comments to be written
 * to the TM code file as code is generated
 */
extern int TraceCode;

/* Error = TRUE prevents further passes if an error occurs */
extern int Error;
#endif							/* _GLOBALS_H_ */

⌨️ 快捷键说明

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