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