From: Peep P. <so...@us...> - 2004-03-20 19:28:43
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10321/src Modified Files: interpret.h lang.y lex.l Log Message: New x= operators. Index: lang.y =================================================================== RCS file: /cvsroot/agd/server/src/lang.y,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- lang.y 18 Mar 2004 20:46:39 -0000 1.6 +++ lang.y 20 Mar 2004 19:18:42 -0000 1.7 @@ -14,9 +14,12 @@ void redeclaration_error(def_id_t *id, int new_type); int compare_args(array_t *arg1, array_t *arg2); -#define MAKE_LVALUE(x) if((int)x.arr.data[0] == F_PUSH_LVAR) x.arr.data[0] = (void *)F_PUSH_LVAR_LVALUE;\ - else if((int)x.arr.data[0] == F_PUSH_GVAR) x.arr.data[0] = (void*)F_PUSH_GVAR_LVALUE;\ - else if((int)x.arr.data[x.arr.length-1] == F_RANGE) x.arr.data[x.arr.length-1] = (void*)F_RANGE_LVALUE\ +#define MAKE_LVALUE(x) if((int)x.arr.data[0] == F_PUSH_LVAR)\ + x.arr.data[0] = (void *)F_PUSH_LVAR_LVALUE;\ + else if((int)x.arr.data[0] == F_PUSH_GVAR)\ + x.arr.data[0] = (void*)F_PUSH_GVAR_LVALUE;\ + else if((int)x.arr.data[x.arr.length-1] == F_RANGE)\ + x.arr.data[x.arr.length-1] = (void*)F_RANGE_LVALUE %} %expect 1 @@ -46,6 +49,8 @@ /* operators */ %right L_ASSIGN +%left L_PE /* Pluq-equals */ L_ME /* Minus-equals */ +%left L_MUE /* Multiply-equals */ L_MOE /* Modulo-equals */ L_DE /* Divide-equals */ %left L_OR L_AND %left L_EQ L_NE %left L_PLUS L_MINUS @@ -628,7 +633,28 @@ array_push(&$$.arr, (void *) F_ADD); } } - | expr L_MINUS expr + | expr L_PE expr /* Plus-equals */ + { + $$.type = $1.type; + $$.side_effect = 1; + $$.direct_type = $$.lval = 0; + + check_operand(F_ADDA, $1.type, $3.type); + + if(!$1.lval) { + comp_error("expression is not a lvalue"); + } + + init_array(&$$.arr); + /* Once for F_ADD, once for F_ASSIGN. */ + array_concat(&$$.arr, &$1.arr); + MAKE_LVALUE($$); + array_concat(&$$.arr, &$1.arr); + array_concat(&$$.arr, &$3.arr); + array_push(&$$.arr, (void *) F_ADD); + array_push(&$$.arr, (void *) F_ASSIGN); + } +| expr L_MINUS expr { $$.lval = $$.direct_type = 0; $$.side_effect = $1.side_effect || $3.side_effect; @@ -653,6 +679,26 @@ array_push(&$$.arr, (void *) F_SUB); } } + | expr L_ME expr /* Minus-equals */ + { + $$.type = $1.type; + $$.side_effect = 1; + $$.direct_type = $$.lval = 0; + + check_operand(F_SUBA, $1.type, $3.type); + if(!$1.lval) { + comp_error("expression is not a lvalue"); + } + + init_array(&$$.arr); + /* Once for F_SUB, once for F_ASSIGN. */ + array_concat(&$$.arr, &$1.arr); + MAKE_LVALUE($$); + array_concat(&$$.arr, &$1.arr); + array_concat(&$$.arr, &$3.arr); + array_push(&$$.arr, (void *) F_SUB); + array_push(&$$.arr, (void *) F_ASSIGN); + } | expr L_MUL expr { $$.lval = $$.direct_type = 0; @@ -672,6 +718,27 @@ array_push(&$$.arr, (void *) F_MUL); } } + | expr L_MUE expr /* Multiply-equals */ + { + $$.type = $1.type; + $$.side_effect = 1; + $$.direct_type = $$.lval = 0; + + check_operand(F_MULA, $1.type, $3.type); + + if(!$1.lval) { + comp_error("expression is not a lvalue"); + } + + init_array(&$$.arr); + /* Once for F_MUL, once for F_ASSIGN. */ + array_concat(&$$.arr, &$1.arr); + MAKE_LVALUE($$); + array_concat(&$$.arr, &$1.arr); + array_concat(&$$.arr, &$3.arr); + array_push(&$$.arr, (void *) F_MUL); + array_push(&$$.arr, (void *) F_ASSIGN); + } | expr L_DIV expr { $$.lval = $$.direct_type = 0; @@ -692,6 +759,27 @@ array_push(&$$.arr, (void *) F_DIV); } } + | expr L_DE expr /* Divide-equals */ + { + $$.type = $1.type; + $$.side_effect = 1; + $$.direct_type = $$.lval = 0; + + check_operand(F_DIVA, $1.type, $3.type); + + if(!$1.lval) { + comp_error("expression is not a lvalue"); + } + + init_array(&$$.arr); + /* Once for F_DIV, once for F_ASSIGN. */ + array_concat(&$$.arr, &$1.arr); + MAKE_LVALUE($$); + array_concat(&$$.arr, &$1.arr); + array_concat(&$$.arr, &$3.arr); + array_push(&$$.arr, (void *) F_DIV); + array_push(&$$.arr, (void *) F_ASSIGN); + } | expr L_MOD expr { $$.lval = $$.direct_type = 0; @@ -711,7 +799,28 @@ array_push(&$$.arr, (void *) F_MOD); } } - | expr L_INC + | expr L_MOE expr /* Modulo-equals */ + { + $$.type = $1.type; + $$.side_effect = 1; + $$.direct_type = $$.lval = 0; + + check_operand(F_MODA, $1.type, $3.type); + + if(!$1.lval) { + comp_error("expression is not a lvalue"); + } + + init_array(&$$.arr); + /* Once for F_MOD, once for F_ASSIGN. */ + array_concat(&$$.arr, &$1.arr); + MAKE_LVALUE($$); + array_concat(&$$.arr, &$1.arr); + array_concat(&$$.arr, &$3.arr); + array_push(&$$.arr, (void *) F_MOD); + array_push(&$$.arr, (void *) F_ASSIGN); + } + | expr L_INC { check_operand(F_POSTINC, $1.type, 0); if(!$1.lval) { Index: interpret.h =================================================================== RCS file: /cvsroot/agd/server/src/interpret.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- interpret.h 18 Mar 2004 20:46:50 -0000 1.7 +++ interpret.h 20 Mar 2004 19:18:42 -0000 1.8 @@ -25,26 +25,31 @@ #define F_ASSIGN 19 /* Pops two variables off the stack, and assigns upper one's value to the lower one. (the lower one should be a T_LVALUE) */ #define F_ADD 20 -#define F_SUB 21 -#define F_MUL 22 -#define F_DIV 23 -#define F_MOD 24 -#define F_NOT 25 -#define F_EQ 26 -#define F_NE 27 -#define F_GT 28 -#define F_GE 29 -#define F_LT 30 -#define F_LE 31 -#define F_NEG 32 -#define F_AND 33 /* Have to keep these in because of check_operand() */ -#define F_OR 34 /* */ -#define F_POSTINC 35 -#define F_PREINC 36 -#define F_POSTDEC 37 -#define F_PREDEC 38 -#define F_RANGE 39 -#define F_RANGE_LVALUE 40 +#define F_ADDA 21 +#define F_SUB 22 +#define F_SUBA 23 +#define F_MUL 24 +#define F_MULA 25 +#define F_DIV 26 +#define F_DIVA 27 +#define F_MOD 28 +#define F_MODA 29 +#define F_NOT 30 +#define F_EQ 31 +#define F_NE 32 +#define F_GT 33 +#define F_GE 34 +#define F_LT 35 +#define F_LE 36 +#define F_NEG 37 +#define F_AND 38 /* Have to keep these in because of check_operand() */ +#define F_OR 39 /* */ +#define F_POSTINC 40 +#define F_PREINC 41 +#define F_POSTDEC 42 +#define F_PREDEC 43 +#define F_RANGE 44 +#define F_RANGE_LVALUE 45 #define F_HIGHEST F_RANGE_LVALUE Index: lex.l =================================================================== RCS file: /cvsroot/agd/server/src/lex.l,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- lex.l 18 Mar 2004 20:46:20 -0000 1.6 +++ lex.l 20 Mar 2004 19:18:42 -0000 1.7 @@ -229,12 +229,6 @@ "--" RET(s, "--", L_DEC); "!" RET(c, '!', L_NOT); "!=" RET(s, "!=", L_NE); -"({" RET(s, "({", L_OPEN_ARRAY); -"([" RET(s, "([", L_OPEN_MAPPING); -"(:" RET(s, "(:", L_OPEN_FUNP); -"})" RET(s, "})", L_CLOSE_ARRAY); -"}]" RET(s, "])", L_CLOSE_MAPPING); -":)" RET(s, ":)", L_CLOSE_FUNP); ")" RET(c, ')', ')'); "==" RET(s, "==", L_EQ); "=" RET(c, '=', L_ASSIGN); @@ -243,7 +237,20 @@ "*" RET(c, '*', L_MUL); "/" RET(c, '/', L_DIV); "%" RET(c, '%', L_MOD); - +"+=" RET(s, "+=", L_PE); +"-=" RET(s, "-=", L_ME); +"*=" RET(s, "*=", L_MUE); +"/=" RET(s, "/=", L_DE); +"%=" RET(s, "%=", L_MOE); + + +"({" RET(s, "({", L_OPEN_ARRAY); +"([" RET(s, "([", L_OPEN_MAPPING); +"(:" RET(s, "(:", L_OPEN_FUNP); +"})" RET(s, "})", L_CLOSE_ARRAY); +"}]" RET(s, "])", L_CLOSE_MAPPING); +":)" RET(s, ":)", L_CLOSE_FUNP); + [0-9]+ yylval.i = atoi(yytext); RET(d, yylval.i, L_INTEGER); return RET(s, "return", L_RETURN); if RET(s, "if", L_IF); |