From f745b638b3580839f70a836b6d0943d7811e0fd9 Mon Sep 17 00:00:00 2001 From: kramm Date: Tue, 6 Jan 2009 21:37:39 +0000 Subject: implemented hex floats, added softwarning log level --- lib/as3/tokenizer.lex | 99 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/as3/tokenizer.lex b/lib/as3/tokenizer.lex index 27317a59..ff73165b 100644 --- a/lib/as3/tokenizer.lex +++ b/lib/as3/tokenizer.lex @@ -31,48 +31,40 @@ #include "tokenizer.h" #include "files.h" -static int verbose = 1; -static void dbg(const char*format, ...) +int as3_verbosity = 1; +void as3_error(const char*format, ...) { char buf[1024]; int l; va_list arglist; - if(!verbose) - return; + if(as3_verbosity<0) + exit(1); va_start(arglist, format); vsprintf(buf, format, arglist); va_end(arglist); - l = strlen(buf); - while(l && buf[l-1]=='\n') { - buf[l-1] = 0; - l--; - } - printf("(tokenizer) "); - printf("%s\n", buf); - fflush(stdout); + fprintf(stderr, "%s:%d:%d: error: %s\n", current_filename_short, current_line, current_column, buf); + fflush(stderr); + exit(1); } - -void syntaxerror(const char*format, ...) +void as3_warning(const char*format, ...) { char buf[1024]; int l; va_list arglist; - if(!verbose) - return; + if(as3_verbosity<1) + return; va_start(arglist, format); vsprintf(buf, format, arglist); va_end(arglist); - fprintf(stderr, "%s:%d:%d: error: %s\n", current_filename_short, current_line, current_column, buf); + fprintf(stderr, "%s:%d:%d: warning: %s\n", current_filename_short, current_line, current_column, buf); fflush(stderr); - exit(1); } -void warning(const char*format, ...) +void as3_softwarning(const char*format, ...) { - return; char buf[1024]; int l; va_list arglist; - if(!verbose) + if(as3_verbosity<2) return; va_start(arglist, format); vsprintf(buf, format, arglist); @@ -80,6 +72,26 @@ void warning(const char*format, ...) fprintf(stderr, "%s:%d:%d: warning: %s\n", current_filename_short, current_line, current_column, buf); fflush(stderr); } +static void dbg(const char*format, ...) +{ + char buf[1024]; + int l; + va_list arglist; + if(as3_verbosity<3) + return; + va_start(arglist, format); + vsprintf(buf, format, arglist); + va_end(arglist); + l = strlen(buf); + while(l && buf[l-1]=='\n') { + buf[l-1] = 0; + l--; + } + printf("(tokenizer) "); + printf("%s\n", buf); + fflush(stdout); +} + #ifndef YY_CURRENT_BUFFER @@ -316,14 +328,14 @@ static inline int handleint() char*max = l?"1073741824":"2147483647"; if(yyleng-l>10) { - warning("integer overflow: %s", s); + as3_warning("integer overflow: %s (converted to Number)", s); return handlefloat(); } if(yyleng-l==10) { int t; for(t=0;tmax[t]) { - warning("integer overflow: %s", s); + as3_warning("integer overflow: %s (converted to Number)", s); return handlefloat(); } else if(yytext[l+t]='0' && c<='9') + d+=(c&15)*base; + else if((c>='a' && c<='f') || (c>='A' && c<='F')) + d+=((c&0x0f)+9)*base; + } + return setfloat(d); +} static inline int handlehex() { char l = (yytext[0]=='-')+2; + int len = yyleng; - if(yyleng-l>8) { + if(len-l>8) { char*s = nrbuf(); syntaxerror("integer overflow %s", s); } int t; unsigned int v = 0; - for(t=l;t='0' && c<='9') v|=(c&15); - else if(c>='a' && c<='f' || - c>='A' && c<='F') + else if((c>='a' && c<='f') || (c>='A' && c<='F')) v|=(c&0x0f)+9; } if(l && v>1073741824) { char*s = nrbuf(); - warning("signed integer overflow: %s", s); + as3_warning("signed integer overflow: %s (converted to Number)", s); return setfloat(v); } if(!l && v>2147483647) { char*s = nrbuf(); - warning("unsigned integer overflow: %s", s); + as3_warning("unsigned integer overflow: %s (converted to Number)", s); return setfloat(v); } @@ -453,10 +490,12 @@ NAME [a-zA-Z_][a-zA-Z0-9_\\]* _ [^a-zA-Z0-9_\\] HEXINT 0x[a-zA-Z0-9]+ +HEXFLOAT 0x[a-zA-Z0-9]*\.[a-zA-Z0-9]* INT [0-9]+ FLOAT [0-9]+(\.[0-9]*)?|\.[0-9]+ HEXWITHSIGN [+-]?({HEXINT}) +HEXFLOATWITHSIGN [+-]?({HEXFLOAT}) INTWITHSIGN [+-]?({INT}) FLOATWITHSIGN [+-]?({FLOAT}) @@ -479,6 +518,7 @@ REGEXP [/]([^/\n]|\\[/])*[/][a-zA-Z]* { {REGEXP} {c(); BEGIN(INITIAL);return handleregexp();} {HEXWITHSIGN} {c(); BEGIN(INITIAL);return handlehex();} +{HEXFLOATWITHSIGN} {c(); BEGIN(INITIAL);return handlehexfloat();} {INTWITHSIGN} {c(); BEGIN(INITIAL);return handleint();} {FLOATWITHSIGN} {c(); BEGIN(INITIAL);return handlefloat();} } @@ -487,6 +527,7 @@ REGEXP [/]([^/\n]|\\[/])*[/][a-zA-Z]* {S} {l();} {HEXINT} {c(); BEGIN(INITIAL);return handlehex();} +{HEXFLOAT} {c(); BEGIN(INITIAL);return handlehexfloat();} {INT} {c(); BEGIN(INITIAL);return handleint();} {FLOAT} {c(); BEGIN(INITIAL);return handlefloat();} -- cgit v1.2.3