|
@@ -28,11 +28,11 @@ static char peek(lexer_t *lexer);
|
|
|
static char eat(lexer_t *lexer);
|
|
|
static void emit_token(lexer_t *lexer, tokentype type);
|
|
|
static tokentype get_keyword(lexer_t *lexer);
|
|
|
-static bool is_int(char c);
|
|
|
+static bool is_number(char c);
|
|
|
static bool is_ident(char c);
|
|
|
static bool is_whitespace(char c);
|
|
|
static void read_string(lexer_t *lexer, char id);
|
|
|
-static void read_int(lexer_t *lexer);
|
|
|
+static void read_number(lexer_t *lexer);
|
|
|
static void read_ident(lexer_t *lexer);
|
|
|
static void read_comment(lexer_t *lexer);
|
|
|
|
|
@@ -216,8 +216,8 @@ lexer_t *lex(char *target_file, char *source)
|
|
|
default:
|
|
|
if (is_ident(c)) {
|
|
|
read_ident(lexer);
|
|
|
- } else if (is_int(c)) {
|
|
|
- read_int(lexer);
|
|
|
+ } else if (is_number(c)) {
|
|
|
+ read_number(lexer);
|
|
|
} else {
|
|
|
emit_token(lexer, TOKEN_ERROR);
|
|
|
file_fatal_error("erroneous token '%c' on line %zu\n",
|
|
@@ -292,9 +292,9 @@ static tokentype get_keyword(lexer_t *lexer)
|
|
|
return TOKEN_IDENT;
|
|
|
}
|
|
|
|
|
|
-static bool is_int(char c)
|
|
|
+static bool is_number(char c)
|
|
|
{
|
|
|
- return c >= '0' && c <= '9';
|
|
|
+ return (c >= '0' && c <= '9') || c == '.';
|
|
|
}
|
|
|
|
|
|
static bool is_ident(char c)
|
|
@@ -321,9 +321,9 @@ static void read_string(lexer_t *lexer, char id)
|
|
|
emit_token(lexer, TOKEN_STRING);
|
|
|
}
|
|
|
|
|
|
-static void read_int(lexer_t *lexer)
|
|
|
+static void read_number(lexer_t *lexer)
|
|
|
{
|
|
|
- while (is_int(peek(lexer)))
|
|
|
+ while (is_number(peek(lexer)))
|
|
|
eat(lexer);
|
|
|
|
|
|
emit_token(lexer, TOKEN_NUMBER);
|
|
@@ -331,7 +331,7 @@ static void read_int(lexer_t *lexer)
|
|
|
|
|
|
static void read_ident(lexer_t *lexer)
|
|
|
{
|
|
|
- while (is_ident(peek(lexer)) || is_int(peek(lexer)))
|
|
|
+ while (is_ident(peek(lexer)) || is_number(peek(lexer)))
|
|
|
eat(lexer);
|
|
|
|
|
|
emit_token(lexer, get_keyword(lexer));
|
|
@@ -339,13 +339,19 @@ static void read_ident(lexer_t *lexer)
|
|
|
|
|
|
static void read_comment(lexer_t *lexer)
|
|
|
{
|
|
|
+ size_t start_line = lexer->line_n;
|
|
|
+
|
|
|
while (1) {
|
|
|
+ if (peek(lexer) == EOF)
|
|
|
+ file_fatal_error("unterminated comment on line %d\n", start_line);
|
|
|
+
|
|
|
if (peek(lexer) == '\n')
|
|
|
++lexer->line_n;
|
|
|
|
|
|
if (eat(lexer) == '*' && peek(lexer) == ')') {
|
|
|
eat(lexer);
|
|
|
- verbose_printf("skipped comment\n");
|
|
|
+ verbose_printf("skipped comment on line %zu\n",
|
|
|
+ start_line);
|
|
|
break;
|
|
|
}
|
|
|
}
|