336e58578c10a4a039c9f80f521baa81ee48f1ad
[dragonfly.git] / lib / libevtr / ktrfmt.l
1 %{
2
3 #include <assert.h>
4 //#define YYSTYPE struct token
5 #include "ktrfmt.tab.h"
6 #include "tok.h"
7 #include "internal.h"
8
9 enum {
10         NR_TOKENS = 8,
11 };
12
13 static struct token tokens[NR_TOKENS];
14 static int curr_tok;
15
16 struct token *
17 tok_new(void)
18 {
19         ++curr_tok;
20         if (curr_tok == NR_TOKENS) {
21                 /* can't happen */
22                 fprintf(stderr, "Reached max number of tokens\n");
23                 exit(2);
24         }
25         return &tokens[curr_tok];
26 }
27
28 void
29 tok_free(struct token *tok)
30 {
31         assert(&tokens[curr_tok] == tok);
32         free(tok->str);
33         --curr_tok;
34 }
35
36 %}
37
38 %option prefix="__ktrfmt"
39 %option outfile="ktrfmt.yy.c"
40 %option bison-bridge
41 %option noyywrap
42 %option nounput
43
44 INT     [0-9]+
45 WHITE   [ \t\r]
46 ID      [a-zA-Z_$][a-zA-Z0-9_]*
47
48 %%
49 {WHITE}+ { /* ignore */ }
50 {ID} {
51         yylval->tok = tok_new();
52         yylval->tok->type = TOK_ID;
53         printd(LEX, "tok %p TOK_ID %p:%s\n", yylval->tok, yytext, yytext);
54         yylval->tok->str = strdup(yytext);
55         return TOK_ID;
56         }
57 {INT} {
58         yylval->tok = tok_new();
59         yylval->tok->type = TOK_INT;
60         yylval->tok->str = strdup(yytext);
61         printd(LEX, "TOK_INT\n");
62         return TOK_INT;
63         }
64 "=" {
65         yylval = NULL;
66         printd(LEX, "TOK_EQ\n");
67         return TOK_EQ;
68         }
69 "[" {
70         yylval = NULL;
71         printd(LEX, "TOK_LEFT_BRACK\n");
72         return TOK_LEFT_BRACK;
73         }
74 "]" {
75         yylval = NULL;
76         printd(LEX, "TOK_RIGHT_BRACK\n");
77         return TOK_RIGHT_BRACK;
78         }
79
80 %%