1
0
Fork 0
lesson-lisp/enums.c

54 lines
1.4 KiB
C
Raw Normal View History

2023-05-03 21:28:58 +00:00
#include "enums.h"
2023-05-03 21:41:04 +00:00
#include <stdbool.h>
2023-05-03 21:28:58 +00:00
#include <stddef.h>
2023-05-03 21:41:04 +00:00
const char *State_to_str(const enum State state)
2023-05-03 21:28:58 +00:00
{
switch (state) {
2023-05-03 21:41:04 +00:00
case STATE_INIT: return "STATE_INIT";
2023-05-03 21:28:58 +00:00
case STATE_WHITESPACE: return "STATE_WHITESPACE";
2023-05-03 21:41:04 +00:00
case STATE_OPEN: return "STATE_OPEN";
case STATE_CLOSE: return "STATE_CLOSE";
2023-05-03 22:31:11 +00:00
case STATE_ATOM: return "STATE_ATOM";
2023-05-03 21:41:04 +00:00
case STATE_NUM: return "STATE_NUM";
2023-05-03 21:28:58 +00:00
}
return NULL;
}
2023-05-03 21:41:04 +00:00
const char *TokenType_to_str(const enum TokenType token_type)
{
switch (token_type) {
case TOKEN_OPEN: return "TOKEN_OPEN";
case TOKEN_CLOSE: return "TOKEN_CLOSE";
2023-05-03 22:31:11 +00:00
case TOKEN_ATOM: return "TOKEN_ATOM";
2023-05-03 21:41:04 +00:00
case TOKEN_NUM: return "TOKEN_NUM";
}
return NULL;
}
const char *Type_to_str(const enum Type type)
{
switch (type) {
case TYPE_PAIR: return "TYPE_PAIR";
case TYPE_ATOM: return "TYPE_ATOM";
case TYPE_STRING: return "TYPE_STRING";
case TYPE_NUMBER: return "TYPE_NUMBER";
}
return NULL;
}
bool
State_to_token_type(const enum State state, enum TokenType *const token_type)
{
switch (state) {
2023-05-03 22:05:11 +00:00
case STATE_OPEN: *token_type = TOKEN_OPEN; break;
case STATE_CLOSE: *token_type = TOKEN_CLOSE; break;
2023-05-03 22:31:11 +00:00
case STATE_ATOM: *token_type = TOKEN_ATOM; break;
2023-05-03 22:05:11 +00:00
case STATE_NUM: *token_type = TOKEN_NUM; break;
2023-05-03 21:41:04 +00:00
default: return false;
}
return true;
}