From e05a919af1d5e1a5e43159b379820cc207f017c7 Mon Sep 17 00:00:00 2001 From: Xie Zicong Date: Thu, 21 Nov 2024 22:22:54 +0800 Subject: [PATCH 1/2] Fixed a small bug in Parser::ParsePrimaryExpr function. --- prototype/compiler.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/prototype/compiler.cc b/prototype/compiler.cc index 1881513..1274846 100644 --- a/prototype/compiler.cc +++ b/prototype/compiler.cc @@ -1863,7 +1863,7 @@ VarDeclNode* Parser::ParseVarDecl(Token* token, size_t length, size_t& index) { var_decl->SetVarDeclNode(type, name, value); } default: - std::cout< args; index++; - while (index < length && - - token[index].value._operator != - Token::OperatorType::r_paren) { + while (index < length && token[index].value._operator != + Token::OperatorType::r_paren) { std::cout << "ARG PPE FUNC" << std::endl; args.push_back(ParseVarDecl(token, length, index)); if (token[index].type == Token::Type::OPERATOR && @@ -2084,13 +2082,13 @@ ExprNode* Parser::ParsePrimaryExpr(Token* token, size_t length, size_t& index) { } else if (token[index].type == Token::Type::OPERATOR && token[index].value._operator == Token::OperatorType::r_paren) { - index++; break; } else { state = State::kEnd; break; } } + index++; FuncNode* func_node = new FuncNode(); std::cout << "NFN PPE FUNC" << std::endl; func_node->SetFuncNode(main_expr, args); From b0935cd60b46a834d4cd6001d293e17bea251a93 Mon Sep 17 00:00:00 2001 From: Xie Zicong Date: Thu, 21 Nov 2024 22:30:10 +0800 Subject: [PATCH 2/2] Fixed some small bugs in Parser::ParseExpr and Parser::ParseVarDecl functions. --- prototype/compiler.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/prototype/compiler.cc b/prototype/compiler.cc index 1274846..b4619d4 100644 --- a/prototype/compiler.cc +++ b/prototype/compiler.cc @@ -1824,6 +1824,8 @@ VarDeclNode* Parser::ParseVarDecl(Token* token, size_t length, size_t& index) { return var_decl; std::cout << "END PVD FUNC E5" << std::endl; } + if (token[index].value._operator == Token::OperatorType::equal) + std::cout << "IS = " << std::endl; switch (token[index].value._operator) { case Token::OperatorType::l_square: { ExprNode* size = ParseExpr(token, length, ++index); @@ -1857,10 +1859,13 @@ VarDeclNode* Parser::ParseVarDecl(Token* token, size_t length, size_t& index) { } dynamic_cast(var_decl)->SetArrayDeclNode(type, name, size); + break; } case Token::OperatorType::equal: { + std::cout<<"EQUAL RUN IN PVD FUNC"<SetVarDeclNode(type, name, value); + break; } default: std::cout << index; @@ -2238,9 +2243,11 @@ ExprNode* Parser::ParsePrimaryExpr(Token* token, size_t length, size_t& index) { } ExprNode* Parser::ParseExpr(Token* token, size_t length, size_t& index) { - if (length >= index) return nullptr; + std::cout<<"START PE FUNC"<= length) return nullptr; ExprNode* expr = ParsePrimaryExpr(token, length, index); expr = ParseBinaryExpr(token, length, index, expr, 0); + std::cout<<"END PE FUNC"<