-
-// ----------------------- expression evaluation -------------------------------------
-
-E : INNERFUNCTION %prec prec_none {$$ = $1;}
-//V : CONSTANT {$$ = 0;}
-E : CONSTANT
-//V : VAR_READ %prec T_IDENTIFIER {$$ = 0;}
-E : VAR_READ %prec T_IDENTIFIER {$$ = $1;}
-//V : NEW {$$ = $1.c;}
-E : NEW {$$ = $1;}
-//V : DELETE {$$ = $1.c;}
-E : DELETE {$$ = $1;}
-
-E : FUNCTIONCALL
-
-E : T_REGEXP {
- $$.c = 0;
- namespace_t ns = {ACCESS_PACKAGE, ""};
- multiname_t m = {QNAME, &ns, 0, "RegExp"};
- if(!$1.options) {
- $$.c = abc_getlex2($$.c, &m);
- $$.c = abc_pushstring($$.c, $1.pattern);
- $$.c = abc_construct($$.c, 1);
- } else {
- $$.c = abc_getlex2($$.c, &m);
- $$.c = abc_pushstring($$.c, $1.pattern);
- $$.c = abc_pushstring($$.c, $1.options);
- $$.c = abc_construct($$.c, 2);
- }
- $$.t = TYPE_REGEXP;
-}
-
-CONSTANT : T_BYTE {$$.c = abc_pushbyte(0, $1);
- //MULTINAME(m, registry_getintclass());
- //$$.c = abc_coerce2($$.c, &m); // FIXME
- $$.t = TYPE_INT;
- }
-CONSTANT : T_SHORT {$$.c = abc_pushshort(0, $1);
- $$.t = TYPE_INT;
- }
-CONSTANT : T_INT {$$.c = abc_pushint(0, $1);
- $$.t = TYPE_INT;
- }
-CONSTANT : T_UINT {$$.c = abc_pushuint(0, $1);
- $$.t = TYPE_UINT;
- }
-CONSTANT : T_FLOAT {$$.c = abc_pushdouble(0, $1);
- $$.t = TYPE_FLOAT;
- }
-CONSTANT : T_STRING {$$.c = abc_pushstring2(0, &$1);free((char*)$1.str);
- $$.t = TYPE_STRING;
- }
-CONSTANT : "undefined" {$$.c = abc_pushundefined(0);
- $$.t = TYPE_ANY;
- }
-CONSTANT : "true" {$$.c = abc_pushtrue(0);
- $$.t = TYPE_BOOLEAN;
- }
-CONSTANT : "false" {$$.c = abc_pushfalse(0);
- $$.t = TYPE_BOOLEAN;
- }
-CONSTANT : "null" {$$.c = abc_pushnull(0);
- $$.t = TYPE_NULL;
- }
-
-E : E '<' E {$$.c = code_append($1.c,$3.c);$$.c = abc_greaterequals($$.c);$$.c=abc_not($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-E : E '>' E {$$.c = code_append($1.c,$3.c);$$.c = abc_greaterthan($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-E : E "<=" E {$$.c = code_append($1.c,$3.c);$$.c = abc_greaterthan($$.c);$$.c=abc_not($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-E : E ">=" E {$$.c = code_append($1.c,$3.c);$$.c = abc_greaterequals($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-E : E "==" E {$$.c = code_append($1.c,$3.c);$$.c = abc_equals($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-E : E "===" E {$$.c = code_append($1.c,$3.c);$$.c = abc_strictequals($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-E : E "!==" E {$$.c = code_append($1.c,$3.c);$$.c = abc_strictequals($$.c);$$.c = abc_not($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-E : E "!=" E {$$.c = code_append($1.c,$3.c);$$.c = abc_equals($$.c);$$.c = abc_not($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-
-E : E "||" E {$$.t = join_types($1.t, $3.t, 'O');
- $$.c = $1.c;
- $$.c = converttype($$.c, $1.t, $$.t);
- $$.c = abc_dup($$.c);
- code_t*jmp = $$.c = abc_iftrue($$.c, 0);
- $$.c = cut_last_push($$.c);
- $$.c = code_append($$.c,$3.c);
- $$.c = converttype($$.c, $3.t, $$.t);
- code_t*label = $$.c = abc_label($$.c);
- jmp->branch = label;
- }
-E : E "&&" E {
- $$.t = join_types($1.t, $3.t, 'A');
- /*printf("%08x:\n",$1.t);
- code_dump($1.c, 0, 0, "", stdout);
- printf("%08x:\n",$3.t);
- code_dump($3.c, 0, 0, "", stdout);
- printf("joining %08x and %08x to %08x\n", $1.t, $3.t, $$.t);*/
- $$.c = $1.c;
- $$.c = converttype($$.c, $1.t, $$.t);
- $$.c = abc_dup($$.c);
- code_t*jmp = $$.c = abc_iffalse($$.c, 0);
- $$.c = cut_last_push($$.c);
- $$.c = code_append($$.c,$3.c);
- $$.c = converttype($$.c, $3.t, $$.t);
- code_t*label = $$.c = abc_label($$.c);
- jmp->branch = label;
- }
-
-E : '!' E {$$.c=$2.c;
- $$.c = abc_not($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-
-E : '~' E {$$.c=$2.c;
- $$.c = abc_bitnot($$.c);
- $$.t = TYPE_INT;
- }
-
-E : E '&' E {$$.c = code_append($1.c,$3.c);
- $$.c = abc_bitand($$.c);
- $$.t = TYPE_INT;
- }
-
-E : E '^' E {$$.c = code_append($1.c,$3.c);
- $$.c = abc_bitxor($$.c);
- $$.t = TYPE_INT;
- }
-
-E : E '|' E {$$.c = code_append($1.c,$3.c);
- $$.c = abc_bitor($$.c);
- $$.t = TYPE_INT;
- }
-
-E : E ">>" E {$$.c = code_append($1.c,$3.c);
- $$.c = abc_rshift($$.c);
- $$.t = TYPE_INT;
- }
-E : E ">>>" E {$$.c = code_append($1.c,$3.c);
- $$.c = abc_urshift($$.c);
- $$.t = TYPE_INT;
- }
-E : E "<<" E {$$.c = code_append($1.c,$3.c);
- $$.c = abc_lshift($$.c);
- $$.t = TYPE_INT;
- }
-
-E : E '/' E {$$.c = code_append($1.c,$3.c);
- $$.c = abc_divide($$.c);
- $$.t = TYPE_NUMBER;
- }
-E : E '%' E {$$.c = code_append($1.c,$3.c);
- $$.c = abc_modulo($$.c);
- $$.t = TYPE_NUMBER;
- }
-E : E '+' E {$$.c = code_append($1.c,$3.c);
- if(BOTH_INT($1.t, $3.t)) {
- $$.c = abc_add_i($$.c);
- $$.t = TYPE_INT;
- } else {
- $$.c = abc_add($$.c);
- $$.t = join_types($1.t,$3.t,'+');
- }
- }
-E : E '-' E {$$.c = code_append($1.c,$3.c);
- if(BOTH_INT($1.t,$3.t)) {
- $$.c = abc_subtract_i($$.c);
- $$.t = TYPE_INT;
- } else {
- $$.c = abc_subtract($$.c);
- $$.t = TYPE_NUMBER;
- }
- }
-E : E '*' E {$$.c = code_append($1.c,$3.c);
- if(BOTH_INT($1.t,$3.t)) {
- $$.c = abc_multiply_i($$.c);
- $$.t = TYPE_INT;
- } else {
- $$.c = abc_multiply($$.c);
- $$.t = TYPE_NUMBER;
- }
- }
-
-E : E "in" E {$$.c = code_append($1.c,$3.c);
- $$.c = abc_in($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-
-E : E "as" E {char use_astype=0; // flash player's astype works differently than astypelate
- if(use_astype && TYPE_IS_CLASS($3.t) && $3.t->data) {
- MULTINAME(m, (classinfo_t*)($3.t->data));
- $$.c = abc_astype2($1.c, &m);
- $$.t = $3.t->data;
- } else {
- $$.c = code_append($1.c, $3.c);
- $$.c = abc_astypelate($$.c);
- $$.t = TYPE_ANY;
- }
- }
-
-E : E "instanceof" E
- {$$.c = code_append($1.c, $3.c);
- $$.c = abc_instanceof($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-
-E : E "is" E {$$.c = code_append($1.c, $3.c);
- $$.c = abc_istypelate($$.c);
- $$.t = TYPE_BOOLEAN;
- }
-
-E : "typeof" '(' E ')' {
- $$.c = $3.c;
- $$.c = abc_typeof($$.c);
- $$.t = TYPE_STRING;
- }
-
-E : "void" E {
- $$.c = cut_last_push($2.c);
- $$.c = abc_pushundefined($$.c);
- $$.t = TYPE_ANY;
- }
-
-E : "void" { $$.c = abc_pushundefined(0);
- $$.t = TYPE_ANY;
- }
-
-E : '(' EXPRESSION ')' {$$=$2;} //allow commas in here, too
-
-E : '-' E {
- $$=$2;
- if(IS_INT($2.t)) {
- $$.c=abc_negate_i($$.c);
- $$.t = TYPE_INT;
- } else {
- $$.c=abc_negate($$.c);
- $$.t = TYPE_NUMBER;
- }