rev 364 - in trunk: . src

SVN User <[email protected]>
Newsgroups gmane.comp.lang.prothon.cvs
Message-ID <[email protected]>
Author: mark
Date: 2004-04-15 22:08:08 -0400 (Thu, 15 Apr 2004)
New Revision: 364

Modified:
   trunk/STATUS.txt
   trunk/src/parser.h
   trunk/src/parser_routines.c
   trunk/src/prothon.y
Log:
added list comprehensions to parser

Modified: trunk/STATUS.txt
===================================================================
--- trunk/STATUS.txt	2004-04-15 22:07:03 UTC (rev 363)
+++ trunk/STATUS.txt	2004-04-16 02:08:08 UTC (rev 364)
@@ -6,6 +6,8 @@
 --- add support for APR_BINARY in File.c ('b' flag)
 --- support any object that supports file methods in stdxxx (duck std)
 
+--- finish Prosist
+
 --- help() in interactive console()
 
 --- -d -m -l cmd-line options missing

Modified: trunk/src/parser.h
===================================================================
--- trunk/src/parser.h	2004-04-15 22:07:03 UTC (rev 363)
+++ trunk/src/parser.h	2004-04-16 02:08:08 UTC (rev 364)
@@ -164,9 +164,10 @@
 code_p expr_to_slice(void* param, code_p expr);
 code_p expr_to_sparm(void* param, code_p p1);
 code_p float_to_obj(void* param, double num, int imag_flag);
-code_p for_tgt_in_expr_body_else(void* param, clist_p locals, code_p expr, code_p body, code_p els);
+code_p expr_for_lcc_to_listcomp(void* param, code_p expr, clist_p forlst, clist_p lcc);
+code_p for_lcc_body_else(void* param, clist_p locals, code_p body, code_p els);
 code_p from_path_import_params(void* param, clist_p path, clist_p iparms);
-code_p if_expr_body_elif_else(void* param, code_p ifex, code_p body, clist_p elif, code_p els);
+code_p if_expr_body_elif_else(void* param, clist_p ifex_list, code_p body, clist_p elif, code_p els);
 code_p import_params(void* param, clist_p iparms);
 code_p int_to_obj(void* param, i64_t num);
 code_p label_eq_expr_to_formparm(void* param, char* label, code_p expr);

Modified: trunk/src/parser_routines.c
===================================================================
--- trunk/src/parser_routines.c	2004-04-15 22:07:03 UTC (rev 363)
+++ trunk/src/parser_routines.c	2004-04-16 02:08:08 UTC (rev 364)
@@ -678,9 +678,10 @@
 	res->code_data[(*k)++].bytecode.param  = 1;
 }
 
-code_p if_expr_body_elif_else(void* param, code_p ifex, code_p body, clist_p elif, code_p els){
+code_p if_expr_body_elif_else(void* param, clist_p ifex_list, code_p body, clist_p elif, code_p els) {
 	int i, k=0, len=0, stack_depth=0, max_stack_depth=0;
 	code *res;
+	code_p ifex = clist_item(ifex_list, 0);
 	calc_code(ifex, &len, &stack_depth, &max_stack_depth);
 	len += SKIP_CODE1_LEN;
 	calc_code(body, &len, &stack_depth, &max_stack_depth);
@@ -752,10 +753,15 @@
 clist_p label_to_forrefs(void* param, char* label1, char* label2){
 	return new_clist_2(label1, label2);
 }
-code_p for_tgt_in_expr_body_else(void* param, clist_p locals, code_p expr, code_p body, code_p els){
+code_p expr_for_lcc_to_listcomp(void* param, code_p expr, clist_p forlst, clist_p lcc) {
+	return debug_retrn(__LINE__, expr);
+}
+
+code_p for_lcc_body_else(void* param, clist_p locals, code_p body, code_p els){
 	code *res;
 	int i, k=0, len=0, stack_depth=0, max_stack_depth=0;
-	int llen = clist_len(locals), loop_loc, body_loc, els_loc, end_els_loc, end_loc;
+	int llen = clist_len(locals)-1, loop_loc, body_loc, els_loc, end_els_loc, end_loc;
+	code_p expr = clist_item(locals, llen);
 	patch_break_continues(clist_item(locals,0), body);
 	for (i=1; i < llen; i++){
 		char* s = (char*)clist_item(locals,i);

Modified: trunk/src/prothon.y
===================================================================
--- trunk/src/prothon.y	2004-04-15 22:07:03 UTC (rev 363)
+++ trunk/src/prothon.y	2004-04-16 02:08:08 UTC (rev 364)
@@ -199,19 +199,22 @@
 					function_params brace_params brace_params2 brace_param mul_except
 					ass_expr_list formal_params elif mul_elif list_params list_params2
 					for_refs for_refs1 for_refs2 arg_list arg_list2 tuple_params tuple_params2
+					for_lc_clause lc_clauses if_lc_clause
 
 %type <code_type> 	statement_block statement mul_statement mul_statements compound_statement
-			expr obj assignment_statement assignment_statement2 def_statement
-			import_statement small_statement if_statement while_statement
-			for_statement gen_ref try_except_statement except else_except
-			try_finally_statement def_ref print_statement assert_statement
-			target_param attr_ref unbound_ref ass_add_statement ass_sub_statement ass_mul_statement
-			ass_div_statement  ass_tdv_statement ass_rem_statement
-			ass_band_statement ass_bor_statement ass_bxor_statement
-			ass_shr_statement  ass_shl_statement ass_exp_statement
-			compound_body else slice slice_param formal_param is_not_check
-			function_param break_statement return_statement yield_statement with_statement
-			continue_statement del_statement del_tgt exec_statement raise_statement
+					expr obj assignment_statement assignment_statement2 def_statement
+					import_statement small_statement if_statement while_statement
+					for_statement gen_ref try_except_statement except else_except
+					try_finally_statement def_ref print_statement assert_statement
+					target_param attr_ref unbound_ref ass_add_statement ass_sub_statement ass_mul_statement
+					ass_div_statement  ass_tdv_statement ass_rem_statement
+					ass_band_statement ass_bor_statement ass_bxor_statement
+					ass_shr_statement  ass_shl_statement ass_exp_statement
+					compound_body else slice slice_param formal_param is_not_check
+					function_param break_statement return_statement yield_statement with_statement
+					continue_statement del_statement del_tgt exec_statement raise_statement
+					if_statement for_statement list_comp
+
 					
 					
 /* Grammar */
@@ -253,7 +256,7 @@
    	    PASS														{ $$ = none(yylex_param); }
 	;
 if_statement: 
-		IF expr compound_body mul_elif else							{ $$ = if_expr_body_elif_else(yylex_param, $2, $3, $4, $5); }
+		if_lc_clause compound_body mul_elif else					{ $$ = if_expr_body_elif_else(yylex_param, $1, $2, $3, $4); }
 	;
 mul_elif:
 		/* empty string */											{ $$ = empty_list(yylex_param); }
@@ -266,18 +269,29 @@
 		/* empty string */											{ $$ = none(yylex_param); }
 	|	ELSE compound_body 											{ $$ = $2; }
 	;
-
 while_statement: 
 		WHILE expr compound_body else
 		{ $$ = while_expr_body_else(yylex_param, "~", $2, $3, $4); }
 	|	LABEL ':' WHILE expr compound_body
 		{ $$ = while_expr_body_else(yylex_param, $1, $4, $5, NULL); }
 	;
-
 for_statement: 
-		for_refs IN_ expr compound_body else
-		{ $$ = for_tgt_in_expr_body_else(yylex_param, $1, $3, $4, $5); }
+		for_lc_clause compound_body else							{ $$ = for_lcc_body_else(yylex_param, $1, $2, $3); }
 	;
+list_comp:
+		'[' expr for_lc_clause lc_clauses ']'						{ $$ = expr_for_lcc_to_listcomp(yylex_param, $2, $3, $4); }
+	;
+lc_clauses:
+		/* empty string */											{ $$ = empty_list(yylex_param); }
+	|   lc_clauses if_lc_clause										{ $$ = append_list_list(yylex_param, $1, $2); }
+	|   lc_clauses for_lc_clause									{ $$ = append_list_list(yylex_param, $1, $2); }
+	;
+if_lc_clause:
+		IF expr														{ $$ = new_list(yylex_param, $2); }
+	;
+for_lc_clause:
+		for_refs IN_ expr											{ $$ = append_list(yylex_param, $1, $3); }
+	;
 for_refs:
 		for_refs1
 	|	for_refs2 ')'
@@ -503,6 +517,7 @@
 	| 	'-' expr 							%prec UMI				{ $$ = unary(yylex_param, __NEG__, $2); }
 	| 	'~' expr      												{ $$ = unary(yylex_param, __INV__, $2); }
 	| 	expr EXP expr												{ $$ = binary(yylex_param, $1, __POW__, $3); }
+	|   list_comp
 	|	obj
 	;
 obj:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.