X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Ffrontend%2Fscanner.l;h=f70f60f84dab33618a7ae84a67771ec33e0a022f;hb=e831693a8da189279f98ab49a41bba77084bba49;hp=ef30682b45b837f8cb931f1e7257f7568ddd3f2b;hpb=812d8a3d3bb4d41ac66294ee1652708b19502eb2;p=sysdb.git diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l index ef30682..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); @@ -75,10 +90,16 @@ csc_start \/\* csc_inside ([^*/]+|[^*]\/|\*[^/]) csc_end \*\/ +/* + * Strings and identifiers. + */ identifier ([A-Za-z_][A-Za-z_0-9$]*) /* TODO: fully support SQL strings */ string ('[^']*') +/* + * Numeric constants. + */ dec ([\+\-]?[0-9]+) exp ([\+\-]?[0-9]+[Ee]\+?[0-9]+) integer ({dec}|{exp}) @@ -103,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; @@ -150,6 +156,7 @@ float ({float1}|{float2}|{float3}|{float4}|{float5}) \<= { return CMP_LE; } \>= { return CMP_GE; } \> { return CMP_GT; } +\|\| { return CONCAT; } . { /* XXX: */ return yytext[0]; }