Commit | Line | Data |
---|---|---|
ac13d9d2 | 1 | %option noyywrap |
e80bea70 | 2 | %option nounput |
ac13d9d2 ML |
3 | %pointer |
4 | ||
5 | EOL \n | |
6 | SPACE [ \t\v\f] | |
7 | WS [ \t\v\n\f] | |
8 | DIGIT [0-9] | |
9 | LETTER [a-zA-Z_] | |
10 | OCTDIGIT [0-7] | |
11 | HEXDIGIT [a-fA-F0-9] | |
12 | EXPONENT [Ee][+-]?{DIGIT}+ | |
13 | FLOQUAL (f|F|l|L) | |
14 | INTQUAL (l|L|ll|LL|lL|Ll|u|U) | |
15 | ||
16 | %{ | |
17 | ||
18 | #include <stdio.h> | |
19 | #include <stdlib.h> | |
20 | #include <string.h> | |
e80bea70 | 21 | |
7e59d9d4 MD |
22 | int yylex(void); |
23 | ||
24 | int yyget_lineno (void); | |
25 | FILE *yyget_in (void); | |
26 | FILE *yyget_out (void); | |
27 | int yyget_leng (void); | |
28 | char *yyget_text (void); | |
29 | void yyset_lineno (int line_number); | |
30 | void yyset_in (FILE * in_str); | |
31 | void yyset_out (FILE * out_str); | |
32 | int yyget_debug (void); | |
33 | void yyset_debug (int bdebug); | |
34 | int yylex_destroy (void); | |
35 | ||
ac13d9d2 ML |
36 | int filter_snarfage = 0; |
37 | int print = 1; | |
38 | ||
39 | enum t_state { | |
40 | SKIP, | |
41 | MULTILINE, | |
42 | MULTILINE_COOKIE, | |
62024674 | 43 | COOKIE |
ac13d9d2 ML |
44 | }; |
45 | ||
46 | enum t_state state = SKIP; | |
47 | int cookie_was_last = 0; | |
48 | ||
49 | #define OUT_RAW(type,text) if (print) printf ("(%s . \"%s\")\n", #type, text) | |
50 | ||
51 | #define OUT_T(type) OUT_RAW (type, yytext) | |
52 | #define OUT_S if (print) printf ("%s\n", yytext) | |
53 | #define OUT(type) if (print) printf ("%s\n", #type) | |
54 | ||
55 | #define IS_COOKIE cookie_was_last = 1 | |
56 | #define IS_NOT_COOKIE cookie_was_last = 0 | |
57 | ||
58 | %} | |
59 | ||
60 | %% | |
61 | ||
62 | \/\*(\n|[^*]|\*[^/])*\*\/ { OUT_T (comment); } | |
63 | ||
64 | ({SPACE}*(\\\n)*{SPACE}*)+ ; | |
65 | ||
66 | ({SPACE}*\n*{SPACE}*)+ { OUT(eol); } | |
67 | ||
6d7c6cf4 | 68 | #.*\n { OUT(hash); IS_NOT_COOKIE; } |
ac13d9d2 ML |
69 | |
70 | {LETTER}({LETTER}|{DIGIT})* { OUT_T (id); IS_NOT_COOKIE; } | |
71 | ||
72 | 0[xX]{HEXDIGIT}+{INTQUAL}? { OUT_RAW (int_hex, yytext + 2); IS_NOT_COOKIE; } | |
73 | 0{OCTDIGIT}+{INTQUAL}? { OUT_RAW (int_oct, yytext + 1); IS_NOT_COOKIE; } | |
74 | {DIGIT}+{INTQUAL}? { OUT_T (int_dec); IS_NOT_COOKIE; } | |
75 | ||
76 | L?\'(\\.|[^\\\'])+\' { OUT_T (char); IS_NOT_COOKIE; } | |
77 | ||
78 | {DIGIT}+{EXPONENT}{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; } | |
79 | {DIGIT}*"."{DIGIT}+({EXPONENT})?{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; } | |
80 | {DIGIT}+"."{DIGIT}*({EXPONENT})?{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; } | |
81 | ||
82 | L?\"(\\.|[^\\\"])*\" { OUT_S; IS_NOT_COOKIE; } | |
83 | ||
84 | "..." { OUT (ellipsis); IS_NOT_COOKIE; } | |
85 | ||
86 | ">>=" { OUT (shift_right_assign); IS_NOT_COOKIE; } | |
87 | "<<=" { OUT (shift_left_assign); IS_NOT_COOKIE; } | |
88 | "+=" { OUT (add_assign); IS_NOT_COOKIE; } | |
89 | "-=" { OUT (sub_assign); IS_NOT_COOKIE; } | |
90 | "*=" { OUT (mul-assign); IS_NOT_COOKIE; } | |
91 | "/=" { OUT (div_assign); IS_NOT_COOKIE; } | |
92 | "%=" { OUT (mod_assign); IS_NOT_COOKIE; } | |
93 | "&=" { OUT (logand_assign); IS_NOT_COOKIE; } | |
94 | "^=" { OUT (logxor_assign); IS_NOT_COOKIE; } | |
95 | "|=" { OUT (logior_assign); IS_NOT_COOKIE; } | |
96 | ">>" { OUT (right_shift); IS_NOT_COOKIE; } | |
97 | "<<" { OUT (left_shift); IS_NOT_COOKIE; } | |
98 | "++" { OUT (inc); IS_NOT_COOKIE; } | |
99 | "--" { OUT (dec); IS_NOT_COOKIE; } | |
100 | "->" { OUT (ptr); IS_NOT_COOKIE; } | |
101 | "&&" { OUT (and); IS_NOT_COOKIE; } | |
102 | "||" { OUT (or); IS_NOT_COOKIE; } | |
103 | "<=" { OUT (le); IS_NOT_COOKIE; } | |
104 | ">=" { OUT (ge); IS_NOT_COOKIE; } | |
105 | "==" { OUT (eq); IS_NOT_COOKIE; } | |
106 | "!=" { OUT (ne); IS_NOT_COOKIE; } | |
107 | ";" { OUT (semicolon); IS_NOT_COOKIE; } | |
108 | ||
109 | ("{"|"<%") { | |
110 | OUT (brace_open); | |
111 | if (filter_snarfage && cookie_was_last && state == COOKIE) | |
112 | state = MULTILINE; | |
113 | IS_NOT_COOKIE; } | |
114 | ||
115 | ("}"|"%>") { | |
116 | OUT (brace_close); | |
117 | if (filter_snarfage && cookie_was_last && state == MULTILINE_COOKIE) { | |
118 | state = SKIP; | |
119 | print = 0; | |
120 | } | |
121 | IS_NOT_COOKIE; } | |
122 | ||
123 | "," { OUT (comma); IS_NOT_COOKIE; } | |
124 | ":" { OUT (colon); IS_NOT_COOKIE; } | |
125 | "=" { OUT (assign); IS_NOT_COOKIE; } | |
126 | "(" { OUT (paren_open); IS_NOT_COOKIE; } | |
127 | ")" { OUT (paren_close); IS_NOT_COOKIE; } | |
128 | ("["|"<:") { OUT (bracket_open); IS_NOT_COOKIE; } | |
129 | ("]"|":>") { OUT (bracket_close); IS_NOT_COOKIE; } | |
130 | "." { OUT (dot); IS_NOT_COOKIE; } | |
131 | "&" { OUT (amp); IS_NOT_COOKIE; } | |
132 | "!" { OUT (bang); IS_NOT_COOKIE; } | |
133 | "~" { OUT (tilde); IS_NOT_COOKIE; } | |
134 | "-" { OUT (minus); IS_NOT_COOKIE; } | |
135 | "+" { OUT (plus); IS_NOT_COOKIE; } | |
136 | "*" { OUT (star); IS_NOT_COOKIE; } | |
137 | "/" { OUT (slash); IS_NOT_COOKIE; } | |
138 | "%" { OUT (percent); IS_NOT_COOKIE; } | |
139 | "<" { OUT (lt); IS_NOT_COOKIE; } | |
140 | ">" { OUT (gt); IS_NOT_COOKIE; } | |
141 | ||
142 | \^{WS}*\^ { | |
143 | if (filter_snarfage) | |
144 | switch (state) { | |
145 | case SKIP: | |
146 | state = COOKIE; | |
147 | print = 1; | |
148 | OUT (snarf_cookie); | |
149 | break; | |
150 | case MULTILINE: | |
151 | case MULTILINE_COOKIE: | |
152 | state = MULTILINE_COOKIE; | |
153 | OUT (snarf_cookie); | |
154 | break; | |
155 | case COOKIE: | |
156 | state = SKIP; | |
157 | OUT (snarf_cookie); | |
158 | print = 0; | |
159 | break; | |
160 | default: | |
161 | /* whoops */ | |
162 | abort (); | |
163 | break; | |
164 | } | |
165 | else | |
166 | OUT (snarf_cookie); | |
167 | ||
168 | IS_COOKIE; } | |
169 | ||
170 | "^" { OUT (caret); IS_NOT_COOKIE; } | |
171 | "|" { OUT (pipe); IS_NOT_COOKIE; } | |
172 | "?" { OUT (question); IS_NOT_COOKIE; } | |
173 | ||
174 | . { fprintf (stderr, "*%s", yytext); fflush (stderr); IS_NOT_COOKIE; } | |
175 | ||
176 | %% | |
177 | ||
178 | int | |
179 | main (int argc, char *argv[]) | |
180 | { | |
181 | if (argc > 1 && !strcmp (argv[1], "--filter-snarfage")) { | |
182 | filter_snarfage = 1; | |
183 | print = 0; | |
184 | } | |
185 | ||
186 | yylex (); | |
187 | ||
188 | return EXIT_SUCCESS; | |
189 | } | |
190 | ||
191 | /* | |
192 | Local Variables: | |
193 | c-file-style: "gnu" | |
194 | End: | |
195 | */ |