added \' escape handling
[swftools.git] / lib / as3 / tokenizer.lex
1 /* tokenizer.lex
2
3    Routines for compiling Flash2 AVM2 ABC Actionscript
4
5    Extension module for the rfxswf library.
6    Part of the swftools package.
7
8    Copyright (c) 2008 Matthias Kramm <kramm@quiss.org>
9  
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
23 %{
24
25
26 #include <string.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include "../utf8.h"
31 #include "tokenizer.h"
32 #include "files.h"
33
34 static int verbose = 1;
35 static void dbg(const char*format, ...)
36 {
37     char buf[1024];
38     int l;
39     va_list arglist;
40     if(!verbose)
41         return;
42     va_start(arglist, format);
43     vsprintf(buf, format, arglist);
44     va_end(arglist);
45     l = strlen(buf);
46     while(l && buf[l-1]=='\n') {
47         buf[l-1] = 0;
48         l--;
49     }
50     printf("(tokenizer) ");
51     printf("%s\n", buf);
52     fflush(stdout);
53 }
54
55 void syntaxerror(const char*format, ...)
56 {
57     char buf[1024];
58     int l;
59     va_list arglist;
60     if(!verbose)
61         return;
62     va_start(arglist, format);
63     vsprintf(buf, format, arglist);
64     va_end(arglist);
65     fprintf(stderr, "%s:%d:%d: error: %s\n", current_filename_short, current_line, current_column, buf);
66     fflush(stderr);
67     exit(1);
68 }
69 void warning(const char*format, ...)
70 {
71     return;
72     char buf[1024];
73     int l;
74     va_list arglist;
75     if(!verbose)
76         return;
77     va_start(arglist, format);
78     vsprintf(buf, format, arglist);
79     va_end(arglist);
80     fprintf(stderr, "%s:%d:%d: warning: %s\n", current_filename_short, current_line, current_column, buf);
81     fflush(stderr);
82 }
83
84
85 #ifndef YY_CURRENT_BUFFER
86 #define YY_CURRENT_BUFFER yy_current_buffer
87 #endif
88
89 void handleInclude(char*text, int len, char quotes)
90 {
91     char*filename = 0;
92     if(quotes) {
93         char*p1 = strchr(text, '"');
94         char*p2 = strrchr(text, '"');
95         if(!p1 || !p2 || p1==p2) {
96             syntaxerror("Invalid include in line %d\n", current_line);
97         }
98         *p2 = 0;
99         filename = strdup(p1+1);
100     } else {
101         int i1=0,i2=len;
102         // find start
103         while(!strchr(" \n\r\t", text[i1])) i1++;
104         // strip
105         while(strchr(" \n\r\t", text[i1])) i1++;
106         while(strchr(" \n\r\t", text[i2-1])) i2--;
107         if(i2!=len) text[i2]=0;
108         filename = strdup(&text[i1]);
109     }
110     
111     char*fullfilename = enter_file(filename, YY_CURRENT_BUFFER);
112     yyin = fopen(fullfilename, "rb");
113     if (!yyin) {
114         syntaxerror("Couldn't open include file \"%s\"\n", fullfilename);
115     }
116
117     yy_switch_to_buffer(yy_create_buffer( yyin, YY_BUF_SIZE ) );
118     //BEGIN(INITIAL); keep context
119 }
120
121 static int do_unescape(const char*s, const char*end, char*n) 
122 {
123     char*o = n;
124     int len=0;
125     while(s<end) {
126         if(*s!='\\') {
127             if(o) o[len] = *s;len++;
128             s++;
129             continue;
130         }
131         s++; //skip past '\'
132         if(s==end) syntaxerror("invalid \\ at end of string");
133
134         /* handle the various line endings (mac, dos, unix) */
135         if(*s=='\r') { 
136             s++; 
137             if(s==end) break;
138             if(*s=='\n') 
139                 s++;
140             continue;
141         }
142         if(*s=='\n')  {
143             s++;
144             continue;
145         }
146         switch(*s) {
147             case '\\': if(o) o[len] = '\\';s++;len++; break;
148             case '"': if(o) o[len] = '"';s++;len++; break;
149             case '\'': if(o) o[len] = '\'';s++;len++; break;
150             case 'b': if(o) o[len] = '\b';s++;len++; break;
151             case 'f': if(o) o[len] = '\f';s++;len++; break;
152             case 'n': if(o) o[len] = '\n';s++;len++; break;
153             case 'r': if(o) o[len] = '\r';s++;len++; break;
154             case 't': if(o) o[len] = '\t';s++;len++; break;
155             case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': {
156                 unsigned int num=0;
157                 int nr = 0;
158                 while(strchr("01234567", *s) && nr<3 && s<end) {
159                     num <<= 3;
160                     num |= *s-'0';
161                     nr++;
162                     s++;
163                 }
164                 if(num>256) 
165                     syntaxerror("octal number out of range (0-255): %d", num);
166                 if(o) o[len] = num;len++;
167                 continue;
168             }
169             case 'x': case 'u': {
170                 int max=2;
171                 char bracket = 0;
172                 char unicode = 0;
173                 if(*s == 'u') {
174                     max = 6;
175                     unicode = 1;
176                 }
177                 s++;
178                 if(s==end) syntaxerror("invalid \\u or \\x at end of string");
179                 if(*s == '{')  {
180                     s++;
181                     if(s==end) syntaxerror("invalid \\u{ at end of string");
182                     bracket=1;
183                 }
184                 unsigned int num=0;
185                 int nr = 0;
186                 while(strchr("0123456789abcdefABCDEF", *s) && (bracket || nr < max) && s<end) {
187                     num <<= 4;
188                     if(*s>='0' && *s<='9') num |= *s - '0';
189                     if(*s>='a' && *s<='f') num |= *s - 'a' + 10;
190                     if(*s>='A' && *s<='F') num |= *s - 'A' + 10;
191                     nr++;
192                     s++;
193                 }
194                 if(bracket) {
195                     if(*s=='}' && s<end) {
196                         s++;
197                     } else {
198                         syntaxerror("missing terminating '}'");
199                     }
200                 }
201                 if(unicode) {
202                     char*utf8 = getUTF8(num);
203                     while(*utf8) {
204                         if(o) o[len] = *utf8;utf8++;len++;
205                     }
206                 } else {
207                     if(num>256) 
208                         syntaxerror("byte out of range (0-255): %d", num);
209                     if(o) o[len] = num;len++;
210                 }
211                 break;
212             }
213             default:
214                 syntaxerror("unknown escape sequence: \"\\%c\"", *s);
215         }
216     }
217     if(o) o[len]=0;
218     return len;
219 }
220
221 static string_t string_unescape(const char*in, int l)
222 {
223     const char*s = in;
224     const char*end = &in[l];
225
226     int len = do_unescape(s, end, 0);
227     char*n = (char*)malloc(len+1);
228     do_unescape(s, end, n);
229     string_t out = string_new(n, len);
230     return out; 
231 }
232
233 static void handleString(char*s, int len)
234 {
235     if(s[0]=='"') {
236         if(s[len-1]!='"') syntaxerror("String doesn't end with '\"'");
237         s++;len-=2;
238     }
239     else if(s[0]=='\'') {
240         if(s[len-1]!='\'') syntaxerror("String doesn't end with '\"'");
241         s++;len-=2;
242     }
243     else syntaxerror("String incorrectly terminated");
244
245     
246     avm2_lval.str = string_unescape(s, len);
247 }
248
249
250 char start_of_expression;
251
252 static inline int mkid(int type)
253 {
254     char*s = malloc(yyleng+1);
255     memcpy(s, yytext, yyleng);
256     s[yyleng]=0;
257     avm2_lval.id = s;
258     return type;
259 }
260
261 static inline int m(int type)
262 {
263     avm2_lval.token = type;
264     return type;
265 }
266
267
268 static char numberbuf[64];
269 static char*nrbuf()
270 {
271     if(yyleng>sizeof(numberbuf)-1)
272         syntaxerror("decimal number overflow");
273     char*s = numberbuf;
274     memcpy(s, yytext, yyleng);
275     s[yyleng]=0;
276     return s;
277 }
278
279 static inline int setint(int v)
280 {
281     avm2_lval.number_int = v;
282     if(v>-128)
283         return T_BYTE;
284     else if(v>=-32768)
285         return T_SHORT;
286     else
287         return T_INT;
288 }
289 static inline int setuint(unsigned int v)
290 {
291     avm2_lval.number_uint = v;
292     if(v<128)
293         return T_BYTE;
294     else if(v<32768)
295         return T_SHORT;
296     else
297         return T_UINT;
298 }
299 static inline int setfloat(double v)
300 {
301     avm2_lval.number_float = v;
302     return T_FLOAT;
303 }
304
305 static inline int handlefloat()
306 {
307     char*s = nrbuf();
308     avm2_lval.number_float = atof(s);
309     return T_FLOAT;
310 }
311
312 static inline int handleint()
313 {
314     char*s = nrbuf();
315     char l = (yytext[0]=='-');
316
317     char*max = l?"1073741824":"2147483647";
318     if(yyleng-l>10) {
319         warning("integer overflow: %s", s);
320         return handlefloat();
321     }
322     if(yyleng-l==10) {
323         int t;
324         for(t=0;t<yyleng-l;t++) {
325             if(yytext[l+t]>max[t]) {
326                 warning("integer overflow: %s", s);
327                 return handlefloat();
328             }
329             else if(yytext[l+t]<max[t])
330                 break;
331         }
332     }
333     if(yytext[0]=='-') {
334         int v = atoi(s);
335         return setint(v);
336     } else {
337         unsigned int v = 0;
338         int t;
339         for(t=0;t<yyleng;t++) {
340             v*=10;
341             v+=yytext[t]-'0';
342         }
343         return setuint(v);
344     }
345 }
346
347 static inline int handlehex()
348 {
349     char l = (yytext[0]=='-')+2;
350
351     if(yyleng-l>8) {
352         char*s = nrbuf();
353         syntaxerror("integer overflow %s", s);
354     }
355
356     int t;
357     unsigned int v = 0;
358     for(t=l;t<yyleng;t++) {
359         v<<=4;
360         char c = yytext[t];
361         if(c>='0' && c<='9')
362             v|=(c&15);
363         else if(c>='a' && c<='f' ||
364                 c>='A' && c<='F')
365             v|=(c&0x0f)+9;
366     }
367     if(l && v>1073741824) {
368         char*s = nrbuf();
369         warning("signed integer overflow: %s", s);
370         return setfloat(v);
371     }
372     if(!l && v>2147483647) {
373         char*s = nrbuf();
374         warning("unsigned integer overflow: %s", s);
375         return setfloat(v);
376     }
377
378     if(l==3) {
379         return setint(-(int)v);
380     } else {
381         return setuint(v);
382     }
383 }
384
385 void handleLabel(char*text, int len)
386 {
387     int t;
388     for(t=len-1;t>=0;--t) {
389         if(text[t]!=' ' &&
390            text[t]!=':')
391             break;
392     }
393     char*s = malloc(t+1);
394     memcpy(s, yytext, t);
395     s[t]=0;
396     avm2_lval.id = s;
397 }
398
399 static int handleregexp()
400 {
401     char*s = malloc(yyleng);
402     int len=yyleng-1;
403     memcpy(s, yytext+1, len);
404     s[len] = 0;
405     int t;
406     for(t=len;t>=0;--t) {
407         if(s[t]=='/') {
408             s[t] = 0;
409             break;
410         }
411     }
412     avm2_lval.regexp.pattern = s;
413     if(t==len) {
414         avm2_lval.regexp.options = 0;
415     } else {
416         avm2_lval.regexp.options = s+t+1;
417     }
418     return T_REGEXP;
419 }
420
421 void initialize_scanner();
422 #define YY_USER_INIT initialize_scanner();
423
424 /* count the number of lines+columns consumed by this token */
425 static inline void l() {
426     int t;
427     for(t=0;t<yyleng;t++) {
428         if(yytext[t]=='\n') {
429             current_line++;
430             current_column=0;
431         } else {
432             current_column++;
433         }
434     }
435 }
436 /* count the number of columns consumed by this token */
437 static inline void c() {
438     current_column+=yyleng;
439 }
440
441 //Boolean                      {c();return m(KW_BOOLEAN);}
442 //int                          {c();return m(KW_INT);}
443 //uint                         {c();return m(KW_UINT);}
444 //Number                       {c();return m(KW_NUMBER);}
445
446
447 %}
448
449 %s REGEXPOK
450 %s BEGINNING
451
452 NAME     [a-zA-Z_][a-zA-Z0-9_\\]*
453 _        [^a-zA-Z0-9_\\]
454
455 HEXINT    0x[a-zA-Z0-9]+
456 INT       [0-9]+
457 FLOAT     [0-9]+(\.[0-9]*)?|\.[0-9]+
458
459 HEXWITHSIGN [+-]?({HEXINT})
460 INTWITHSIGN [+-]?({INT})
461 FLOATWITHSIGN [+-]?({FLOAT})
462
463 STRING   ["](\\[\x00-\xff]|[^\\"\n])*["]|['](\\[\x00-\xff]|[^\\'\n])*[']
464 S        [ \n\r\t]
465 MULTILINE_COMMENT [/][*]+([*][^/]|[^/*]|[^*][/]|[\x00-\x1f])*[*]+[/]
466 SINGLELINE_COMMENT \/\/[^\n]*\n
467 REGEXP   [/]([^/\n]|\\[/])*[/][a-zA-Z]*
468 %%
469
470
471 {SINGLELINE_COMMENT}         {l(); /* single line comment */}
472 {MULTILINE_COMMENT}          {l(); /* multi line comment */}
473 [/][*]                       {syntaxerror("syntax error: unterminated comment", yytext);}
474
475 ^include{S}+{STRING}{S}*/\n    {l();handleInclude(yytext, yyleng, 1);}
476 ^include{S}+[^" \t\r\n][\x20-\xff]*{S}*/\n    {l();handleInclude(yytext, yyleng, 0);}
477 {STRING}                     {l(); BEGIN(INITIAL);handleString(yytext, yyleng);return T_STRING;}
478
479 <BEGINNING,REGEXPOK>{
480 {REGEXP}                     {c(); BEGIN(INITIAL);return handleregexp();} 
481 {HEXWITHSIGN}                {c(); BEGIN(INITIAL);return handlehex();}
482 {INTWITHSIGN}                {c(); BEGIN(INITIAL);return handleint();}
483 {FLOATWITHSIGN}              {c(); BEGIN(INITIAL);return handlefloat();}
484 }
485
486 \xef\xbb\xbf                 {/* utf 8 bom */}
487 {S}                          {l();}
488
489 {HEXINT}                     {c(); BEGIN(INITIAL);return handlehex();}
490 {INT}                        {c(); BEGIN(INITIAL);return handleint();}
491 {FLOAT}                      {c(); BEGIN(INITIAL);return handlefloat();}
492
493 3rr0r                        {/* for debugging: generates a tokenizer-level error */
494                               syntaxerror("3rr0r");}
495
496 {NAME}{S}*:{S}*for/{_}        {l();handleLabel(yytext, yyleng-3);return T_FOR;}
497 {NAME}{S}*:{S}*do/{_}         {l();handleLabel(yytext, yyleng-2);return T_DO;}
498 {NAME}{S}*:{S}*while/{_}      {l();handleLabel(yytext, yyleng-5);return T_WHILE;}
499 {NAME}{S}*:{S}*switch/{_}     {l();handleLabel(yytext, yyleng-6);return T_SWITCH;}
500 for                          {c();avm2_lval.id="";return T_FOR;}
501 do                           {c();avm2_lval.id="";return T_DO;}
502 while                        {c();avm2_lval.id="";return T_WHILE;}
503 switch                       {c();avm2_lval.id="";return T_SWITCH;}
504
505 [&][&]                       {c();BEGIN(REGEXPOK);return m(T_ANDAND);}
506 [|][|]                       {c();BEGIN(REGEXPOK);return m(T_OROR);}
507 [!][=]                       {c();BEGIN(REGEXPOK);return m(T_NE);}
508 [!][=][=]                    {c();BEGIN(REGEXPOK);return m(T_NEE);}
509 [=][=][=]                    {c();BEGIN(REGEXPOK);return m(T_EQEQEQ);}
510 [=][=]                       {c();BEGIN(REGEXPOK);return m(T_EQEQ);}
511 [>][=]                       {c();return m(T_GE);}
512 [<][=]                       {c();return m(T_LE);}
513 [-][-]                       {c();BEGIN(INITIAL);return m(T_MINUSMINUS);}
514 [+][+]                       {c();BEGIN(INITIAL);return m(T_PLUSPLUS);}
515 [+][=]                       {c();return m(T_PLUSBY);}
516 [-][=]                       {c();return m(T_MINUSBY);}
517 [/][=]                       {c();return m(T_DIVBY);}
518 [%][=]                       {c();return m(T_MODBY);}
519 [*][=]                       {c();return m(T_MULBY);}
520 [|][=]                       {c();return m(T_ORBY);}
521 [>][>][=]                    {c();return m(T_SHRBY);}
522 [<][<][=]                    {c();return m(T_SHLBY);}
523 [>][>][>][=]                 {c();return m(T_USHRBY);}
524 [<][<]                       {c();return m(T_SHL);}
525 [>][>][>]                    {c();return m(T_USHR);}
526 [>][>]                       {c();return m(T_SHR);}
527 \.\.\.                       {c();return m(T_DOTDOTDOT);}
528 \.\.                         {c();return m(T_DOTDOT);}
529 \.                           {c();return m('.');}
530 ::                           {c();return m(T_COLONCOLON);}
531 :                            {c();return m(':');}
532 instanceof                   {c();return m(KW_INSTANCEOF);}
533 implements                   {c();return m(KW_IMPLEMENTS);}
534 interface                    {c();return m(KW_INTERFACE);}
535 namespace                    {c();return m(KW_NAMESPACE);}
536 protected                    {c();return m(KW_PROTECTED);}
537 undefined                    {c();return m(KW_UNDEFINED);}
538 continue                     {c();return m(KW_CONTINUE);}
539 override                     {c();return m(KW_OVERRIDE);}
540 internal                     {c();return m(KW_INTERNAL);}
541 function                     {c();return m(KW_FUNCTION);}
542 default                      {c();return m(KW_DEFAULT);}
543 package                      {c();return m(KW_PACKAGE);}
544 private                      {c();return m(KW_PRIVATE);}
545 dynamic                      {c();return m(KW_DYNAMIC);}
546 extends                      {c();return m(KW_EXTENDS);}
547 delete                       {c();return m(KW_DELETE);}
548 return                       {c();return m(KW_RETURN);}
549 public                       {c();return m(KW_PUBLIC);}
550 native                       {c();return m(KW_NATIVE);}
551 static                       {c();return m(KW_STATIC);}
552 import                       {c();return m(KW_IMPORT);}
553 typeof                       {c();return m(KW_TYPEOF);}
554 throw                        {c();return m(KW_THROW);}
555 class                        {c();return m(KW_CLASS);}
556 const                        {c();return m(KW_CONST);}
557 catch                        {c();return m(KW_CATCH);}
558 final                        {c();return m(KW_FINAL);}
559 false                        {c();return m(KW_FALSE);}
560 break                        {c();return m(KW_BREAK);}
561 super                        {c();return m(KW_SUPER);}
562 each                         {c();return m(KW_EACH);}
563 void                         {c();return m(KW_VOID);}
564 true                         {c();return m(KW_TRUE);}
565 null                         {c();return m(KW_NULL);}
566 else                         {c();return m(KW_ELSE);}
567 case                         {c();return m(KW_CASE);}
568 with                         {c();return m(KW_WITH);}
569 use                          {c();return m(KW_USE);}
570 new                          {c();return m(KW_NEW);}
571 get                          {c();return m(KW_GET);}
572 set                          {c();return m(KW_SET);}
573 var                          {c();return m(KW_VAR);}
574 try                          {c();return m(KW_TRY);}
575 is                           {c();return m(KW_IS) ;}
576 in                           {c();return m(KW_IN) ;}
577 if                           {c();return m(KW_IF) ;}
578 as                           {c();return m(KW_AS);}
579 {NAME}                       {c();BEGIN(INITIAL);return mkid(T_IDENTIFIER);}
580
581 [+-\/*^~@$!%&\(=\[\]\{\}|?:;,<>] {c();BEGIN(REGEXPOK);return m(yytext[0]);}
582 [\)\]]                           {c();BEGIN(INITIAL);return m(yytext[0]);}
583
584 .                            {char c1=yytext[0];
585                               char buf[128];
586                               buf[0] = yytext[0];
587                               int t;
588                               for(t=1;t<128;t++) {
589                                   char c = buf[t]=input();
590                                   if(c=='\n' || c==EOF)  {
591                                       buf[t] = 0;
592                                       break;
593                                   }
594                               }
595                               if(c1>='0' && c1<='9')
596                                   syntaxerror("syntax error: %s (identifiers must not start with a digit)");
597                               else
598                                   syntaxerror("syntax error: %s", buf);
599                               printf("\n");
600                               exit(1);
601                               yyterminate();
602                              }
603 <<EOF>>                      {l();
604                               void*b = leave_file();
605                               if (!b) {
606                                  yyterminate();
607                                  yy_delete_buffer(YY_CURRENT_BUFFER);
608                                  return m(T_EOF);
609                               } else {
610                                   yy_delete_buffer(YY_CURRENT_BUFFER);
611                                   yy_switch_to_buffer(b);
612                               }
613                              }
614
615 %%
616
617 int yywrap()
618 {
619     return 1;
620 }
621
622 static char mbuf[256];
623 char*token2string(enum yytokentype nr, YYSTYPE v)
624 {
625     if(nr==T_STRING)     return "<string>";
626     else if(nr==T_INT)     return "<int>";
627     else if(nr==T_UINT)     return "<uint>";
628     else if(nr==T_BYTE)     return "<byte>";
629     else if(nr==T_FLOAT)     return "<float>";
630     else if(nr==T_REGEXP)     return "REGEXP";
631     else if(nr==T_EOF)        return "***END***";
632     else if(nr==T_GE)         return ">=";
633     else if(nr==T_LE)         return "<=";
634     else if(nr==T_MINUSMINUS) return "--";
635     else if(nr==T_PLUSPLUS)   return "++";
636     else if(nr==KW_IMPLEMENTS) return "implements";
637     else if(nr==KW_INTERFACE)  return "interface";
638     else if(nr==KW_NAMESPACE)  return "namespace";
639     else if(nr==KW_PROTECTED)  return "protected";
640     else if(nr==KW_OVERRIDE)   return "override";
641     else if(nr==KW_INTERNAL)   return "internal";
642     else if(nr==KW_FUNCTION)   return "function";
643     else if(nr==KW_PACKAGE)    return "package";
644     else if(nr==KW_PRIVATE)    return "private";
645     else if(nr==KW_BOOLEAN)    return "Boolean";
646     else if(nr==KW_DYNAMIC)    return "dynamic";
647     else if(nr==KW_EXTENDS)    return "extends";
648     else if(nr==KW_PUBLIC)     return "public";
649     else if(nr==KW_NATIVE)     return "native";
650     else if(nr==KW_STATIC)     return "static";
651     else if(nr==KW_IMPORT)     return "import";
652     else if(nr==KW_NUMBER)     return "number";
653     else if(nr==KW_CLASS)      return "class";
654     else if(nr==KW_CONST)      return "const";
655     else if(nr==KW_FINAL)      return "final";
656     else if(nr==KW_FALSE)      return "False";
657     else if(nr==KW_TRUE)       return "True";
658     else if(nr==KW_UINT)       return "uint";
659     else if(nr==KW_NULL)       return "null";
660     else if(nr==KW_ELSE)       return "else";
661     else if(nr==KW_USE)        return "use";
662     else if(nr==KW_INT)        return "int";
663     else if(nr==KW_NEW)        return "new";
664     else if(nr==KW_GET)        return "get";
665     else if(nr==KW_SET)        return "set";
666     else if(nr==KW_VAR)        return "var";
667     else if(nr==KW_IS)         return "is";
668     else if(nr==KW_AS)         return "as";
669     else if(nr==T_IDENTIFIER)  return "ID";
670     else {
671         sprintf(mbuf, "%d", nr);
672         return mbuf;
673     }
674 }
675
676 void initialize_scanner()
677 {
678     BEGIN(BEGINNING);
679 }
680