2 /* Include <config.h> before anything else because Gnulib headers such
3 as <stdio.h> rely on it.
5 However, when cross-compiling, don't include <config.h> because it
6 contains information about the host, not about the build. */
7 #ifndef CROSS_COMPILING
23 EXPONENT [Ee][+-]?{DIGIT}+
25 INTQUAL (l|L|ll|LL|lL|Ll|u|U)
32 /* Prevent compilation of static input() function in generated scanner
33 code. This function is never actually used, and GCC 4.3 will emit
37 int filter_snarfage = 0;
47 enum t_state state = SKIP;
48 int cookie_was_last = 0;
50 #define OUT_RAW(type,text) if (print) printf ("(%s . \"%s\")\n", #type, text)
52 #define OUT_T(type) OUT_RAW (type, yytext)
53 #define OUT_S if (print) printf ("%s\n", yytext)
54 #define OUT(type) if (print) printf ("%s\n", #type)
56 #define IS_COOKIE cookie_was_last = 1
57 #define IS_NOT_COOKIE cookie_was_last = 0
63 \/\*(\n|[^*]|\*[^/])*\*\/ { OUT_T (comment); }
65 ({SPACE}*(\\\n)*{SPACE}*)+ ;
67 ({SPACE}*\n*{SPACE}*)+ { OUT(eol); }
69 #.*\n { OUT(hash); IS_NOT_COOKIE; }
71 {LETTER}({LETTER}|{DIGIT})* { OUT_T (id); IS_NOT_COOKIE; }
73 0[xX]{HEXDIGIT}+{INTQUAL}? { OUT_RAW (int_hex, yytext + 2); IS_NOT_COOKIE; }
74 0{OCTDIGIT}+{INTQUAL}? { OUT_RAW (int_oct, yytext + 1); IS_NOT_COOKIE; }
75 {DIGIT}+{INTQUAL}? { OUT_T (int_dec); IS_NOT_COOKIE; }
77 L?\'(\\.|[^\\\'])+\' { OUT_T (char); IS_NOT_COOKIE; }
79 {DIGIT}+{EXPONENT}{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
80 {DIGIT}*"."{DIGIT}+({EXPONENT})?{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
81 {DIGIT}+"."{DIGIT}*({EXPONENT})?{FLOQUAL}? { OUT_T (flo_dec); IS_NOT_COOKIE; }
83 L?\"(\\.|[^\\\"])*\" { OUT_S; IS_NOT_COOKIE; }
85 "..." { OUT (ellipsis); IS_NOT_COOKIE; }
87 ">>=" { OUT (shift_right_assign); IS_NOT_COOKIE; }
88 "<<=" { OUT (shift_left_assign); IS_NOT_COOKIE; }
89 "+=" { OUT (add_assign); IS_NOT_COOKIE; }
90 "-=" { OUT (sub_assign); IS_NOT_COOKIE; }
91 "*=" { OUT (mul-assign); IS_NOT_COOKIE; }
92 "/=" { OUT (div_assign); IS_NOT_COOKIE; }
93 "%=" { OUT (mod_assign); IS_NOT_COOKIE; }
94 "&=" { OUT (logand_assign); IS_NOT_COOKIE; }
95 "^=" { OUT (logxor_assign); IS_NOT_COOKIE; }
96 "|=" { OUT (logior_assign); IS_NOT_COOKIE; }
97 ">>" { OUT (right_shift); IS_NOT_COOKIE; }
98 "<<" { OUT (left_shift); IS_NOT_COOKIE; }
99 "++" { OUT (inc); IS_NOT_COOKIE; }
100 "--" { OUT (dec); IS_NOT_COOKIE; }
101 "->" { OUT (ptr); IS_NOT_COOKIE; }
102 "&&" { OUT (and); IS_NOT_COOKIE; }
103 "||" { OUT (or); IS_NOT_COOKIE; }
104 "<=" { OUT (le); IS_NOT_COOKIE; }
105 ">=" { OUT (ge); IS_NOT_COOKIE; }
106 "==" { OUT (eq); IS_NOT_COOKIE; }
107 "!=" { OUT (ne); IS_NOT_COOKIE; }
108 ";" { OUT (semicolon); IS_NOT_COOKIE; }
112 if (filter_snarfage && cookie_was_last && state == COOKIE)
118 if (filter_snarfage && cookie_was_last && state == MULTILINE_COOKIE) {
124 "," { OUT (comma); IS_NOT_COOKIE; }
125 ":" { OUT (colon); IS_NOT_COOKIE; }
126 "=" { OUT (assign); IS_NOT_COOKIE; }
127 "(" { OUT (paren_open); IS_NOT_COOKIE; }
128 ")" { OUT (paren_close); IS_NOT_COOKIE; }
129 ("["|"<:") { OUT (bracket_open); IS_NOT_COOKIE; }
130 ("]"|":>") { OUT (bracket_close); IS_NOT_COOKIE; }
131 "." { OUT (dot); IS_NOT_COOKIE; }
132 "&" { OUT (amp); IS_NOT_COOKIE; }
133 "!" { OUT (bang); IS_NOT_COOKIE; }
134 "~" { OUT (tilde); IS_NOT_COOKIE; }
135 "-" { OUT (minus); IS_NOT_COOKIE; }
136 "+" { OUT (plus); IS_NOT_COOKIE; }
137 "*" { OUT (star); IS_NOT_COOKIE; }
138 "/" { OUT (slash); IS_NOT_COOKIE; }
139 "%" { OUT (percent); IS_NOT_COOKIE; }
140 "<" { OUT (lt); IS_NOT_COOKIE; }
141 ">" { OUT (gt); IS_NOT_COOKIE; }
152 case MULTILINE_COOKIE:
153 state = MULTILINE_COOKIE;
171 "^" { OUT (caret); IS_NOT_COOKIE; }
172 "|" { OUT (pipe); IS_NOT_COOKIE; }
173 "?" { OUT (question); IS_NOT_COOKIE; }
175 . { fprintf (stderr, "*%s", yytext); fflush (stderr); IS_NOT_COOKIE; }
180 main (int argc, char *argv[])
182 if (argc > 1 && !strcmp (argv[1], "--filter-snarfage")) {