Files
l-language/include/l_lang.h
T
Serendipity 3b7bab1e1b 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, 递归函数
2026-06-05 00:26:59 +08:00

39 lines
922 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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