feat: 添加“while 语句”支持,并对解析器进行重构以处理控制流相关内容
- 引入了 WhileStmt 结构来表示 while 循环语句。 - 在解析器中实现了对 while 语句的解析逻辑。 - 在分析器中为 while 语句添加了语义分析。 - 重构了现有的解析器方法,以利用 StateProtector 进行状态管理。 - 更新了对各种表达式和语句的错误处理。 - 移除了未使用的终止符管理方法,并简化了表达式解析。 - 将 FigLSPServer.cpp 重命名为 LSPServer.cpp,并调整了构建配置。 - 增强了重复声明和类型错误的错误报告。 - 在多个文件中改进了代码格式和一致性。
This commit is contained in:
@@ -16,4 +16,5 @@
|
||||
|
||||
#include <Ast/Stmt/ExprStmt.hpp>
|
||||
#include <Ast/Stmt/IfStmt.hpp>
|
||||
#include <Ast/Stmt/VarDecl.hpp>
|
||||
#include <Ast/Stmt/VarDecl.hpp>
|
||||
#include <Ast/Stmt/WhileStmt.hpp>
|
||||
@@ -36,7 +36,8 @@ namespace Fig
|
||||
ExprStmt, // 表达式语句,如 println(1)
|
||||
VarDecl, // 变量声明
|
||||
IfStmt, // If语句
|
||||
ElseIfStmt, // ElseIf语句,不准悬空
|
||||
ElseIfStmt, // ElseIf语句,不准悬空,平铺式else if
|
||||
WhileStmt, // while语句
|
||||
};
|
||||
struct AstNode
|
||||
{
|
||||
|
||||
@@ -16,9 +16,17 @@ namespace Fig
|
||||
{
|
||||
String name;
|
||||
|
||||
// Analyzer槽位,存储具体深度
|
||||
int resolvedDepth = -1; // 代表未解析
|
||||
bool isGlobal = false; // 是否全局/对外公开 (isPublic)
|
||||
// Analyzer槽位
|
||||
|
||||
// 寻址空间
|
||||
bool isGlobal = false; // 是否全局, 全局变量存哈希/堆
|
||||
|
||||
// 仅 isGlobal = false 有效
|
||||
int resolvedDepth = -1; // 用于获取闭包上值, -1 代表未解析
|
||||
|
||||
// 栈内槽位
|
||||
int localId = -1; // 局部变量id, -1 未解析
|
||||
|
||||
|
||||
IdentiExpr()
|
||||
{
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace Fig
|
||||
bool isInfer; // 是否用了 := 类型推断
|
||||
Expr *initExpr;
|
||||
|
||||
int localId = -1;
|
||||
|
||||
VarDecl()
|
||||
{
|
||||
type = AstType::VarDecl;
|
||||
|
||||
37
src/Ast/Stmt/WhileStmt.hpp
Normal file
37
src/Ast/Stmt/WhileStmt.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/*!
|
||||
@file src/Ast/Stmt/WhileStmt.hpp
|
||||
@brief WhileStmt定义
|
||||
@author PuqiAR (im@puqiar.top)
|
||||
@date 2026-02-24
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Ast/Base.hpp>
|
||||
|
||||
namespace Fig
|
||||
{
|
||||
struct WhileStmt final : public Stmt
|
||||
{
|
||||
Expr *cond;
|
||||
BlockStmt *body;
|
||||
|
||||
WhileStmt()
|
||||
{
|
||||
type = AstType::WhileStmt;
|
||||
}
|
||||
|
||||
WhileStmt(Expr *_cond, BlockStmt *_body, SourceLocation _location) :
|
||||
cond(_cond),
|
||||
body(_body)
|
||||
{
|
||||
type = AstType::WhileStmt;
|
||||
location = std::move(_location);
|
||||
}
|
||||
|
||||
virtual String toString() const override
|
||||
{
|
||||
return std::format("<WhileStmt ({}) {{{}}}>", cond->toString(), body->toString());
|
||||
}
|
||||
};
|
||||
}; // namespace Fig
|
||||
Reference in New Issue
Block a user