frame finished but bad_any_cast

This commit is contained in:
Downright
2025-03-24 19:06:49 +08:00
parent a36f73c8a2
commit 7f364abffb
4 changed files with 759 additions and 117 deletions

View File

@@ -124,7 +124,7 @@ std::any ASTPrinter::visitFuncFParam(SysYParser::FuncFParamContext *ctx){
}
std::any ASTPrinter::visitBlockStmt(SysYParser::BlockStmtContext *ctx){
cout << ' ' << ctx->LBRACE()->getText() << endl;
cout << ctx->LBRACE()->getText() << endl;
indentLevel++;
for (auto item : ctx->blockItem()) item->accept(this);
indentLevel--;
@@ -134,6 +134,7 @@ std::any ASTPrinter::visitBlockStmt(SysYParser::BlockStmtContext *ctx){
// std::any ASTPrinter::visitBlockItem(SysYParser::BlockItemContext *ctx);
std::any ASTPrinter::visitAssignStmt(SysYParser::AssignStmtContext *ctx){
cout << getIndent();
ctx->lValue()->accept(this);
cout << ' ' << ctx->ASSIGN()->getText() << ' ';
ctx->exp()->accept(this);
@@ -142,6 +143,7 @@ std::any ASTPrinter::visitAssignStmt(SysYParser::AssignStmtContext *ctx){
}
std::any ASTPrinter::visitExpStmt(SysYParser::ExpStmtContext *ctx){
cout << getIndent();
if (ctx->exp()) {
ctx->exp()->accept(this);
}
@@ -153,7 +155,17 @@ std::any ASTPrinter::visitIfStmt(SysYParser::IfStmtContext *ctx){
cout << getIndent() << ctx->IF()->getText() << ' ' << ctx->LPAREN()->getText();
ctx->cond()->accept(this);
cout << ctx->RPAREN()->getText() << ' ';
ctx->stmt(0)->accept(this);
//格式化有问题
if(ctx->stmt(0)) {
ctx->stmt(0)->accept(this);
}
else {
cout << '{' << endl;
indentLevel++;
ctx->stmt(0)->accept(this);
indentLevel--;
cout << getIndent() << '}' << endl;
}
if (ctx->ELSE()) {
cout << getIndent() << ctx->ELSE()->getText() << ' ';
ctx->stmt(1)->accept(this);