feat(09): start the parsing of the input

This commit is contained in:
Raphael 2025-04-27 15:50:50 +02:00
parent 65bc1c35f1
commit bf81e18e76
3 changed files with 54 additions and 11 deletions

View file

@ -6,7 +6,7 @@
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
# Updated: 2025/04/27 13:00:00 by rparodi ### ########.fr #
# Updated: 2025/04/27 13:01:07 by rparodi ### ########.fr #
# #
# **************************************************************************** #
@ -56,14 +56,6 @@ END = \033[0m
# All (make all)
all: header $(NAME) footer
get_db:
@rm -rf ./cpp_09.tgz ./cpp_09 ./data.csv &> /dev/null
@wget https://cdn.intra.42.fr/document/document/33121/cpp_09.tgz &> /dev/null
@tar -xvf cpp_09.tgz &> /dev/null
@cp ./cpp_09/data.csv . &> /dev/null
@rm -rf ./cpp_09.tgz ./cpp_09 &> /dev/null
@printf '$(GREY)Downloaded $(END)$(GREEN)data.csv$(END)\n'
# Clean (make clean)
clean:
@printf '$(GREY) Removing $(END)$(RED)Objects$(END)\n'

View file

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* RPN.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/27 13:03:08 by rparodi #+# #+# */
/* Updated: 2025/04/27 15:39:50 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
#pragma once
#define CLR_RESET "\033[0m"
#define CLR_BLACK "\033[0;30m"
#define CLR_RED "\033[0;31m"
#define CLR_GREEN "\033[0;32m"
#define CLR_YELLOW "\033[0;33m"
#define CLR_BLUE "\033[0;34m"
#define CLR_MAGENTA "\033[0;35m"
#define CLR_CYAN "\033[0;36m"
#define CLR_WHITE "\033[0;37m"
#define CLR_GOLD "\033[38;5;220m"
#define CLR_GREY "\033[38;5;240m"

View file

@ -6,10 +6,35 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/04/27 12:58:08 by rparodi #+# #+# */
/* Updated: 2025/04/27 13:00:01 by rparodi ### ########.fr */
/* Updated: 2025/04/27 15:50:20 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
int main(int argc, char **argv) {
#include <iostream>
#include <stack>
#include "RPN.hpp"
/**
* @brief check if the input have only numbers and operators
*
* @param str the input of the user
* @return true if the input is valid, false otherwise
*/
bool check_input(std::string str) {
std::string allowed = "0123456789 +-*/";
for (std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
if (allowed.find(*it) == std::string::npos)
return false;
}
return true;
}
int main(int argc, char **argv) {
if (argc != 2) {
std::cerr << CLR_RED << "Usage:\t" << argv[0] << " <string>" << CLR_RESET << std::endl;
}
std::string input = argv[1];
if (!check_input(input)) {
std::cerr << CLR_RED << "Error:\tYour input can only have digits, spaces and the operators '+' '-' '*' '/'" << CLR_RESET << std::endl;
}
}