97 lines
1.3 KiB
C

enum NodeKind {
NODE_FUNCTION,
NODE_VAR_DECL,
NODE_TYPEDEF,
NODE_STRUCT,
NODE_RETURN,
NODE_BINARY_OP,
NODE_LITERAL,
NODE_IDENTIFIER,
NODE_CALL,
NODE_BLOCK,
}
struct ASTNode {
NodeKind kind;
union {
FunctionNode fn;
VarDeclNode var;
TypedefNode td;
StructNode str;
ExprNode expr;
BlockNode block;
}
}
// Function
struct FunctionNode {
String name;
String return_type;
List<VarDeclNode> params;
BlockNode body;
bool is_inline;
bool is_static;
bool is_export;
bool is_extern;
bool is_asm;
}
// Variable declaration
struct VarDeclNode {
String name;
String type;
ExprNode* init; // optional
bool is_raw;
}
// Block
struct BlockNode {
List<ASTNode> statements;
}
// Typedef
struct TypedefNode {
String alias;
String type;
}
// Struct
struct StructNode {
String name;
List<VarDeclNode> fields;
}
// Expression
enum ExprKind {
EXPR_LITERAL, EXPR_IDENTIFIER, EXPR_BINARY, EXPR_CALL, EXPR_CAST
}
struct ExprNode {
ExprKind kind;
union {
LiteralNode lit;
String ident;
BinaryExprNode bin;
CallExprNode call;
CastExprNode cast;
}
}
// Binary op
struct BinaryExprNode {
String op;
ExprNode* lhs;
ExprNode* rhs;
}
// Function call
struct CallExprNode {
String callee;
List<ExprNode> args;
}
// Literal
struct LiteralNode {
String value; // numeric, char, string
}