11 #define TK_PlusPlus 262
12 #define TK_MinusMinus 263
13 #define TK_ArrowStar 264
14 #define TK_DotStar 265
15 #define TK_ShiftLeft 266
16 #define TK_ShiftRight 267
17 #define TK_IntegerDecimal 268
18 #define TK_IntegerOctal 269
19 #define TK_IntegerHex 270
20 #define TK_EqualsEquals 271
21 #define TK_NotEquals 272
24 #define TK_MultAssign 275
25 #define TK_DivAssign 276
26 #define TK_PercentAssign 277
27 #define TK_PlusAssign 278
28 #define TK_MinusAssign 279
29 #define TK_AmpAssign 280
30 #define TK_CaretAssign 281
31 #define TK_BarAssign 282
32 #define TK_DotDotDot 283
33 #define TK_Whitespace 284
34 #define TK_Comment 285
36 int line = 1, col = 1;
38 void token( int tok, char *data, int len )
40 printf( "<%i> ", tok );
41 for ( int i = 0; i < len; i++ )
42 fputc( data[i], stdout );
43 fputc( '\n', stdout );
45 /* Count newlines and columns. This code is here mainly for having some
46 * code in the token routine when commenting out the above output during
47 * performance testing. */
48 for ( int i = 0; i < len; i ++ ) {
49 if ( data[i] == '\n' ) {
64 printf("fill(%i)\n", n);
70 char *start, *p = buf, *lim = buf, *marker;
71 int len, have, want, shift;
78 #define YYMARKER marker
83 if ( start > buf ) { \
85 memmove( buf, start, have ); \
91 want = BUFSIZE - have - 1; \
92 len = fread( lim, 1, want, stdin ); \
107 FRACTCONST = ( [0-9]* "." [0-9]+ ) | [0-9]+ ".";
108 EXPONENT = [eE] [+\-]? [0-9]+;
109 FLOATSUFFIX = [flFL];
111 "L"? "\'" ( ANY \ [\'\\\n] | "\\" ANY )* "\'" {
112 token( TK_Slit, start, p-start );
116 "L"? "\"" ( ANY \ [\"\\\n] | "\\" ANY )* "\"" {
117 token( TK_Dlit, start, p-start );
121 [a-zA-Z_][a-zA-Z0-9_]* {
122 token( TK_Id, start, p-start );
126 ( FRACTCONST EXPONENT? FLOATSUFFIX? ) | ( [0-9]+ EXPONENT FLOATSUFFIX? ) {
127 token( TK_Float, start, p-start );
132 ( "0" | [1-9][0-9]* ) [ulUL]* {
133 token( TK_IntegerDecimal, start, p-start );
138 token( TK_IntegerOctal, start, p-start );
142 "0x" [0-9a-fA-F]+[ulUL]* {
143 token( TK_IntegerHex, start, p-start );
147 "::" { token( TK_NameSep, start, p-start ); goto again; }
148 "==" { token( TK_EqualsEquals, start, p-start ); goto again; }
149 "!=" { token( TK_NotEquals, start, p-start ); goto again; }
150 "&&" { token( TK_AndAnd, start, p-start ); goto again; }
151 "||" { token( TK_OrOr, start, p-start ); goto again; }
152 "*=" { token( TK_MultAssign, start, p-start ); goto again; }
153 "/=" { token( TK_DivAssign, start, p-start ); goto again; }
154 "%=" { token( TK_PercentAssign, start, p-start ); goto again; }
155 "+=" { token( TK_PlusAssign, start, p-start ); goto again; }
156 "-=" { token( TK_MinusAssign, start, p-start ); goto again; }
157 "&=" { token( TK_AmpAssign, start, p-start ); goto again; }
158 "^=" { token( TK_CaretAssign, start, p-start ); goto again; }
159 "|=" { token( TK_BarAssign, start, p-start ); goto again; }
160 "++" { token( TK_PlusPlus, start, p-start ); goto again; }
161 "--" { token( TK_MinusMinus, start, p-start ); goto again; }
162 "->" { token( TK_Arrow, start, p-start ); goto again; }
163 "->*" { token( TK_ArrowStar, start, p-start ); goto again; }
164 ".*" { token( TK_DotStar, start, p-start ); goto again; }
165 "..." { token( TK_DotDotDot, start, p-start ); goto again; }
167 "/*" { goto comment; }
168 "//" (ANY\"\n")* "\n" { goto again; }
169 [\001-\040\177]+ { goto again; }
171 [\041-\057\072-\100\133-\140\173-\176] {
172 token( *start, start, p-start );
181 ANY { goto comment; }