/* computorv1.h */ #ifndef COMPUTORV1_H #define COMPUTORV1_H #include "libft.h" #include // tmp for printf, for float debug #include // for va_list #include /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * LEXER.C */ typedef enum { TOKEN_VARIABLE, // x, y, etc. TOKEN_NUMBER_INT, // int TOKEN_NUMBER_DOUBLE, // double TOKEN_POWER, // ^ or ** TOKEN_SIGN_PLUS, // + TOKEN_SIGN_MINUS, // - TOKEN_FACTOR_MULT, // * TOKEN_FACTOR_DIV, // / or : TOKEN_EQUAL, // = TOKEN_END // null (end of input) } token_type; typedef enum { TOKEN_NO_TAG, TOKEN_NUMBER, TOKEN_SIGN, TOKEN_FACTOR, } token_tag; typedef struct { token_type type; token_tag tag; union { char value_char; double value_double; }; } token; int lexerize(const char *input, token *tokens); /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * PARSER.C */ typedef enum { TERM_LEFT, // a in "a = b" TERM_RIGHT, // b in "a = b" TERM_END, // last term } term_position; typedef enum { TERM_PLUS, // + TERM_MINUS, // - TERM_NULL, // null -> for the last term } term_sign; typedef struct { term_position position; term_sign sign; double coefficient; double exponent; } term; int parse(token *tokens, term *terms, int terms_count_max); /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ERRORS.C */ typedef enum { ERROR_BASE = 1, // start at 1 to avoid exit(0) for errors ERROR_TOKEN_COUNT, ERROR_UNKNOWN_TOKEN, ERROR_NUMBER_TOO_BIG, ERROR_PARSING, ERROR_TERM_COUNT, ERROR_TOKEN_POSITION, ERROR_VAR_DIFF, ERROR_SENTINEL, // last token not used, only for enum count } program_error; int stop_errors(program_error err, const char *format, ...); /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * GLOBALS */ extern char *input_g_err; extern token *tokens_g_err; #endif