build a parser for c--

This commit is contained in:
ulic-youthlic 2025-03-24 18:40:16 +08:00
parent 843eb0938a
commit 7a6ac3d2b8
Signed by: youthlic
GPG key ID: 63E86C3C14A0D721
10 changed files with 830 additions and 3 deletions

74
node.h Normal file
View 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);