]>
Commit | Line | Data |
---|---|---|
ffc11f03 CP |
1 | %option noyywrap |
2 | ||
3 | %{ | |
4 | #include "y.tab.h" | |
5 | #include <string.h> | |
6 | ||
7 | #define YYSTYPE char * | |
8 | extern YYSTYPE yylval; | |
9 | ||
10 | #include <stdlib.h> | |
11 | #include "../lib/stringbuf.h" | |
12 | ||
13 | #define MAX_STR_CONST 512 | |
14 | %} | |
15 | ||
16 | digit [0-9] | |
17 | letter [a-zA-Z] | |
18 | ||
19 | %x str | |
20 | %% | |
21 | ||
22 | char bufdata[MAX_STR_CONST]; | |
23 | StringBuf buf; | |
24 | ||
25 | \" { | |
26 | sbinit(&buf, bufdata, sizeof(bufdata)); | |
27 | BEGIN(str); | |
28 | } | |
29 | ||
30 | <str>{ | |
31 | \" { | |
32 | BEGIN(INITIAL); | |
33 | sbterminate(&buf); | |
34 | yylval = strdup(bufdata); | |
35 | return STRING; | |
36 | } | |
37 | \\\\ { sbaddchar(&buf, '\\'); } | |
38 | \\\" { sbaddchar(&buf, '"'); } | |
39 | [^\\] { sbaddchar(&buf, *yytext); } | |
40 | } | |
41 | ||
42 | "(" { return LPAREN; } | |
43 | ")" { return RPAREN; } | |
44 | [ \t]+ { return WHITESPACE; } | |
45 | {letter}+ { | |
46 | yylval = strdup(yytext); | |
47 | return IDENTIFIER; | |
48 | } | |
49 | ||
50 | [\n\r] /* ignore */; | |
51 | ||
52 | <<EOF>> { | |
53 | BEGIN(INITIAL); | |
54 | yyterminate(); | |
55 | } | |
56 | %% |