From: Peep P. <so...@us...> - 2004-03-21 14:16:55
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4008/src Modified Files: lang.h lang.y lex.l Log Message: Added for(). Index: lang.h =================================================================== RCS file: /cvsroot/agd/server/src/lang.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- lang.h 21 Mar 2004 13:26:17 -0000 1.5 +++ lang.h 21 Mar 2004 14:06:36 -0000 1.6 @@ -34,45 +34,46 @@ L_ELSE = 260, L_DO = 261, L_WHILE = 262, - L_CONTINUE = 263, - L_BREAK = 264, - L_DATA_TYPE = 265, - L_IDENTIFIER = 266, - L_STRING = 267, - L_INTEGER = 268, - L_OPEN_MAPPING = 269, - L_CLOSE_MAPPING = 270, - L_OPEN_ARRAY = 271, - L_CLOSE_ARRAY = 272, - L_OPEN_FUNP = 273, - L_CLOSE_FUNP = 274, - L_ASSIGN = 275, - L_ME = 276, - L_PE = 277, - L_DE = 278, - L_MOE = 279, - L_MUE = 280, - L_POWE = 281, - L_AND = 282, - L_OR = 283, - L_NE = 284, - L_EQ = 285, - L_MINUS = 286, - L_PLUS = 287, - L_GE = 288, - L_LE = 289, - L_GT = 290, - L_LT = 291, - L_MOD = 292, - L_DIV = 293, - L_MUL = 294, - L_POW = 295, - L_DEREF = 296, - L_DEC = 297, - L_INC = 298, - L_NOT = 299, - L_NEG = 300, - L_TYPECAST = 301 + L_FOR = 263, + L_CONTINUE = 264, + L_BREAK = 265, + L_DATA_TYPE = 266, + L_IDENTIFIER = 267, + L_STRING = 268, + L_INTEGER = 269, + L_OPEN_MAPPING = 270, + L_CLOSE_MAPPING = 271, + L_OPEN_ARRAY = 272, + L_CLOSE_ARRAY = 273, + L_OPEN_FUNP = 274, + L_CLOSE_FUNP = 275, + L_ASSIGN = 276, + L_ME = 277, + L_PE = 278, + L_DE = 279, + L_MOE = 280, + L_MUE = 281, + L_POWE = 282, + L_AND = 283, + L_OR = 284, + L_NE = 285, + L_EQ = 286, + L_MINUS = 287, + L_PLUS = 288, + L_GE = 289, + L_LE = 290, + L_GT = 291, + L_LT = 292, + L_MOD = 293, + L_DIV = 294, + L_MUL = 295, + L_POW = 296, + L_DEREF = 297, + L_DEC = 298, + L_INC = 299, + L_NOT = 300, + L_NEG = 301, + L_TYPECAST = 302 }; #endif #define L_RETURN 258 @@ -80,45 +81,46 @@ #define L_ELSE 260 #define L_DO 261 #define L_WHILE 262 -#define L_CONTINUE 263 -#define L_BREAK 264 -#define L_DATA_TYPE 265 -#define L_IDENTIFIER 266 -#define L_STRING 267 -#define L_INTEGER 268 -#define L_OPEN_MAPPING 269 -#define L_CLOSE_MAPPING 270 -#define L_OPEN_ARRAY 271 -#define L_CLOSE_ARRAY 272 -#define L_OPEN_FUNP 273 -#define L_CLOSE_FUNP 274 -#define L_ASSIGN 275 -#define L_ME 276 -#define L_PE 277 -#define L_DE 278 -#define L_MOE 279 -#define L_MUE 280 -#define L_POWE 281 -#define L_AND 282 -#define L_OR 283 -#define L_NE 284 -#define L_EQ 285 -#define L_MINUS 286 -#define L_PLUS 287 -#define L_GE 288 -#define L_LE 289 -#define L_GT 290 -#define L_LT 291 -#define L_MOD 292 -#define L_DIV 293 -#define L_MUL 294 -#define L_POW 295 -#define L_DEREF 296 -#define L_DEC 297 -#define L_INC 298 -#define L_NOT 299 -#define L_NEG 300 -#define L_TYPECAST 301 +#define L_FOR 263 +#define L_CONTINUE 264 +#define L_BREAK 265 +#define L_DATA_TYPE 266 +#define L_IDENTIFIER 267 +#define L_STRING 268 +#define L_INTEGER 269 +#define L_OPEN_MAPPING 270 +#define L_CLOSE_MAPPING 271 +#define L_OPEN_ARRAY 272 +#define L_CLOSE_ARRAY 273 +#define L_OPEN_FUNP 274 +#define L_CLOSE_FUNP 275 +#define L_ASSIGN 276 +#define L_ME 277 +#define L_PE 278 +#define L_DE 279 +#define L_MOE 280 +#define L_MUE 281 +#define L_POWE 282 +#define L_AND 283 +#define L_OR 284 +#define L_NE 285 +#define L_EQ 286 +#define L_MINUS 287 +#define L_PLUS 288 +#define L_GE 289 +#define L_LE 290 +#define L_GT 291 +#define L_LT 292 +#define L_MOD 293 +#define L_DIV 294 +#define L_MUL 295 +#define L_POW 296 +#define L_DEREF 297 +#define L_DEC 298 +#define L_INC 299 +#define L_NOT 300 +#define L_NEG 301 +#define L_TYPECAST 302 @@ -135,7 +137,7 @@ def_id_t *id; } YYSTYPE; /* Line 1240 of yacc.c. */ -#line 139 "lang.h" +#line 141 "lang.h" # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 Index: lang.y =================================================================== RCS file: /cvsroot/agd/server/src/lang.y,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- lang.y 21 Mar 2004 13:26:17 -0000 1.12 +++ lang.y 21 Mar 2004 14:06:36 -0000 1.13 @@ -42,7 +42,7 @@ } /* keywords */ -%token L_RETURN L_IF L_ELSE L_DO L_WHILE +%token L_RETURN L_IF L_ELSE L_DO L_WHILE L_FOR %token L_CONTINUE L_BREAK /* operands */ @@ -85,7 +85,7 @@ %type <arr> call_args call_arg_list %type <expr> expr optional_expr range_expr -%type <arr> return if else do_while while break continue +%type <arr> return if else do_while while for break continue %type <arr> fun_call call_other %type <arr> statements statement %type <arr> block block_or_semi @@ -433,6 +433,11 @@ init_array(&$$); array_concat(&$$, &$1); } + | for + { + init_array(&$$); + array_concat(&$$, &$1); + } | break ';' { if(!break_allowed) { @@ -1392,10 +1397,49 @@ array_concat(&$$, &$6); array_push(&$$, (void *) F_JMP); array_push(&$$, (void *) -($6.length + $4.arr.length + 3)); - break_allowed = continue_allowed = 1; + break_allowed = continue_allowed = 0; } ; +for: + L_FOR '(' expr ';' expr ';' expr ')' + { + break_allowed = continue_allowed = 1; + } + statement + { + int i; + for(i=0;i<$10.length;i++) { + if((int)$10.data[i] == F_BREAK) { + $10.data[i] = (void *) F_JMP; + i++; + $10.data[i] = (void *) $10.length + $7.arr.length - i - 1; + } else if((int)$10.data[i] == F_CONTINUE) { + $10.data[i] = (void *) F_JMP; + i++; + $10.data[i] = (void *) -(i + $5.arr.length + 5); + } + } + + init_array(&$$); + /* first expr. */ + array_concat(&$$, &$3.arr); + /* condition expr. */ + array_concat(&$$, &$5.arr); + array_push(&$$, (void *) F_JMPF); + array_push(&$$, (void *) ($7.arr.length + $10.length + 3)); + + /* Third expression - after every loop. */ + array_concat(&$$, &$7.arr); + /* Statements. */ + array_concat(&$$, &$10); + array_push(&$$, (void *) F_JMP); + array_push(&$$, (void *) -($10.length + $7.arr.length + + $5.arr.length + 3)); + break_allowed = continue_allowed = 0; + + } + ; + break: L_BREAK { Index: lex.l =================================================================== RCS file: /cvsroot/agd/server/src/lex.l,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- lex.l 21 Mar 2004 13:26:17 -0000 1.10 +++ lex.l 21 Mar 2004 14:06:36 -0000 1.11 @@ -257,6 +257,7 @@ [0-9]+K yylval.i = atoi(yytext) * 1024; RET(d, yylval.i, L_INTEGER); [0-9]+M yylval.i = atoi(yytext) * 1048576; RET(d, yylval.i, L_INTEGER); [0-9]+ yylval.i = atoi(yytext); RET(d, yylval.i, L_INTEGER); + return RET(s, "return", L_RETURN); if RET(s, "if", L_IF); else RET(s, "else", L_ELSE); @@ -264,6 +265,8 @@ while RET(s, "while", L_WHILE); break RET(s, "break", L_BREAK); continue RET(s, "continue", L_CONTINUE); +for RET(s, "for", L_FOR); + void yylval.i = T_VOID; RET(s, "void", L_DATA_TYPE); int yylval.i = T_INT; RET(s, "int", L_DATA_TYPE); string yylval.i = T_STRING; RET(s, "string", L_DATA_TYPE); |