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

📄 globals.h

📁 c的简化编译器
💻 H
字号:
/****************************************************/
/* File: globals.h                                  */
/* Main program for c- compiler                     */
/* Compiler Construction: Principles and Practice   */
/* Maker:Liukai                                     */
/****************************************************/

#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

/* MAXRESERVED = the number of reserved words */
#define MAXRESERVED 6
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 */
typedef enum 
    /* book-keeping tokens */
   {ENDFILE,ERROR,
    /* reserved words */
    IF,ELSE,WHILE,INT,RETURN,VOID,
    /* multicharacter tokens */
    ID,NUM,
    /* special symbols */
    ASSIGN,EQ,NEQ,LT,PLUS,MINUS,TIMES,OVER,LPAREN,RPAREN,SEMI,DOUHAO,ZLPAREN,ZRPAREN,DLPAREN,DRPAREN,MT,LET,MET
   } TokenType;
//////////////////////////////////////////////////////////////////////////////////////
/**************************************************/
/***********   Syntax tree for parsing ************/
/**************************************************/
typedef enum {StmtK,ExpK} NodeKind;
typedef enum {IfK,WhileK,AssignK,CompoundK,ReturnK} StmtKind;
typedef enum {OpK,ConstK,IdK} ExpKind;
typedef enum {VarK,FunK} IdType1;

typedef enum {Void,Int} ExpType;
typedef enum {yes,no} isarry;


/////////////////////////////////////////////////////////////*****************

typedef struct TreeNode
{
	struct TreeNode *child[3];
	struct TreeNode *sibling;
	int lineno;
	NodeKind nodeKind;
	union {StmtKind stmt;ExpKind exp;} Kind;
	IdType1 idtype1;
	/*IdType2 idtype2;*/
	isarry is;
	int arryno;
	union {TokenType op;
			int val;
			char *name;
			} attr;
	ExpType type;
} 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 token 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
 * printed 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

⌨️ 快捷键说明

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