X-Git-Url: https://git.llucax.com/z.facultad/75.42/calculadora.git/blobdiff_plain/536f6abd563c15019e14a1a0e573b21e909bd88b..0030baf01844749eb88b276c6e8ce417cdd6914d:/parser_equation.c?ds=inline diff --git a/parser_equation.c b/parser_equation.c index 479c9e7..abf55ce 100644 --- a/parser_equation.c +++ b/parser_equation.c @@ -16,29 +16,17 @@ #include "bool.h" #include "equation.h" +#include "equation_list.h" +#include "parser_common.h" #include "parseerror.h" #include "dllist.h" #include #include #include -bool is_space(char c) { - return (c == ' ') || (c == '\t'); -} +#include "memdebug_debugger.h" -bool is_number(char c) { - return ('0' < c) && (c < '9'); -} - -bool is_alpha(char c) { - return (c == '_') || (('a' < c) && (c < 'z')) || (('A' < c) && (c < 'Z')); -} - -bool is_alpha_num(c) { - return is_number(c) || is_alpha(c); -} - -#define PARSE_ERROR(str) ParseError_set_pos_message(error, str, i, c) +#define PARSE_ERROR(str) ParseError_set_pos_message(error, str, i + 1, c) bool parser_equation(const char* line, size_t len, DLList* equation_list, ParseError* error) { @@ -49,6 +37,7 @@ bool parser_equation(const char* line, size_t len, DLList* equation_list, char c; Equation* eq; for (i = 0; i < len; i++) { + c = line[i]; switch (state) { case SEARCH_VAR: /* Busca el comienzo de una variable. */ if (!is_space(c)) { @@ -73,6 +62,8 @@ bool parser_equation(const char* line, size_t len, DLList* equation_list, } else if (c == '=') { /* Es igual, empieza la expresión. */ state = EXP; + /* Calculo la longitud de la variable. */ + var_len = i - var_start; } else { /* es otra cosa */ PARSE_ERROR( "un espacio, una letra, un número o un igual");