eolian: preliminary number constant stuff in eo_lexer

This commit is contained in:
Daniel Kolesa 2014-07-16 16:18:13 +01:00
parent c636882158
commit 80165034ed
2 changed files with 32 additions and 8 deletions

View File

@ -44,7 +44,7 @@ next_char(Eo_Lexer *ls)
static const char * const tokens[] = static const char * const tokens[] =
{ {
"<comment>", "<value>", "<comment>", "<number>", "<value>",
KEYWORDS KEYWORDS
}; };
@ -104,9 +104,9 @@ init_hash(void)
unsigned int i; unsigned int i;
if (keyword_map) return; if (keyword_map) return;
keyword_map = eina_hash_string_superfast_new(NULL); keyword_map = eina_hash_string_superfast_new(NULL);
for (i = 2; i < (sizeof(tokens) / sizeof(const char*)); ++i) for (i = 3; i < (sizeof(tokens) / sizeof(const char*)); ++i)
{ {
eina_hash_add(keyword_map, tokens[i], (void*)(size_t)(i - 1)); eina_hash_add(keyword_map, tokens[i], (void*)(size_t)(i - 2));
} }
} }
@ -437,7 +437,7 @@ eo_lexer_token_to_str(int token, char *buf)
const char * const char *
eo_lexer_keyword_str_get(int kw) eo_lexer_keyword_str_get(int kw)
{ {
return tokens[kw + 1]; return tokens[kw + 2];
} }
Eina_Bool Eina_Bool

View File

@ -13,7 +13,7 @@
enum Tokens enum Tokens
{ {
TOK_COMMENT = START_CUSTOM, TOK_VALUE TOK_COMMENT = START_CUSTOM, TOK_NUMBER, TOK_VALUE
}; };
/* all keywords in eolian, they can still be used as names (they're TOK_VALUE) /* all keywords in eolian, they can still be used as names (they're TOK_VALUE)
@ -59,14 +59,38 @@ enum Keywords
#undef KW #undef KW
#undef KWAT #undef KWAT
enum Numbers
{
NUM_INT,
NUM_UINT,
NUM_LONG,
NUM_ULONG,
NUM_LLONG,
NUM_ULLONG,
NUM_FLOAT,
NUM_DOUBLE,
NUM_LDOUBLE
};
/* a token - "token" is the actual token id, "value" is the value of a token /* a token - "token" is the actual token id, "value" is the value of a token
* if needed - NULL otherwise - for example the value of a TOK_VALUE, "kw" * if needed - NULL otherwise - for example the value of a TOK_VALUE, "kw"
* is the keyword id if this is a keyword, it's 0 when not a keyword */ * is the keyword id if this is a keyword, it's 0 when not a keyword */
typedef struct _Eo_Token typedef struct _Eo_Token
{ {
int token; int token, kw;
const char *value; union
int kw; {
const char *value;
signed int value_i;
unsigned int value_u;
signed long value_l;
unsigned long value_ul;
signed long long value_ll;
unsigned long long value_ull;
float value_f;
double value_d;
long double value_ld;
};
} Eo_Token; } Eo_Token;
enum Nodes enum Nodes