build a parser for c--
This commit is contained in:
parent
843eb0938a
commit
7a6ac3d2b8
10 changed files with 830 additions and 3 deletions
74
node.h
Normal file
74
node.h
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
#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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue