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