|
@@ -17,12 +17,16 @@ struct lexer lexer_create(struct str in);
|
|
|
void lexer_read_char(struct lexer *l);
|
|
void lexer_read_char(struct lexer *l);
|
|
|
|
|
|
|
|
struct token lexer_next_token(struct lexer *l);
|
|
struct token lexer_next_token(struct lexer *l);
|
|
|
|
|
+
|
|
|
struct str lexer_read_ident(struct lexer *l);
|
|
struct str lexer_read_ident(struct lexer *l);
|
|
|
struct str lexer_read_str_lit(struct lexer *l);
|
|
struct str lexer_read_str_lit(struct lexer *l);
|
|
|
|
|
+struct str lexer_read_int_lit(struct lexer *l);
|
|
|
|
|
+
|
|
|
enum token_type_enum lexer_lookup_ident(struct str ident);
|
|
enum token_type_enum lexer_lookup_ident(struct str ident);
|
|
|
void lexer_skip_whitespace(struct lexer *l);
|
|
void lexer_skip_whitespace(struct lexer *l);
|
|
|
|
|
|
|
|
bool _lexer_is_letter(char c);
|
|
bool _lexer_is_letter(char c);
|
|
|
|
|
+bool _lexer_is_number(char c);
|
|
|
|
|
|
|
|
#if defined(IMP) || defined(LEXER_IMP)
|
|
#if defined(IMP) || defined(LEXER_IMP)
|
|
|
|
|
|
|
@@ -82,6 +86,9 @@ lexer_next_token(struct lexer *l)
|
|
|
t = token_create(lexer_lookup_ident(ident), ident);
|
|
t = token_create(lexer_lookup_ident(ident), ident);
|
|
|
return t;
|
|
return t;
|
|
|
}
|
|
}
|
|
|
|
|
+ if ( _lexer_is_number(l->c) ) {
|
|
|
|
|
+ return token_create(TT_INT_LIT, lexer_read_int_lit(l));
|
|
|
|
|
+ }
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -114,6 +121,17 @@ lexer_read_str_lit(struct lexer *l)
|
|
|
return str_slice(l->in, pos+1, l->pos-1);
|
|
return str_slice(l->in, pos+1, l->pos-1);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+struct str
|
|
|
|
|
+lexer_read_int_lit(struct lexer *l)
|
|
|
|
|
+{
|
|
|
|
|
+ size_t pos = l->pos;
|
|
|
|
|
+ while ( _lexer_is_number(l->c) ) {
|
|
|
|
|
+ lexer_read_char(l);
|
|
|
|
|
+ }
|
|
|
|
|
+ return str_slice(l->in, pos, l->pos);
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
enum token_type_enum
|
|
enum token_type_enum
|
|
|
lexer_lookup_ident(struct str ident)
|
|
lexer_lookup_ident(struct str ident)
|
|
|
{
|
|
{
|
|
@@ -173,6 +191,12 @@ _lexer_is_letter(char c)
|
|
|
|| c == 0x5F;
|
|
|| c == 0x5F;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+bool
|
|
|
|
|
+_lexer_is_number(char c)
|
|
|
|
|
+{
|
|
|
|
|
+ return ( c >= '0' && c <= '9' );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
#endif /* defined(IMP) || defined(LEXER_IMP) */
|
|
#endif /* defined(IMP) || defined(LEXER_IMP) */
|
|
|
|
|
|
|
|
#endif /* LEXER_H */
|
|
#endif /* LEXER_H */
|