functions very basic functionality added

This commit is contained in:
2021-07-16 10:07:16 +02:00
parent 24d4fb2567
commit 3e913263fc
4 changed files with 145 additions and 135 deletions

View File

@@ -141,21 +141,19 @@ std::unique_ptr<Node> Parser::parse_value() {
return std::make_unique<FloatValueNode>(std::stof(lexer.consumeCurrentToken().token_string));
}
if (lexer.tokenType() == TokenType::string_literal) {
if (lexer.nextTokenType() != TokenType::open_paren) {
return std::make_unique<StringValueNode>(lexer.consumeCurrentToken().token_string);
} else {
// function
std::string func_name = lexer.consumeCurrentToken().token_string;
std::vector<std::unique_ptr<Node>> pars;
return std::make_unique<StringValueNode>(lexer.consumeCurrentToken().token_string);
}
if (lexer.tokenType() == TokenType::identifier) {
std::string func_name = lexer.consumeCurrentToken().token_string;
std::vector<std::unique_ptr<Node>> pars;
lexer.skipToken(TokenType::open_paren);
while (lexer.tokenType() != TokenType::close_paren) { // TODO handle errors
auto par = parse_value();
lexer.skipTokenOptional(TokenType::comma);
}
lexer.skipToken(TokenType::close_paren);
return std::make_unique<FunctionNode>(func_name, std::move(pars));
lexer.skipToken(TokenType::open_paren);
while (lexer.tokenType() != TokenType::close_paren) { // TODO handle errors
pars.push_back(parse_value());
lexer.skipTokenOptional(TokenType::comma);
}
lexer.skipToken(TokenType::close_paren);
return std::make_unique<FunctionNode>(func_name, std::move(pars));
}
throw Exception("Syntax error");
}