globals.h

来自「混合991_编译实验」· C头文件 代码 · 共 100 行

H
100
字号
#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
#ifndef MAXTOKENLEN
#define MAXTOKENLEN 100
#endif
#define MAXRESERVED 7
#define MAXCHILDREN 3
#define SIZE      50
#define BUCKETSIZE 211

typedef int TokenType;

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



typedef enum {StmtK,ExpK,DeclK} NodeKind;
typedef enum {IfK,WhileK,ReturnK,AssignK,ExpStmtK,BreakK,CompoundK,InputK,OutputK} StmtKind;
typedef enum {SingleVarK,ArrayVarK,FuncVarK} DeclKind;
typedef enum {OpK,ConstK,IdK,ArrayK,CallK} ExpKind;


typedef enum {Void,Integer,Boolean,Char,Float} ExpType;

/**********************************************************/
/******************* struct for symboltable****************/
/**********************************************************/
typedef struct LineListRec
{
    int lineno;
	struct LineListRec* next;
} *   LineList;

typedef struct BucketListRec
{
    char* name;
	LineList lines;
	int memloc;
	int arraysize;/*just use for array*/
	bool func;
	ExpType type;
	struct BucketListRec* next;
}*  BucketList;

struct tableRec
{
      BucketList table[BUCKETSIZE];
	  tableRec* parent;
	  tableRec* sibling;
	  tableRec* child;
};
/********************************************************/
/********Syntax tree for pasing**************************/
/********************************************************/



typedef struct TreeNode
 {
 struct TreeNode* child[MAXCHILDREN];
 struct TreeNode* sibling;
 int lineno;
 NodeKind nodekind;
 union {StmtKind stmt; ExpKind exp; DeclKind decl;} kind;
 union {TokenType op;
        int vali;
		float valf;
		char valc;
	    char* name;
 }  attr;
 ExpType type;
 int     array_size; /*just use for declkind*/
 tableRec* tablep; /*position int symtab tree of this node*/
 }  TreeNode;


/*********************************************************/
/****************** flgas for tracing ********************/
/*********************************************************/
extern int TraceScan;
extern int EchoSource;
extern int Traceparse;
extern int TraceAnalyze;
extern int TraceCode;
extern int Error;

#endif

⌨️ 快捷键说明

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