summaryrefslogtreecommitdiff
path: root/tools/d2c/rules/tokens.l
diff options
context:
space:
mode:
Diffstat (limited to 'tools/d2c/rules/tokens.l')
-rw-r--r--tools/d2c/rules/tokens.l57
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/d2c/rules/tokens.l b/tools/d2c/rules/tokens.l
new file mode 100644
index 0000000..36d6c4a
--- /dev/null
+++ b/tools/d2c/rules/tokens.l
@@ -0,0 +1,57 @@
+
+%top {
+
+#include "grammar.h"
+
+}
+
+
+%option noyywrap
+%option nounput
+%option noinput
+%option yylineno
+%option stack
+%option noyy_top_state
+
+%x cond
+%x cond_binval
+%x cond_hexval
+%x action
+%x raw_line
+
+
+%%
+
+
+\/\/[^\n]+ { printf("SKIP '%s'\n", yytext); }
+
+"if" { yy_push_state(cond); return IF; }
+<cond>[ ]+ { }
+<cond>"(" { return EXPR_START; }
+<cond>[A-Za-z_][A-Za-z0-9_]* { yylvalp->string = strdup(yytext); return NAME; }
+<cond>"==" { return EQUAL; }
+<cond>"'" { yy_push_state(cond_binval); }
+<cond_binval>[01][01]* { yylvalp->string = strdup(yytext); return BINVAL; }
+<cond_binval>"'" { yy_pop_state(); }
+<cond>"0x" { yy_push_state(cond_hexval); }
+<cond_hexval>[0-9a-f][0-9a-f]* { yylvalp->string = strdup(yytext); yy_pop_state(); return HEXVAL; }
+<cond>")" { return EXPR_END; }
+<cond>"&&" { return AND; }
+<cond>"&" { return AND_LOG; }
+
+<cond>";" { yy_pop_state(); return THEN; }
+
+[ ] { }
+
+"see " { yy_push_state(raw_line); return SEE; }
+
+"unpredictable" { return UNPREDICTABLE; }
+
+"call" { yy_push_state(raw_line); return CALL; }
+"chk_call" { yy_push_state(raw_line); return CHK_CALL; }
+
+<raw_line>[^\n]+ { yylvalp->cstring = yytext; return RAW_LINE; }
+<raw_line>"\n" { yy_pop_state(); }
+
+
+%%