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

📄 globals.h

📁 CMinus 小型编译器的词法分析与语法分析部分
💻 H
字号:
/****************************************************/
/* File: globals.h                                  */
/* Global types and vars for TINY compiler          */
/* must come before other include files             */
/* Compiler Construction: Principles and Practice   */
/* Kenneth C. Louden                                */
/****************************************************/

#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


typedef enum 
    /* book-keeping tokens */
   {ENDFILE,ERROR,
    /* reserved words */
    IF,ELSE,RETURN,WHILE,
    /* multicharacter tokens */
    ID,NUM,
	/* type*/
	INT,VOID,
    /* special symbols + - * / < <= > >= == != = ; , ( ) [ ] { } */    PLUS,MINUS,TIMES,OVER,LT,LTEQ,GT,GTEQ,EQ,NOEQ,ASSIGN,SEMI,COMMA,LPAREN,RPAREN,LBRA,RBRA,LBRACE,RBRACE
   } TokenType;

extern FILE* source; 
extern FILE* listing;
extern FILE* code; 

extern int lineno; 

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

typedef enum {StmtK,ExpK,DecK,ParamK} NodeKind;
typedef enum {CompoundK,SelectionK,IterationK,ReturnK,ExpressionK} StmtKind;
typedef enum {OpK,ConstK,IdK,AssignK,CallK} ExpKind;
typedef enum {Var,Array,Null} ParamKind;
typedef enum {ArrayK,VarK,FunK} DecKind;		//declaration kind treenode ;

#define MAXCHILDREN 3

typedef struct treeNode
   { struct treeNode * child[MAXCHILDREN];
     struct treeNode * sibling;
     int lineno;
     NodeKind nodekind;
     union { StmtKind stmt; ExpKind exp; DecKind dec;ParamKind param;} kind;
     union { TokenType op;
             int val;
			 char * type;
             char * name; } attr;
   } TreeNode;

extern int EchoSource;
extern int TraceScan;
extern int TraceParse;
extern int Error; 

#endif

⌨️ 快捷键说明

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