From 48876482f6c732014c9ec0cf7c707b72af4e0829 Mon Sep 17 00:00:00 2001 From: Lixuanwang Date: Thu, 6 Mar 2025 04:06:19 +0800 Subject: [PATCH] bug report and example fix for issue1 --- src/ASTPrinter.cpp | 5 ++++- test/bug1.sy | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/bug1.sy diff --git a/src/ASTPrinter.cpp b/src/ASTPrinter.cpp index f5adbcc..60d78af 100644 --- a/src/ASTPrinter.cpp +++ b/src/ASTPrinter.cpp @@ -227,7 +227,10 @@ std::any ASTPrinter::visitUnaryExp(SysYParser::UnaryExpContext *ctx){ cout << ctx->Ident()->getText() << ctx->LPAREN()->getText(); if(ctx->funcRParams()) ctx->funcRParams()->accept(this); - cout << ctx->RPAREN()->getText(); + if (ctx->RPAREN()) + cout << ctx->RPAREN()->getText(); + else + cout << ""; } else if(ctx->unaryExp()){ cout << ctx->unaryOp()->getText(); diff --git a/test/bug1.sy b/test/bug1.sy new file mode 100644 index 0000000..c7dcb0c --- /dev/null +++ b/test/bug1.sy @@ -0,0 +1,7 @@ +// bug1: getint(; + +int main() { + int a; + a = getint(; + return 0; +} \ No newline at end of file