1
0
Fork 0

Rename SYMBOL to IDENT

This commit is contained in:
Alex Kotov 2023-05-04 15:22:11 +04:00
parent 495408bed4
commit 53c92bcc2c
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
6 changed files with 19 additions and 19 deletions

View file

@ -13,7 +13,7 @@ bool is_space(char chr)
return isspace(chr);
}
bool is_symbol_head(char chr)
bool is_ident_head(char chr)
{
return isalpha(chr) ||
chr == '!' ||
@ -36,9 +36,9 @@ bool is_symbol_head(char chr)
chr == '~';
}
bool is_symbol_tail(char chr)
bool is_ident_tail(char chr)
{
return is_symbol_head(chr) || isdigit(chr);
return is_ident_head(chr) || isdigit(chr);
}
bool is_number(char chr)

View file

@ -4,8 +4,8 @@
#include <stdbool.h>
bool is_space(char chr);
bool is_symbol_head(char chr);
bool is_symbol_tail(char chr);
bool is_ident_head(char chr);
bool is_ident_tail(char chr);
bool is_number(char chr);
#endif

View file

@ -14,7 +14,7 @@ const char *State_to_str(const enum State state)
case STATE_SQUARE_CLOSE: return "STATE_SQUARE_CLOSE";
case STATE_CURLY_OPEN: return "STATE_CURLY_OPEN";
case STATE_CURLY_CLOSE: return "STATE_CURLY_CLOSE";
case STATE_SYMBOL: return "STATE_SYMBOL";
case STATE_IDENT: return "STATE_IDENT";
case STATE_NUM: return "STATE_NUM";
}
return NULL;
@ -29,7 +29,7 @@ const char *TokenType_to_str(const enum TokenType token_type)
case TOKEN_SQUARE_CLOSE: return "TOKEN_SQUARE_CLOSE";
case TOKEN_CURLY_OPEN: return "TOKEN_CURLY_OPEN";
case TOKEN_CURLY_CLOSE: return "TOKEN_CURLY_CLOSE";
case TOKEN_SYMBOL: return "TOKEN_SYMBOL";
case TOKEN_IDENT: return "TOKEN_IDENT";
case TOKEN_NUM: return "TOKEN_NUM";
}
return NULL;
@ -56,7 +56,7 @@ State_to_token_type(const enum State state, enum TokenType *const token_type)
case STATE_SQUARE_CLOSE: *token_type = TOKEN_SQUARE_CLOSE; break;
case STATE_CURLY_OPEN: *token_type = TOKEN_CURLY_OPEN; break;
case STATE_CURLY_CLOSE: *token_type = TOKEN_CURLY_CLOSE; break;
case STATE_SYMBOL: *token_type = TOKEN_SYMBOL; break;
case STATE_IDENT: *token_type = TOKEN_IDENT; break;
case STATE_NUM: *token_type = TOKEN_NUM; break;
default: return false;
}

View file

@ -12,7 +12,7 @@ enum State {
STATE_SQUARE_CLOSE,
STATE_CURLY_OPEN,
STATE_CURLY_CLOSE,
STATE_SYMBOL,
STATE_IDENT,
STATE_NUM,
};
@ -23,7 +23,7 @@ enum TokenType {
TOKEN_SQUARE_CLOSE,
TOKEN_CURLY_OPEN,
TOKEN_CURLY_CLOSE,
TOKEN_SYMBOL,
TOKEN_IDENT,
TOKEN_NUM,
};

16
lexer.c
View file

@ -62,8 +62,8 @@ void lex(const char chr)
} else if (is_space(chr)) {
state = STATE_WHITESPACE;
buffer_add(chr);
} else if (is_symbol_head(chr)) {
state = STATE_SYMBOL;
} else if (is_ident_head(chr)) {
state = STATE_IDENT;
buffer_add(chr);
} else if (is_number(chr)) {
state = STATE_NUM;
@ -105,10 +105,10 @@ void lex(const char chr)
buffer_add(chr);
} else if (is_space(chr)) {
buffer_add(chr);
} else if (is_symbol_head(chr)) {
} else if (is_ident_head(chr)) {
token_add(state, buffer);
buffer_clean();
state = STATE_SYMBOL;
state = STATE_IDENT;
buffer[buffer_index++] = chr;
} else if (is_number(chr)) {
token_add(state, buffer);
@ -160,10 +160,10 @@ void lex(const char chr)
buffer_clean();
state = STATE_WHITESPACE;
buffer_add(chr);
} else if (is_symbol_head(chr)) {
} else if (is_ident_head(chr)) {
token_add(state, buffer);
buffer_clean();
state = STATE_SYMBOL;
state = STATE_IDENT;
buffer_add(chr);
} else if (is_number(chr)) {
token_add(state, buffer);
@ -174,7 +174,7 @@ void lex(const char chr)
abort();
}
break;
case STATE_SYMBOL:
case STATE_IDENT:
if (chr == '(') {
token_add(state, buffer);
buffer_clean();
@ -210,7 +210,7 @@ void lex(const char chr)
buffer_clean();
state = STATE_WHITESPACE;
buffer_add(chr);
} else if (is_symbol_tail(chr)) {
} else if (is_ident_tail(chr)) {
buffer_add(chr);
} else {
abort();

View file

@ -33,7 +33,7 @@ struct Object *expr()
case TOKEN_SQUARE_OPEN:
case TOKEN_CURLY_OPEN:
return parens();
case TOKEN_SYMBOL:
case TOKEN_IDENT:
{
struct Object *const object = Object_new_symbol(tokens_top()->val);
tokens_pop();