diff --git a/Makefile b/Makefile index d4653d2..373c1e8 100644 --- a/Makefile +++ b/Makefile @@ -36,11 +36,13 @@ D_LIB = ./libft D_HEADERS = ./headers HEADERS = computorv1.h \ errors.h \ - lexer.h + lexer.h \ + parser.h D_SRCS = ./src SRCS = computorv1.c \ errors.c \ - lexer.c + lexer.c \ + parser.c # COMPILATION CONFIG : CC = gcc @@ -95,7 +97,7 @@ $(NAME): $(OBJS) run: $(NAME) @echo $(YELLOW)"run"$(RESET) - @./$(NAME) "3 * x^2 + 1 * x^1 - 2 * x^0 = 5 * x^1" + @./$(NAME) "3.4 * x^2 + 1 * x^1 - 2 * x^0 = 5.123 * x^1" clean: $(RM_OBJS) diff --git a/headers/computorv1.h b/headers/computorv1.h index 91f70cc..ab29d7a 100644 --- a/headers/computorv1.h +++ b/headers/computorv1.h @@ -1,4 +1,10 @@ #ifndef COMPUTORV1_H #define COMPUTORV1_H +#include "libft.h" +#include "lexer.h" +#include "parser.h" +#include "errors.h" +#include // tmp for printf, for float debug + #endif \ No newline at end of file diff --git a/headers/lexer.h b/headers/lexer.h index 8402982..ae53511 100644 --- a/headers/lexer.h +++ b/headers/lexer.h @@ -1,6 +1,10 @@ #ifndef LEXER_H #define LEXER_H +#include "libft.h" +#include "errors.h" +#include + typedef enum { TOKEN_VARIABLE, // x, y, etc. @@ -24,6 +28,6 @@ typedef struct }; } token; -void lexerize(const char *input, token *tokens); +int lexerize(const char *input, token *tokens); #endif \ No newline at end of file diff --git a/headers/parser.h b/headers/parser.h new file mode 100644 index 0000000..bc0c36c --- /dev/null +++ b/headers/parser.h @@ -0,0 +1,27 @@ +#ifndef PARSER_H +#define PARSER_H + +#include "libft.h" +#include "lexer.h" +#include "errors.h" + +typedef enum +{ + TERM_LEFT, // a in "a = b" + TERM_RIGHT, // b in "a = b" +} term_type; + +typedef struct +{ + term_type type; + union + { + char value_char; + int value_int; + double value_double; + }; +} term; + +int parse(token *tokens, term *terms); + +#endif \ No newline at end of file diff --git a/src/computorv1.c b/src/computorv1.c index b425602..fd59c9e 100644 --- a/src/computorv1.c +++ b/src/computorv1.c @@ -1,8 +1,4 @@ #include "computorv1.h" -#include "libft.h" -#include "lexer.h" -#include "errors.h" -#include // tmp for float debug void remove_spaces(char *s) { @@ -63,7 +59,11 @@ int main(int ac, char **av) ft_putchar('\n'); // debug token tokens[arg_len]; - lexerize(input, tokens); + int token_count = lexerize(input, tokens); + + ft_putstr("-> token_count : "); // debug + ft_putnbr(token_count); // debug + ft_putchar('\n'); // debug // tmp debug output ft_putchar('\n'); // debug @@ -105,6 +105,15 @@ int main(int ac, char **av) } i++; } + ft_putchar('\n'); // debug + // END tmp debug output + + term terms[token_count / 2]; + int term_count = parse(tokens, terms); + + ft_putstr("-> term_count : "); // debug + ft_putnbr(term_count); // debug + ft_putchar('\n'); // debug return (0); } diff --git a/src/lexer.c b/src/lexer.c index 788f57c..f89d3cd 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1,7 +1,4 @@ #include "lexer.h" -#include "libft.h" -#include "errors.h" -#include // any single letter is a valid variable, like 'x' or 'y' static bool token_is_variable(const char *input, int input_pos, int *token_size) @@ -153,7 +150,7 @@ static bool token_is_equal(const char *input, int input_pos, int *token_size) /** * LEXER */ -void lexerize(const char *input, token *tokens) +int lexerize(const char *input, token *tokens) { int token_count; int input_pos; @@ -222,4 +219,6 @@ void lexerize(const char *input, token *tokens) tokens[token_count].type = TOKEN_END; tokens[token_count].value_char = '\0'; + + return token_count; } diff --git a/src/parser.c b/src/parser.c new file mode 100644 index 0000000..62eebbb --- /dev/null +++ b/src/parser.c @@ -0,0 +1,10 @@ +#include "parser.h" + +int parse(token *tokens, term *terms) +{ + if (tokens) + { + terms[0].type = 0; + } + return 1; +} \ No newline at end of file