Files
42_EXT_05_computorv1/src/utils/print_enums.c
2026-05-06 22:34:16 +02:00

72 lines
2.3 KiB
C

/* print_enums.c */
#include "computorv1.h"
const char *token_type_to_str(e_token_type enum_value)
{
if (enum_value > TOKEN_END || enum_value < TOKEN_VARIABLE)
return "invalid enum value";
static const char *const token_type_str[TOKEN_END + 1] = {
[TOKEN_VARIABLE] = "TOKEN_VARIABLE",
[TOKEN_NUMBER_INT] = "TOKEN_NUMBER_INT",
[TOKEN_NUMBER_DOUBLE] = "TOKEN_NUMBER_DOUBLE",
[TOKEN_NUMBER_INT_SUPER] = "TOKEN_NUMBER_INT_SUPER",
[TOKEN_POWER] = "TOKEN_POWER",
[TOKEN_SIGN_PLUS] = "TOKEN_SIGN_PLUS",
[TOKEN_SIGN_MINUS] = "TOKEN_SIGN_MINUS",
[TOKEN_FACTOR_MULT] = "TOKEN_FACTOR_MULT",
[TOKEN_FACTOR_DIV] = "TOKEN_FACTOR_DIV",
[TOKEN_EQUAL] = "TOKEN_EQUAL",
[TOKEN_END] = "TOKEN_END"};
return token_type_str[enum_value];
}
const char *token_tag_to_str(e_token_tag enum_value)
{
if (enum_value > TOKEN_FACTOR || enum_value < TOKEN_NO_TAG)
return "invalid enum value";
static const char *const token_tag_str[TOKEN_FACTOR + 1] = {
[TOKEN_NO_TAG] = "TOKEN_NO_TAG",
[TOKEN_NUMBER] = "TOKEN_NUMBER",
[TOKEN_SIGN] = "TOKEN_SIGN",
[TOKEN_FACTOR] = "TOKEN_FACTOR"};
return token_tag_str[enum_value];
}
const char *term_position_to_str(e_term_position enum_value)
{
if (enum_value > TERM_END || enum_value < TERM_LEFT)
return "invalid enum value";
static const char *const term_position_str[TERM_END + 1] = {
[TERM_LEFT] = "TERM_LEFT",
[TERM_RIGHT] = "TERM_RIGHT",
[TERM_END] = "TERM_END"};
return term_position_str[enum_value];
}
const char *term_sign_to_str(e_term_sign enum_value)
{
if (enum_value > TERM_NULL || enum_value < TERM_PLUS)
return "invalid enum value";
static const char *const term_sign_str[TERM_NULL + 1] = {
[TERM_PLUS] = "TERM_PLUS",
[TERM_MINUS] = "TERM_MINUS",
[TERM_NULL] = "TERM_NULL"};
return term_sign_str[enum_value];
}
const char *delta_sign_to_str(e_delta_sign enum_value)
{
if (enum_value > DELTA_ZERO || enum_value < DELTA_PLUS)
return "invalid enum value";
static const char *const delta_sign_str[DELTA_ZERO + 1] = {
[DELTA_PLUS] = "DELTA_PLUS",
[DELTA_MINUS] = "DELTA_MINUS",
[DELTA_ZERO] = "DELTA_ZERO"};
return delta_sign_str[enum_value];
}