680197aafe
- 更新了 ParserTest,以改进文件路径处理和输出格式。 - 在 StmtParser 中新增了 parseConstDecl 和 parseForStmt 方法,用于处理常量声明和 for 循环。 - TypeExpr现归类为Expr。TypeExpr属于Expr,语义阶段视为Expr - 添加了新的 AST 节点:PostfixExpr、TernaryExpr、ForStmt 和 ImportStmt,用于表示新的语法结构。
38 lines
823 B
C++
38 lines
823 B
C++
/*!
|
|
@file src/Parser/Parser.cpp
|
|
@brief 语法分析器实现
|
|
@author PuqiAR (im@puqiar.top)
|
|
@date 2026-03-08
|
|
*/
|
|
|
|
#include <Parser/Parser.hpp>
|
|
|
|
namespace Fig
|
|
{
|
|
Result<Program *, Error> Parser::Parse()
|
|
{
|
|
Program *program = arena.Allocate<Program>();
|
|
|
|
while (currentToken().type != TokenType::EndOfFile)
|
|
{
|
|
if (lexerError)
|
|
{
|
|
return std::unexpected(*lexerError);
|
|
}
|
|
auto result = parseStatement();
|
|
if (!result)
|
|
{
|
|
return std::unexpected(result.error());
|
|
}
|
|
|
|
Stmt *stmt = *result;
|
|
if (stmt)
|
|
{
|
|
program->nodes.push_back(stmt);
|
|
}
|
|
}
|
|
|
|
return program;
|
|
}
|
|
}; // namespace Fig
|