Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed many bugs in Parser related functions. #130

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions prototype/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1857,13 +1859,16 @@ VarDeclNode* Parser::ParseVarDecl(Token* token, size_t length, size_t& index) {
}
dynamic_cast<ArrayDeclNode*>(var_decl)->SetArrayDeclNode(type, name,
size);
break;
}
case Token::OperatorType::equal: {
std::cout<<"EQUAL RUN IN PVD FUNC"<<std::endl;
ExprNode* value = ParseExpr(token, length, ++index);
var_decl->SetVarDeclNode(type, name, value);
break;
}
default:
std::cout<<index;
std::cout << index;
std::cout << "END PVD FUNC E1" << std::endl;
return var_decl;
}
Expand Down Expand Up @@ -2072,10 +2077,8 @@ ExprNode* Parser::ParsePrimaryExpr(Token* token, size_t length, size_t& index) {
std::cout << "FN PPE FUNC" << std::endl;
std::vector<ExprNode*> 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 &&
Expand All @@ -2084,13 +2087,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);
Expand Down Expand Up @@ -2240,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"<<std::endl;
if (index >= length) return nullptr;
ExprNode* expr = ParsePrimaryExpr(token, length, index);
expr = ParseBinaryExpr(token, length, index, expr, 0);
std::cout<<"END PE FUNC"<<std::endl;
return expr;
}

Expand Down
Loading