#include #include "include/tokenizer.hpp" #include "include/syntax_tree.hpp" #include "include/parser.hpp" const SyntaxTree *Parser::parse(const std::string &input) { tokens = tokenizer.tokenize(input); current_token = tokens[0]; return nullptr; } void Parser::parseExpression() { parseTerm(); parsePrimeExpression(); } void Parser::parsePrimeExpression() { if(current_token->type == nil) return; if(current_token->type == sum || current_token->type == substraction) { ++current_token; parseExpression(); } } void Parser::parseTerm() { parseFactor(); parsePrimeTerm(); } void Parser::parsePrimeTerm() { if(current_token->type == nil) return; if(current_token->type == multiplication || current_token->value == division) { ++current_token; parseTerm(); } } void Parser::parseFactor() { switch(current_token->type) { case substraction: ++current_token; parseExpression(); break; case left_parens: ++current_token; parseExpression(); if(current_token->type != right_parens) return; ++current_token; break; case operand: ++current_token; break; default: return; } }