#include <stdio.h>
#include <stdarg.h>
#include "../utf8.h"
+#include "common.h"
#include "tokenizer.h"
#include "files.h"
-int as3_pass = 0;
-int as3_verbosity = 1;
unsigned int as3_tokencount = 0;
-void as3_error(const char*format, ...)
-{
- char buf[1024];
- int l;
- va_list arglist;
- if(as3_verbosity<0)
- exit(1);
- 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);
- fflush(stderr);
- exit(1);
-}
-void as3_warning(const char*format, ...)
-{
- char buf[1024];
- int l;
- va_list arglist;
- if(as3_verbosity<1)
- return;
- va_start(arglist, format);
- vsprintf(buf, format, arglist);
- va_end(arglist);
- fprintf(stderr, "%s:%d:%d: warning: %s\n", current_filename_short, current_line, current_column, buf);
- fflush(stderr);
-}
-void as3_softwarning(const char*format, ...)
-{
- char buf[1024];
- int l;
- va_list arglist;
- if(as3_verbosity<2)
- return;
- va_start(arglist, format);
- vsprintf(buf, format, arglist);
- va_end(arglist);
- 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];
}
break;
}
- default:
- syntaxerror("unknown escape sequence: \"\\%c\"", *s);
+ default: {
+ if(o) {
+ o[len+0] = '\\';
+ o[len+1] = *s;
+ }
+ s++;
+ len+=2;
+ break;
+ }
}
}
if(o) o[len]=0;
static void handleString(char*s, int len)
{
- if(as3_pass < 2) {
- // don't bother decoding strings in pass 1
- memset(&a3_lval, 0, sizeof(a3_lval));
- return;
- }
-
if(s[0]=='"') {
if(s[len-1]!='"') syntaxerror("String doesn't end with '\"'");
s++;len-=2;
s++;len-=2;
}
else syntaxerror("String incorrectly terminated");
-
a3_lval.str = string_unescape(s, len);
}
static inline int setint(int v)
{
a3_lval.number_int = v;
- if(v>-128)
- return T_BYTE;
- else if(v>=-32768)
- return T_SHORT;
- else
- return T_INT;
-}
-static inline int setuint(unsigned int v)
-{
- a3_lval.number_uint = v;
- if(v<128)
- return T_BYTE;
- else if(v<32768)
- return T_SHORT;
- else
- return T_UINT;
+ return T_INT;
}
static inline int setfloat(double v)
{
char*s = nrbuf();
char l = (yytext[0]=='-');
- char*max = l?"1073741824":"2147483647";
+ //char*max = l?"1073741824":"2147483647";
+ char*max = l?"2147483648":"2147483647";
+
if(yyleng-l>10) {
as3_softwarning("integer overflow: %s (converted to Number)", s);
return handlefloat();
v*=10;
v+=yytext[t]-'0';
}
- return setuint(v);
+ return setint(v);
}
}
else if((c>='a' && c<='f') || (c>='A' && c<='F'))
v|=(c&0x0f)+9;
}
- if(l && v>1073741824) {
+ if(l && v>=0x80000000) {
char*s = nrbuf();
- as3_softwarning("signed integer overflow: %s (converted to Number)", s);
+ as3_softwarning("integer overflow: %s (converted to Number)", s);
return setfloat(v);
}
- if(!l && v>2147483647) {
+ if(!l && v>0x7fffffff) {
char*s = nrbuf();
- as3_softwarning("unsigned integer overflow: %s (converted to Number)", s);
+ as3_softwarning("integer overflow: %s (converted to Number)", s);
return setfloat(v);
}
if(l==3) {
return setint(-(int)v);
} else {
- return setuint(v);
+ return setint(v);
}
}
current_column+=yyleng;
}
-static trie_t*namespaces = 0;
-void tokenizer_register_namespace(const char*id)
+trie_t*active_namespaces = 0;
+/*void tokenizer_register_namespace(const char*id)
{
- trie_put(&namespaces, id);
+ trie_put(namespaces, id, 0);
}
+void tokenizer_unregister_namespace(const char*id)
+{
+ trie_remove(namespaces, id);
+}*/
static inline tokenizer_is_namespace(const char*id)
{
- return trie_lookup(namespaces, id);
+ return trie_contains(active_namespaces, id);
}
static inline int handleIdentifier()
{HEXFLOAT}/{_} {c(); BEGIN(INITIAL);return handlehexfloat();}
{INT}/{_} {c(); BEGIN(INITIAL);return handleint();}
{FLOAT}/{_} {c(); BEGIN(INITIAL);return handlefloat();}
+NaN {c(); BEGIN(INITIAL);return m(KW_NAN);}
3rr0r {/* for debugging: generates a tokenizer-level error */
syntaxerror("3rr0r");}
[%][=] {c();BEGIN(REGEXPOK);return m(T_MODBY);}
[*][=] {c();BEGIN(REGEXPOK);return m(T_MULBY);}
[|][=] {c();BEGIN(REGEXPOK);return m(T_ORBY);}
+[&][=] {c();BEGIN(REGEXPOK);return m(T_ANDBY);}
[>][>][=] {c();BEGIN(REGEXPOK);return m(T_SHRBY);}
[<][<][=] {c();BEGIN(REGEXPOK);return m(T_SHLBY);}
[>][>][>][=] {c();BEGIN(REGEXPOK);return m(T_USHRBY);}
}
else if(nr==T_INT) return "<int>";
else if(nr==T_UINT) return "<uint>";
- else if(nr==T_BYTE) return "<byte>";
else if(nr==T_FLOAT) return "<float>";
else if(nr==T_EOF) return "***END***";
else if(nr==T_GE) return ">=";