From: Peep P. <so...@us...> - 2004-06-20 14:04:53
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1220 Modified Files: lang.y Log Message: Some hacks on expr_list and defining variables. Index: lang.y =================================================================== RCS file: /cvsroot/agd/server/src/lang.y,v retrieving revision 1.22 retrieving revision 1.23 diff -u -d -r1.22 -r1.23 --- lang.y 14 Jun 2004 20:56:38 -0000 1.22 +++ lang.y 20 Jun 2004 14:04:45 -0000 1.23 @@ -1,4 +1,6 @@ %{ +/* local_vars and global_vars still need some work, + especially in not allowing 'void'. */ #include <stdlib.h> #include "config.h" @@ -126,21 +128,9 @@ def: fundef - | vardef + | global_var ; -vardef: - optional_type global_vars ';' - { - global_type = 0; - if($1 == T_VOID) { - comp_error("invalid type"); - } else if(!$1) { - comp_error("missing type"); - } - } - ; - fundef: optional_type L_IDENTIFIER { @@ -318,12 +308,15 @@ } | L_OPEN_ARRAY expr_list L_CLOSE_ARRAY { - $$.side_effect = $2.side_effect; + /* Ugh, an array constant has no side effect, but + still pushes something on the stack. Let's + set side effect always on, for now. */ + $$.side_effect = /*$2.side_effect*/ 1; + $$.lval = 0; $$.type = $2.type | T_ARRAY; -/* $2.arr.length--;*/ add_token(F_PUSH_ARRAY); -/* add_two_tokens($2.type, $2.arr.data[$2.arr.length]);*/ + add_two_tokens($2.type, $2.lval); /* Abusing lval as length. */ } ; @@ -503,43 +496,37 @@ /* empty */ { $$.type = $$.side_effect = 0; -/* init_array(&$$.arr); - array_push(&$$.arr, (void *) 0);*/ + /* Ok, we're seriously abusing + a variable here - it's used in length + context - .lval shows how many members + are in the list. */ + $$.lval = 0; } | expr_list2 - { + { $$.type = $1.type; $$.side_effect = $1.side_effect; -/* init_array(&$$.arr); - array_concat(&$$.arr, &$1.arr);*/ - } - ; + $$.lval = $1.lval; /* Same abuse here. */ + } + ; expr_list2: expr - { - $$.type = $1.type; -/* $$.side_effect = $1.side_effect; - init_array(&$$.arr); - array_concat(&$$.arr, &$1.arr); - array_push(&$$.arr, (void *) 1);*/ - } - | expr ',' expr_list2 - { - $$.side_effect = $1.side_effect || $3.side_effect; + { + $$.type = $1.type; + $$.lval = 1; /* And here. */ + } + | expr ',' expr_list2 + { + $$.side_effect = $1.side_effect || $3.side_effect; if($1.type != $3.type) { comp_error("all elements in array constant must be of same type"); /*$$.type = T_MIXED;*/ } $$.type = $1.type; -/* init_array(&$$.arr); - array_concat(&$$.arr, &$1.arr); - $3.arr.length--; - array_concat(&$$.arr, &$3.arr); - array_push(&$$.arr, $3.arr.data[$3.arr.length] + 1); - $3.arr.data = realloc($3.arr.data, sizeof(void *) * $3.arr.length);*/ - } - ; + $$.lval = $3.lval + 1; /* And here. */ + } + ; block_or_semi: block { $$ = 1; } @@ -708,10 +695,27 @@ $$ = $1; } ; - + +local_var: + type local_vars + { + global_type = 0; + if(!$1) { + comp_error("missing type"); + } else if($1 == T_VOID) { + comp_error("invalid type"); + } + } + ; + local_vars: lvar_def - | local_vars ',' lvar_def + | local_vars ',' optional_type lvar_def + { + if($3 == T_VOID) { + comp_error("invalid type"); + } + } ; lvar_def: @@ -735,10 +739,29 @@ } } ; - + +global_var: + optional_type global_vars ';' + { + if(!$1) { + comp_error("missing type"); + } + if($1 == T_VOID) { + comp_error("invalid type"); + } + + global_type = 0; + } + ; + global_vars: gvar_def - | global_vars ',' gvar_def + | global_vars ',' optional_type gvar_def + { + if($3 == T_VOID) { + comp_error("invalid type"); + } + } ; gvar_def: @@ -783,18 +806,6 @@ } ; -local_var: - type local_vars - { - global_type = 0; - if(!$1) { - comp_error("missing type"); - } else if($1 == T_VOID) { - comp_error("invalid type"); - } - } - ; - optional_expr: /* empty */ { memset(&$$, 0, sizeof($$)); } |