1
0
Fork 0
lesson-lisp/enums.c

54 lines
1.4 KiB
C

#include "enums.h"
#include <stdbool.h>
#include <stddef.h>
const char *State_to_str(const enum State state)
{
switch (state) {
case STATE_INIT: return "STATE_INIT";
case STATE_WHITESPACE: return "STATE_WHITESPACE";
case STATE_OPEN: return "STATE_OPEN";
case STATE_CLOSE: return "STATE_CLOSE";
case STATE_ATOM: return "STATE_ATOM";
case STATE_NUM: return "STATE_NUM";
}
return NULL;
}
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";
case TOKEN_ATOM: return "TOKEN_ATOM";
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) {
case STATE_OPEN: *token_type = TOKEN_OPEN; break;
case STATE_CLOSE: *token_type = TOKEN_CLOSE; break;
case STATE_ATOM: *token_type = TOKEN_ATOM; break;
case STATE_NUM: *token_type = TOKEN_NUM; break;
default: return false;
}
return true;
}