diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2016-01-28 23:32:25 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2016-01-28 23:32:25 (GMT) |
commit | 16e0fd9d89ef433848678dfc8dd20426844a2868 (patch) | |
tree | 79075ae02c133cea21ffb555b1086aae833b3aac /tools/d2c/args/tokens.l | |
parent | 66c99d59d6a6d533de0bb65488de8243213bcdea (diff) |
Cleaned, rewritten and improved the whole code of the compiler.
Diffstat (limited to 'tools/d2c/args/tokens.l')
-rw-r--r-- | tools/d2c/args/tokens.l | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tools/d2c/args/tokens.l b/tools/d2c/args/tokens.l new file mode 100644 index 0000000..4b1a2a1 --- /dev/null +++ b/tools/d2c/args/tokens.l @@ -0,0 +1,67 @@ + +%top { + +#include "grammar.h" + +} + + +%option noyywrap +%option nounput +%option noinput +%option yylineno +%option stack +%option noyy_top_state + +%x binval +%x hexval + + +%% + + +%{ + + /* Choix d'un des démarrages multiples */ + if (*init_token != ALLOW_ALL) + { + unsigned int first; + first = *init_token; + *init_token = ALLOW_ALL; + return first; + } + +%} + + +[A-Za-z_][A-Za-z0-9_]* { + if (strcmp(yytext, "NOT") == 0) return NOT; + else if (strcmp(yytext, "AND") == 0) return AND_LOG; + else if (strcmp(yytext, "EOR") == 0) return EOR; + else + { + yylvalp->string = strdup(yytext); + return NAME; + } + } + +[0-9][0-9]* { yylvalp->integer = atoi(yytext); return NUMBER; } + +"'" { yy_push_state(binval); } +<binval>[01][01]* { yylvalp->string = strdup(yytext); return BINVAL; } +<binval>"'" { yy_pop_state(); } + +"0x" { yy_push_state(hexval); } +<hexval>[0-9a-f][0-9a-f]* { yylvalp->string = strdup(yytext); yy_pop_state(); return HEXVAL; } + +"," { return COMMA; } +":" { return COLON; } +"&" { return AND_LOG; } + +"(" { yy_push_state(INITIAL); return OP; } +")" { yy_pop_state(); return CP; } + +[ ]+ { } + + +%% |