feat: L Language v0.1 编译器完整实现
5 阶段编译流水线: 词法分析 → 语法分析(Pratt) → 语义分析(类型推断) → LLVM IR → .exe 模块: - lexer: 手写状态机, 40 种 Token, // 和 /* */ 注释 - parser: Pratt 表达式解析(9 级优先级) + 递归下降语句/函数 - ast: 14 种节点类型 + 工厂函数 - sema: 作用域链符号表 + 类型推断 + 类型检查 - codegen: AST → LLVM-C API, print_i64/f64/bool 内建 - driver: 命令行 + 流水线串联 + 错误报告 - util: Arena bump allocator (8MB) 测试: 65 单元测试(词法41+语法15+语义9) + 5 集成测试 全部通过 语言特性: i64/f64/bool/void, let不可变变量, if/else, while, 递归函数
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
#ifndef L_LANG_H
|
||||
#define L_LANG_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// === 类型系统 ===
|
||||
typedef enum {
|
||||
TYPE_I64,
|
||||
TYPE_F64,
|
||||
TYPE_BOOL,
|
||||
TYPE_VOID,
|
||||
TYPE_UNKNOWN, // 尚未推断
|
||||
TYPE_ERROR, // 类型错误
|
||||
} TypeKind;
|
||||
|
||||
static inline const char* type_name(TypeKind kind) {
|
||||
switch (kind) {
|
||||
case TYPE_I64: return "i64";
|
||||
case TYPE_F64: return "f64";
|
||||
case TYPE_BOOL: return "bool";
|
||||
case TYPE_VOID: return "void";
|
||||
default: return "<unknown>";
|
||||
}
|
||||
}
|
||||
|
||||
// === 向前声明 ===
|
||||
typedef struct Token Token;
|
||||
typedef struct AstNode AstNode;
|
||||
typedef struct Scope Scope;
|
||||
typedef struct Arena Arena;
|
||||
|
||||
// === 跨模块分配器接口(避免循环依赖,各模块通过 void* 使用 arena)===
|
||||
void* arena_alloc_impl(void* alloc, size_t size);
|
||||
char* arena_strdup_impl(void* alloc, const char* src, size_t len);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user