renamed enum and struct

This commit is contained in:
hugogogo
2026-05-03 23:06:04 +02:00
parent 6648161d9a
commit 3420923557
7 changed files with 71 additions and 46 deletions

View File

@@ -12,7 +12,7 @@
* LEXER.C
*/
typedef enum t_token_type
typedef enum
{
TOKEN_VARIABLE, // x, y, etc.
TOKEN_NUMBER_INT, // int
@@ -24,63 +24,76 @@ typedef enum t_token_type
TOKEN_FACTOR_DIV, // / or :
TOKEN_EQUAL, // =
TOKEN_END // null (end of input)
} token_type;
} e_token_type;
typedef enum t_token_tag
typedef enum
{
TOKEN_NO_TAG,
TOKEN_NUMBER,
TOKEN_SIGN,
TOKEN_FACTOR,
} token_tag;
} e_token_tag;
typedef struct
{
token_type type;
token_tag tag;
e_token_type type;
e_token_tag tag;
union
{
char value_char;
int value_int;
double value_double;
};
} token;
} s_token;
int lexerize(const char *input, token *tokens);
int lexerize(const char *input, s_token *tokens);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* PARSER.C
*/
typedef enum t_term_position
typedef enum
{
TERM_LEFT, // a in "a = b"
TERM_RIGHT, // b in "a = b"
TERM_END, // last term
} term_position;
} e_term_position;
typedef enum t_term_sign
typedef enum
{
TERM_PLUS, // +
TERM_MINUS, // -
TERM_NULL, // null -> for the last term
} term_sign;
} e_term_sign;
typedef struct t_term
typedef struct
{
term_position position;
term_sign sign;
e_term_position position;
e_term_sign sign;
double coefficient;
int exponent;
} term;
} s_term;
int parse(token *tokens, term *terms, int terms_count_max);
int parse(s_token *tokens, s_term *terms, int terms_count_max);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* REDUCE.C
*/
typedef struct
{
double a;
double b;
double c;
} s_polynom;
void reduce(s_term *terms, s_polynom *polynom);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* UTILS/ERRORS.C
*/
typedef enum t_program_error
typedef enum
{
ERROR_BASE = 1, // start at 1 to avoid exit(0) for errors
ERROR_TOKEN_COUNT,
@@ -91,26 +104,27 @@ typedef enum t_program_error
ERROR_TOKEN_POSITION,
ERROR_VAR_DIFF,
ERROR_SENTINEL, // last token not used, only for enum count
} program_error;
} e_program_error;
void print_state();
int stop_errors(program_error err, const char *format, ...);
int stop_errors(e_program_error err, const char *format, ...);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* UTILS/PRINT_ENUMS.C
*/
const char *token_type_to_str(token_type type);
const char *token_tag_to_str(token_tag tag);
const char *term_position_to_str(term_position pos);
const char *term_sign_to_str(term_sign sign);
const char *token_type_to_str(e_token_type type);
const char *token_tag_to_str(e_token_tag tag);
const char *term_position_to_str(e_term_position pos);
const char *term_sign_to_str(e_term_sign sign);
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* GLOBALS
*/
extern char *input_g_err;
extern token *tokens_g_err;
extern term *terms_g_err;
extern s_token *tokens_g_err;
extern s_term *terms_g_err;
extern s_term *polynom_g_err;
#endif