diff --git a/ctype.c b/ctype.c index 151bb1c..c4bb557 100644 --- a/ctype.c +++ b/ctype.c @@ -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) diff --git a/ctype.h b/ctype.h index 0e3df0f..2d293ac 100644 --- a/ctype.h +++ b/ctype.h @@ -4,8 +4,8 @@ #include 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 diff --git a/enums.c b/enums.c index 4fdd8b5..70615f3 100644 --- a/enums.c +++ b/enums.c @@ -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; } diff --git a/enums.h b/enums.h index f3fc5cd..115374c 100644 --- a/enums.h +++ b/enums.h @@ -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, }; diff --git a/lexer.c b/lexer.c index 50a1808..a0a0c29 100644 --- a/lexer.c +++ b/lexer.c @@ -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(); diff --git a/parser.c b/parser.c index e517a80..1d2f7c1 100644 --- a/parser.c +++ b/parser.c @@ -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();