From: Sebastian Harl Date: Wed, 30 Jul 2014 09:44:06 +0000 (+0200) Subject: frontend/scanner: Simplified handling of reserved words. X-Git-Tag: sysdb-0.3.0~10 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e831693a8da189279f98ab49a41bba77084bba49;p=sysdb.git frontend/scanner: Simplified handling of reserved words. --- diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l index f45fbe7..f70f60f 100644 --- a/src/frontend/scanner.l +++ b/src/frontend/scanner.l @@ -44,6 +44,21 @@ #define YY_EXTRA_TYPE sdb_fe_yyextra_t * +static struct { + const char *name; + int id; +} reserved_words[] = { + { "AND", AND }, + { "FETCH", FETCH }, + { "IS", IS }, + { "LIST", LIST }, + { "LOOKUP", LOOKUP }, + { "MATCHING", MATCHING }, + { "NOT", NOT }, + { "NULL", NULL_T }, + { "OR", OR }, +}; + void sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); @@ -109,25 +124,10 @@ float ({float1}|{float2}|{float3}|{float4}|{float5}) } {identifier} { - /* XXX: simplify handling of reserved words */ - if (! strcasecmp(yytext, "AND")) - return AND; - else if (! strcasecmp(yytext, "FETCH")) - return FETCH; - else if (! strcasecmp(yytext, "IS")) - return IS; - else if (! strcasecmp(yytext, "LIST")) - return LIST; - else if (! strcasecmp(yytext, "LOOKUP")) - return LOOKUP; - else if (! strcasecmp(yytext, "MATCHING")) - return MATCHING; - else if (! strcasecmp(yytext, "NOT")) - return NOT; - else if (! strcasecmp(yytext, "NULL")) - return NULL_T; - else if (! strcasecmp(yytext, "OR")) - return OR; + size_t i; + for (i = 0; i < SDB_STATIC_ARRAY_LEN(reserved_words); ++i) + if (! strcasecmp(reserved_words[i].name, yytext)) + return reserved_words[i].id; yylval->str = strdup(yytext); return IDENTIFIER;