#ifndef LEXER_H #define LEXER_H #include "libft.h" #include "errors.h" #include /** * PROPOSITION 1 */ // typedef enum // { // TOKEN_VARIABLE, // x, y, etc. // TOKEN_NUMBER, // int or double // TOKEN_POWER, // ^ or ** // TOKEN_SIGN, // + or - // TOKEN_FACTOR, // * or / or : // TOKEN_EQUAL, // = // TOKEN_END // null (end of input) // } token_type; // // typedef enum // { // TOKEN_NUMBER_INT, // int // TOKEN_NUMBER_DOUBLE, // double // TOKEN_SIGN_ADD, // + // TOKEN_SIGN_MINUS, // - // TOKEN_FACTOR_MULTIPLICATION, // * // TOKEN_FACTOR_DIVISION, // / or : // } token_subtype; // // typedef struct // { // token_type type; // token_subtype subtype; // union // { // char value_char; // double value_double; // }; // } token; /** * PROPOSITION 2 */ // // TYPES and SUBTYPES // typedef enum // { // TOKEN_VARIABLE, // x, y, etc. // TOKEN_NUMBER, // int or double // TOKEN_POWER, // ^ or ** // TOKEN_SIGN, // + or - // TOKEN_FACTOR, // * or / or : // TOKEN_EQUAL, // = // TOKEN_END // null (end of input) // } token_type; // // typedef enum // { // NUMBER_INT, // NUMBER_DOUBLE // } number_subtype; // // typedef enum // { // SIGN_ADD, // + // SIGN_MINUS // - // } sign_subtype; // // typedef enum // { // FACTOR_MULTIPLICATION, // * // FACTOR_DIVISION, // / or : // } factor_subtype; // // // DATA // // typedef struct // { // char value; // e.g., 'x', 'y' // } token_variable; // // typedef struct // { // number_subtype subtype; // double value; // } token_number; // // typedef struct // { // sign_subtype subtype; // char value; // } token_sign; // // typedef struct // { // factor_subtype subtype; // char value; // } token_factor; // // typedef struct // { // char value; // } token_power; // // typedef struct // { // char value; // } token_equal; // // typedef struct // { // char value; // } token_end; // // // TOKEN // // typedef union // { // token_variable variable; // value // token_number number; // subtype [INT, DOUBLE], value // token_sign sign; // subtype [PLUS, MINUS], value // token_factor factor; // subtype [MULT, DIV], value // token_power power; // value // token_equal equal; // value // token_end end; // value // } token_data; // // typedef struct // { // token_type type; // token_data data; // } token; /** * PROPOSITION 3 */ // typedef enum // { // TOKEN_VARIABLE, // x, y, etc. // TOKEN_NUMBER, // int or double // TOKEN_POWER, // ^ or ** // TOKEN_SIGN, // + or - // TOKEN_FACTOR, // * or / or : // TOKEN_EQUAL, // = // TOKEN_END // null (end of input) // } token_type; // // typedef enum // { // TOKEN_NO_SUBTYPE, // // NUMBER // TOKEN_NUMBER_INT, // TOKEN_NUMBER_DOUBLE, // // SIGN // TOKEN_SIGN_PLUS, // TOKEN_SIGN_MINUS, // // FACTOR // TOKEN_FACTOR_MULTIPLICATION, // TOKEN_FACTOR_DIVISION, // } token_subtype; // // typedef struct // { // token_type type; // token_subtype subtype; // union // { // char value_char; // double value_double; // }; // } token; /** * PROPOSITION 4 */ 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); #endif