adding utils with enum_print
This commit is contained in:
59
src/utils/print_enums.c
Normal file
59
src/utils/print_enums.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/* print_enums.c */
|
||||
|
||||
#include "computorv1.h"
|
||||
|
||||
const char *token_type_to_str(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_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(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(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(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];
|
||||
}
|
||||
Reference in New Issue
Block a user