75 lines
916 B
C
75 lines
916 B
C
|
|
#pragma once
|
||
|
|
#include <stdint.h>
|
||
|
|
|
||
|
|
typedef enum node_kind_t {
|
||
|
|
Semi,
|
||
|
|
Comma,
|
||
|
|
Assignop,
|
||
|
|
Plus,
|
||
|
|
Minus,
|
||
|
|
Times,
|
||
|
|
Div,
|
||
|
|
And,
|
||
|
|
Or,
|
||
|
|
Dot,
|
||
|
|
Not,
|
||
|
|
Lp,
|
||
|
|
Rp,
|
||
|
|
Lb,
|
||
|
|
Rb,
|
||
|
|
Lc,
|
||
|
|
Rc,
|
||
|
|
Struct,
|
||
|
|
Return,
|
||
|
|
If,
|
||
|
|
Else,
|
||
|
|
While,
|
||
|
|
Type_int,
|
||
|
|
Type_float,
|
||
|
|
Integer,
|
||
|
|
Float,
|
||
|
|
Ident,
|
||
|
|
Line_comment,
|
||
|
|
Block_comment,
|
||
|
|
Program,
|
||
|
|
ExtDefList,
|
||
|
|
ExtDef,
|
||
|
|
ExtDecList,
|
||
|
|
Specifier,
|
||
|
|
StructSpecifier,
|
||
|
|
OptTag,
|
||
|
|
Tag,
|
||
|
|
VarDec,
|
||
|
|
FunDec,
|
||
|
|
VarList,
|
||
|
|
ParamDec,
|
||
|
|
CompSt,
|
||
|
|
StmtList,
|
||
|
|
Stmt,
|
||
|
|
DefList,
|
||
|
|
Def,
|
||
|
|
DecList,
|
||
|
|
Dec,
|
||
|
|
Exp,
|
||
|
|
Args
|
||
|
|
} NodeType;
|
||
|
|
typedef union value {
|
||
|
|
double real;
|
||
|
|
intptr_t integer;
|
||
|
|
char const *id;
|
||
|
|
void *null;
|
||
|
|
} ValueUnion;
|
||
|
|
typedef struct node {
|
||
|
|
NodeType type;
|
||
|
|
intptr_t line;
|
||
|
|
intptr_t size;
|
||
|
|
struct node **children;
|
||
|
|
union value value;
|
||
|
|
} Node;
|
||
|
|
|
||
|
|
typedef Node *pNode;
|
||
|
|
|
||
|
|
pNode newNode(NodeType, intptr_t, intptr_t, Node **, ValueUnion);
|
||
|
|
ValueUnion nullValue();
|
||
|
|
void DFS(pNode, int);
|