Changeset d76127 in git
- Timestamp:
- May 1, 2000, 9:17:32 PM (23 years ago)
- Branches:
- (u'spielwiese', 'f6c3dc58b0df4bd712574325fe76d0626174ad97')
- Children:
- 8c8a76ef1d90b953025a5f8cefe0723f9fe5cb82
- Parents:
- 172cdfc80c3ad17a576a439c847fa830ffac37e6
- Location:
- modules/modgen
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
modules/modgen/grammar.y
r172cdf rd76127 1 1 /* 2 * $Id: grammar.y,v 1.1 2 2000-04-17 07:21:24krueger Exp $2 * $Id: grammar.y,v 1.13 2000-05-01 19:14:48 krueger Exp $ 3 3 */ 4 4 … … 23 23 extern int yylineno; 24 24 extern int do_create_makefile; 25 extern char *sectname[]; 25 26 26 27 extern int init_modgen(moddef *module_def, char *filename); … … 57 58 58 59 %token SECTEND 60 /* SECT2: Singular procedure declaration */ 61 %token SECT2START 59 62 %token SECT2END 63 /* SECT3: procedure declaration */ 64 %token SECT3START 60 65 %token SECT3END 66 /* SECT4: C/C++ text */ 67 %token SECT4START 68 %token SECT4END 69 61 70 /*%token PROCEND*/ 62 71 %token PROCDECLTOK … … 74 83 %token <name> MCODETOK 75 84 %token <name> CODEPART 85 %token <name> CMTPART 76 86 %token <name> PROCCMD 77 87 %token <name> ANYTOK … … 85 95 %nonassoc '=' 86 96 %% 87 goal: part1 sect 2 sect2end code88 89 if(trace)printf("Finish modules \n");97 goal: part1 sect3 sect3end sect4 98 { 99 if(trace)printf("Finish modules 1\n"); 90 100 return 0; 91 } 101 } 102 | part1 sect3full sect4 103 { 104 if(trace)printf("Finish modules 2\n"); 105 return 0; 106 } 107 | part1 sect2full sect3full sect4 108 { 109 if(trace)printf("Finish modules 3\n"); 110 return 0; 111 } 112 | part1 sect3full sect2full sect4 113 { 114 if(trace)printf("Finish modules 4\n"); 115 return 0; 116 } 92 117 ; 93 118 … … 134 159 { 135 160 memset(&procedure_decl, 0, sizeof(procdef)); 136 if(debug>2)printf("End of section %d\n", sectnum-1);161 if(debug>2)printf("End of section 1 (new=%d)\n", sectnum); 137 162 } 138 163 ; … … 158 183 } 159 184 break; 160 case 2: /* pass 2: procedure declaration */185 case 3: /* pass 3: procedure declaration */ 161 186 if( (vt=checkvar($1, VAR_STRING, &write_cmd)) ) { 162 187 proc_set_var(&procedure_decl, VAR_STRING, vt, $1, $3.string); … … 182 207 Add2files(&module_def, $3); 183 208 break; 184 case 2: /* pass 2: procedure declaration */209 case 3: /* pass 3: procedure declaration */ 185 210 if( (vt=checkvar($1, VAR_FILE, &write_cmd)) ) { 186 211 proc_set_var(&procedure_decl, VAR_FILE, vt, $1, $3); … … 200 225 case 1: /* pass 1: */ 201 226 break; 202 case 2: /* pass 2: procedure declaration */227 case 3: /* pass 3: procedure declaration */ 203 228 if( (vt=checkvar($1, VAR_FILES, &write_cmd)) ) { 204 229 proc_set_var(&procedure_decl, VAR_FILES, vt, $1, &$3); … … 218 243 case 1: /* pass 1: */ 219 244 break; 220 case 2: /* pass 2: procedure declaration */245 case 3: /* pass 3: procedure declaration */ 221 246 if( (vt=checkvar($1, VAR_NUM, &write_cmd)) ) { 222 247 proc_set_var(&procedure_decl, VAR_NUM, vt, $1, &$3); … … 244 269 } 245 270 break; 246 case 2: /* pass 2: procedure declaration */271 case 3: /* pass 3: procedure declaration */ 247 272 if( (vt=checkvar($1, VAR_BOOL, &write_cmd)) ) { 248 273 proc_set_var(&procedure_decl, VAR_BOOL, vt, $1, &$3); … … 271 296 ; 272 297 273 sect2: procdef 274 | sect2 procdef 275 ; 298 sect2full: SECT2START sect2 sect2end; 299 300 sect2: procdefsg 301 | sect2 procdefsg 302 ; 276 303 277 304 sect2end: SECT2END 305 { 306 if(debug>2)printf("End of section 'Singular' 2 (%d)\n", 307 sectnum); 308 }; 309 310 311 sect3full: SECT3START sect3 sect3end; 312 313 sect3: procdef 314 | sect3 procdef 315 ; 316 317 sect3end: SECT3END 278 318 { 279 319 write_finish_functions(&module_def, &procedure_decl); 280 if(debug>2)printf("End of section %d\n", sectnum-1); 320 if(debug>2)printf("End of section 'procedures' 3 (%d)\n", 321 sectnum); 281 322 } 282 323 ; … … 284 325 /* 285 326 */ 286 procdef : procdeclproccode287 { 288 if(debug>2)printf(" PROCDEF:\n");327 procdefsg: procdeclsg proccode 328 { 329 if(debug>2)printf("SG-PROCDEF:\n"); 289 330 } 290 331 | procdecl proccode procdeclexample 291 332 { 292 if(debug>2)printf(" PROCDEF mit example:\n");333 if(debug>2)printf("SG-PROCDEF mit example:\n"); 293 334 fflush(module_def.fmtfp); 294 335 } 295 296 297 procdecl : procdecl2 '{'336 ; 337 338 procdeclsg: procdeclsg2 '{' 298 339 { 299 340 setup_proc(&module_def, &procedure_decl); 300 341 } 301 | procdecl 2 procdeclhelp '{'342 | procdeclsg2 procdeclhelp '{' 302 343 { 303 344 setup_proc(&module_def, &procedure_decl); … … 305 346 ; 306 347 307 procdecl1: PROCDECLTOK NAME 308 { 309 init_proc(&procedure_decl, $2, NULL, yylineno, LANG_SINGULAR); 310 free($2); 311 if(write_singular_procedures(&module_def, &procedure_decl)) 312 return(myyyerror("Error while creating bin-file\n")); 313 } 314 | STATICTOK PROCDECLTOK NAME 315 { 316 init_proc(&procedure_decl, $3, NULL, yylineno, LANG_SINGULAR); 317 procedure_decl.is_static = TRUE; 318 free($3); 319 if(write_singular_procedures(&module_def, &procedure_decl)) 320 return(myyyerror("Error while creating bin-file\n")); 321 }; 322 323 procdecl2: procdecl1 '(' sgtypelist ')' 324 | funcdecl1 325 | funcdecl1 '(' ')' 326 | funcdecl1 '(' typelist ')' 348 procdeclsg2: procdecl1 '(' sgtypelist ')' 349 { 350 write_singular_parameter(&module_def, yylineno, "list", "#"); 351 procedure_decl.lineno_other = yylineno; 352 } 327 353 | procdecl1 328 354 { … … 337 363 ; 338 364 339 funcdecl1: NAME 340 { 341 if(debug>2)printf("funcdecl1-1\n"); 342 init_proc(&procedure_decl, $1, NULL, yylineno); 343 free($1); 344 } 345 | VARTYPETOK NAME 365 procdecl1: PROCDECLTOK NAME 366 { 367 init_proc(&procedure_decl, $2, NULL, yylineno, LANG_SINGULAR); 368 free($2); 369 if(write_singular_procedures(&module_def, &procedure_decl)) 370 return(myyyerror("Error while creating bin-file\n")); 371 } 372 | STATICTOK PROCDECLTOK NAME 373 { 374 init_proc(&procedure_decl, $3, NULL, yylineno, LANG_SINGULAR); 375 procedure_decl.is_static = TRUE; 376 free($3); 377 if(write_singular_procedures(&module_def, &procedure_decl)) 378 return(myyyerror("Error while creating bin-file\n")); 379 }; 380 381 procdef: procdecl proccode 382 { 383 if(debug>2)printf("PROCDEF:\n"); 384 } 385 | procdecl proccode procdeclexample 386 { 387 if(debug>2)printf("PROCDEF mit example:\n"); 388 fflush(module_def.fmtfp); 389 } 390 ; 391 392 procdecl: procdecl2 '{' 393 { 394 setup_proc(&module_def, &procedure_decl); 395 } 396 | procdecl2 procdeclhelp '{' 397 { 398 setup_proc(&module_def, &procedure_decl); 399 } 400 ; 401 402 procdecl2: funcdecl1 403 | funcdecl1 '(' ')' 404 | funcdecl1 '(' typelist ')'; 405 406 funcdecl1: VARTYPETOK NAME 346 407 { 347 408 if(debug>2)printf("funcdecl1-2\n"); 348 409 init_proc(&procedure_decl, $2, &$1, yylineno); 349 410 free($2); 350 }351 | STATICTOK NAME352 {353 if(debug>2)printf("funcdecl1-3\n");354 init_proc(&procedure_decl, $2, NULL, yylineno);355 free($2);356 procedure_decl.is_static = TRUE;357 411 } 358 412 | STATICTOK VARTYPETOK NAME … … 382 436 proccodeline: CODEPART 383 437 { 438 printf(">>>>(%d) %s<<<<\n", procedure_decl.flags.start_of_code, $1); 384 439 write_codeline(&module_def, &procedure_decl, $1, yylineno-1); 385 440 } 386 441 | proccodeline CODEPART 387 442 { 443 printf(">>>>(%d) %s<<<<\n", procedure_decl.flags.start_of_code, $2); 444 write_codeline(&module_def, &procedure_decl, $2); 445 } 446 | proccodeline CMTPART 447 { 448 printf(">>>>(%d) %s<<<<\n", procedure_decl.flags.start_of_code, $2); 388 449 write_codeline(&module_def, &procedure_decl, $2); 389 450 } … … 445 506 yylineno, $2, sectnum)); 446 507 break; 508 509 case CMD_DECL: 510 case CMD_CHECK: 511 procedure_decl.flags.auto_header = 0; 512 case CMD_NODECL: 513 write_cmd(&module_def, &procedure_decl); 514 break; 515 447 516 default: 517 write_function_header(&module_def, &procedure_decl); 448 518 write_cmd(&module_def, &procedure_decl); 449 519 } … … 465 535 break; 466 536 default: 467 write_cmd(&module_def, &procedure_decl, 468 procedure_decl.procname); 537 write_function_header(&module_def, &procedure_decl); 538 case CMD_DECL: 539 case CMD_CHECK: 540 write_cmd(&module_def, &procedure_decl); 469 541 } 470 542 free($2); … … 485 557 break; 486 558 default: 559 write_function_header(&module_def, &procedure_decl); 560 case CMD_DECL: 561 case CMD_CHECK: 487 562 write_cmd(&module_def, &procedure_decl, $4); 488 563 } … … 504 579 break; 505 580 default: 581 write_function_header(&module_def, &procedure_decl); 582 case CMD_DECL: 583 case CMD_CHECK: 506 584 write_cmd(&module_def, &procedure_decl, $4); 507 585 } … … 523 601 break; 524 602 default: 603 write_function_header(&module_def, &procedure_decl); 604 case CMD_DECL: 605 case CMD_CHECK: 525 606 write_cmd(&module_def, &procedure_decl, $4); 526 607 } … … 607 688 ; 608 689 609 code: codeline SECT3END 610 { 611 fprintf(module_def.modfp, "%s", $1); 612 } 613 ; 690 sect4: SECT4START codeline SECT4END 691 { 692 fprintf(module_def.modfp, "'%s'", $2); 693 }; 614 694 615 695 codeline: CODEPART -
modules/modgen/misc.cc
r172cdf rd76127 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: misc.cc,v 1. 9 2000-03-30 06:35:45krueger Exp $ */4 /* $Id: misc.cc,v 1.10 2000-05-01 19:17:32 krueger Exp $ */ 5 5 /* 6 6 * ABSTRACT: lib parsing … … 187 187 } valid_cmds[] = { 188 188 { "declaration", write_function_declaration, CMD_DECL, CMDT_SINGLE, 0 }, 189 { "error", write_function_error, CMD_ERROR, CMDT_ANY, 0 }, 190 { "nodeclaration",write_function_nodecl, CMD_NODECL, CMDT_SINGLE, 0 }, 189 191 { "typecheck", write_function_typecheck, CMD_CHECK, CMDT_SINGLE, 0 }, 190 191 192 //{ "return", write_function_result, CMD_RETURN, CMDT_EQ, 0 }, 193 //{ "return", write_function_return, CMD_RETURN, CMDT_SINGLE, 1 }, 192 194 { "return", write_function_return, CMD_RETURN, CMDT_0, 1 }, 193 195 { "return", write_function_return, CMD_RETURN, CMDT_ANY, 1 }, … … 225 227 idtyp t, void *arg1 = NULL, void *arg2 = NULL); 226 228 } valid_vars[] = { 227 { "module", VAR_STRING, VAR_MODULE, 0 }, 229 { "help", VAR_STRING, VAR_HELP, write_main_variable }, 230 { "info", VAR_STRING, VAR_INFO, write_main_variable }, 231 { "package", VAR_STRING, VAR_MODULE, 0 }, 228 232 { "version", VAR_STRING, VAR_VERSION, write_main_variable }, 229 { "info", VAR_STRING, VAR_INFO, write_main_variable },230 { "help", VAR_STRING, VAR_HELP, write_main_variable },231 #if 0232 { "do_typecheck", VAR_BOOL, VAR_TYPECHECK },233 #endif234 233 { NULL, VAR_UNKNOWN, VAR_NONE, 0 } 235 234 }; … … 280 279 printf(")\n"); 281 280 if(pi->return_val.typ!=0) 282 printf("\treturn = %s (%s)\n", pi->return_val.name, pi->return_val.typname); 281 printf("\treturn = %s (%s)\n", pi->return_val.name, 282 pi->return_val.typname); 283 283 printf("{%s}\n", pi->c_code); 284 284 } … … 443 443 444 444 default: 445 fprintf(module->fmtfp, " res->rtyp = %s;\n", pi->return_val.typname); 446 fprintf(module->fmtfp, " res->data = (void *)%s();\n", pi->funcname); 445 fprintf(module->fmtfp, " res->rtyp = %s;\n", 446 pi->return_val.typname); 447 fprintf(module->fmtfp, " res->data = (void *)%s();\n", 448 pi->funcname); 447 449 fprintf(module->fmtfp, " return FALSE;"); 448 450 } … … 521 523 { 522 524 strcpy(type_conv[NONE], "none"); 523 strcpy(type_conv[NONE], "void");525 // strcpy(type_conv[NONE], "void"); 524 526 strcpy(type_conv[INT_CMD], "int"); 525 527 strcpy(type_conv[RING_CMD], "ring"); -
modules/modgen/modgen.h
r172cdf rd76127 1 1 /* 2 * $Id: modgen.h,v 1.1 1 2000-03-30 06:36:10krueger Exp $2 * $Id: modgen.h,v 1.12 2000-05-01 19:14:48 krueger Exp $ 3 3 * 4 4 */ … … 33 33 class procflags { 34 34 public: 35 char start_of_code; 35 36 char declaration_done; 36 37 char typecheck_done; 37 38 39 char auto_header; 40 char do_declaration; 38 41 char do_typecheck; 39 42 char do_return; … … 110 113 111 114 typedef enum { CMD_NONE, CMD_BADSYNTAX, CMD_DECL, CMD_CHECK, CMD_RETURN, 112 CMD_SINGULAR 115 CMD_SINGULAR, CMD_ERROR, CMD_NODECL 113 116 } cmd_token; 114 117 … … 127 130 extern int debug; 128 131 extern int trace; 132 extern int xyz; 129 133 130 134 extern int IsCmd(char *n, int & tok); … … 173 177 174 178 /* from proc.cc */ 179 extern void write_function_header(moddefv module, procdefv proc); 175 180 extern void write_procedure_typecheck(moddefv module, procdefv pi, FILE *fmtfp); 176 181 extern void write_procedure_return(moddefv module, procdefv pi, FILE *fmtfp); 177 182 extern void write_function_declaration(moddefv module, procdefv pi, void *arg = NULL); 183 extern void write_function_nodecl(moddefv module, procdefv pi, void *arg = NULL); 184 extern void write_function_error(moddefv module, procdefv pi, void *arg = NULL); 178 185 extern void write_function_typecheck(moddefv module, procdefv pi, void *arg = NULL); 179 186 extern void write_function_result(moddefv module, procdefv pi, void *arg = NULL); -
modules/modgen/proc.cc
r172cdf rd76127 1 1 /* 2 * $Id: proc.cc,v 1.1 2 2000-03-30 06:35:45krueger Exp $2 * $Id: proc.cc,v 1.13 2000-05-01 19:14:48 krueger Exp $ 3 3 */ 4 4 … … 80 80 81 81 /*========================================================================*/ 82 void write_function_header( 83 moddefv module, 84 procdefv proc 85 ) 86 { 87 if(!proc->flags.auto_header) return; 88 if(!proc->flags.start_of_code) return; 89 90 if(debug>4) { 91 printf("write_function_header: auto=%d\n", proc->flags.auto_header); 92 printf("write_function_header: declaration: do=%d, done=%d\n", 93 proc->flags.do_declaration, 94 proc->flags.declaration_done); 95 printf("write_function_header: typecheck: do=%d, done=%d\n", 96 proc->flags.do_typecheck, 97 proc->flags.typecheck_done); 98 } 99 100 if(proc->flags.do_declaration && !proc->flags.declaration_done) 101 write_function_declaration(module, proc, module->fmtfp); 102 103 if(proc->flags.do_typecheck && !proc->flags.typecheck_done) 104 write_function_typecheck(module, proc, module->fmtfp); 105 } 106 107 /*========================================================================*/ 82 108 /* 83 109 * write declaration of function to file pointed by 'fp', usualy the … … 116 142 { 117 143 int i; 144 if(debug>4) printf("write_function_declaration: do=%d, done=%d\n", 145 pi->flags.do_declaration, pi->flags.declaration_done); 146 if(pi->flags.declaration_done) return; 147 if(!pi->flags.do_declaration) return; 118 148 if(pi->paramcnt>0) { 119 149 fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename); 120 150 fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name); 121 fprintf(module->fmtfp, " leftv v = h,v_save;\n");122 fprintf(module->fmtfp, " int tok = NONE,index = 0;\n");151 fprintf(module->fmtfp, " leftv __v = __h, __v_save;\n"); 152 fprintf(module->fmtfp, " int __tok = NONE, __index = 0;\n"); 123 153 for (i=0;i<pi->paramcnt; i++) { 124 154 fprintf(module->fmtfp, 125 " sleftv s%s; leftv z%s = &s%s;\n", pi->param[i].varname,155 " sleftv __s%s; leftv __z%s = &__s%s;\n", pi->param[i].varname, 126 156 pi->param[i].varname, pi->param[i].varname); 127 157 fprintf(module->fmtfp, " %s %s;\n", type_conv[pi->param[i].typ], … … 131 161 fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename); 132 162 fprintf(module->fmtfp, "\n"); 133 pi->flags.declaration_done = 1; 134 } 163 } 164 pi->flags.declaration_done = 1; 165 } 166 167 /*========================================================================*/ 168 void write_function_nodecl( 169 moddefv module, 170 procdefv pi, 171 void *arg 172 ) 173 { 174 pi->flags.do_declaration = 0; 175 pi->flags.do_typecheck = 0; 176 pi->flags.auto_header = 0; 177 } 178 179 /*========================================================================*/ 180 void write_function_error( 181 moddefv module, 182 procdefv pi, 183 void *arg 184 ) 185 { 186 int i; 187 188 fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename); 189 fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name); 190 fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename); 191 fprintf(module->fmtfp, "\n"); 135 192 } 136 193 … … 142 199 ) 143 200 { 201 if(debug>4) printf("write_function_typecheck: do=%d, done=%d\n", 202 pi->flags.do_typecheck, pi->flags.typecheck_done); 203 if(pi->flags.typecheck_done) return; 204 if(!pi->flags.do_typecheck) return; 205 144 206 fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename); 145 207 fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name); … … 178 240 switch( pi->return_val.typ) { 179 241 case SELF_CMD: 180 fprintf(module->modfp_h, "BOOLEAN %s( res, ", pi->funcname);242 fprintf(module->modfp_h, "BOOLEAN %s(__res, ", pi->funcname); 181 243 break; 182 244 … … 192 254 fprintf(module->modfp_h, ");\n\n"); 193 255 } 194 else if(debug>2)printf("CMD: return()\n"); 195 256 else { 257 if(debug>2)printf("CMD: return()\n"); 258 } 259 196 260 fprintf(module->fmtfp, "#line %d \"%s\"\n", yylineno, module->filename); 197 261 write_procedure_return(module, pi, module->fmtfp); … … 243 307 244 308 fprintf(fmtfp, "#line %d \"%s\"\n", pi->lineno, module->filename); 245 fprintf(fmtfp, "BOOLEAN mod_%s(leftv res, leftvh)\n{\n", pi->procname);309 fprintf(fmtfp, "BOOLEAN mod_%s(leftv __res, leftv __h)\n{\n", pi->procname); 246 310 } 247 311 … … 274 338 for (i=0;i<pi->paramcnt; i++) gen_func_param_check(fmtfp, pi, i); 275 339 276 fprintf(fmtfp, " if(v!=NULL) { tok = v->Typ(); goto mod_%s_error; }\n", 340 fprintf(fmtfp, 341 " if(__v!=NULL) { __tok = __v->Typ(); goto mod_%s_error; }\n", 277 342 pi->procname); 278 343 … … 315 380 fprintf(module->modfp, "#line %d \"%s.cc\"\n", modlineno++, module->name); 316 381 if(trace)printf(" done.\n");fflush(stdout); 317 fclose(module->fmtfp); 318 fclose(module->fmtfp2); 319 fclose(module->fmtfp3); 382 fclose(module->fmtfp); module->fmtfp = NULL; 383 fclose(module->fmtfp2); module->fmtfp2 = NULL; 384 fclose(module->fmtfp3); module->fmtfp3 = NULL; 320 385 return; 321 386 } … … 329 394 ) 330 395 { 331 fprintf(fp, " if( v==NULL) goto mod_%s_error;\n", pi->procname);332 fprintf(fp, " tok =v->Typ();\n");333 fprintf(fp, " if(( index=iiTestConvert(tok, %s))==0)\n",396 fprintf(fp, " if(__v==NULL) goto mod_%s_error;\n", pi->procname); 397 fprintf(fp, " __tok = __v->Typ();\n"); 398 fprintf(fp, " if((__index=iiTestConvert(__tok, %s))==0)\n", 334 399 pi->param[i].typname); 335 400 fprintf(fp, " goto mod_%s_error;\n", pi->procname); 336 fprintf(fp, " v_save =v->next;\n");337 fprintf(fp, " v->next = NULL;\n");338 fprintf(fp, " if(iiConvert( tok, %s, index, v,z%s))\n",401 fprintf(fp, " __v_save = __v->next;\n"); 402 fprintf(fp, " __v->next = NULL;\n"); 403 fprintf(fp, " if(iiConvert(__tok, %s, __index, __v, __z%s))\n", 339 404 pi->param[i].typname, pi->param[i].varname); 340 405 fprintf(fp, " goto mod_%s_error;\n", pi->procname); 341 fprintf(fp, " v =v_save;\n");342 fprintf(fp, " %s = (%s) z%s->Data();\n", pi->param[i].varname,406 fprintf(fp, " __v = __v_save;\n"); 407 fprintf(fp, " %s = (%s)__z%s->Data();\n", pi->param[i].varname, 343 408 type_conv[pi->param[i].typ], pi->param[i].varname); 344 409 … … 368 433 fprintf(module->fmtfp, "#line @d \"%s.cc\"\n", module->name); 369 434 if(pi->funcname == NULL) { 370 if(!pi->flags.result_done) fprintf(fmtfp, " res->data = NULL;\n");371 fprintf(fmtfp, " res->rtyp = %s;\n", pi->return_val.typname);435 if(!pi->flags.result_done) fprintf(fmtfp, " __res->data = NULL;\n"); 436 fprintf(fmtfp, " __res->rtyp = %s;\n", pi->return_val.typname); 372 437 //fprintf(fmtfp, " res->rtyp = NONE;\n"); 373 438 //fprintf(fmtfp, " res->data = NULL;\n"); … … 377 442 switch( pi->return_val.typ) { 378 443 case SELF_CMD: 379 fprintf(fmtfp, " return(%s( res", pi->funcname);444 fprintf(fmtfp, " return(%s(__res", pi->funcname); 380 445 for (i=0;i<pi->paramcnt; i++) 381 fprintf(fmtfp, ", (%s) %s->Data()",446 fprintf(fmtfp, ", (%s) __%s->Data()", 382 447 type_conv[pi->param[i].typ], pi->param[i].varname); 383 448 fprintf(fmtfp, "));\n\n"); … … 389 454 fprintf(fmtfp, " return(%s(", pi->funcname); 390 455 for (i=0;i<pi->paramcnt; i++) { 391 fprintf(fmtfp, "(%s) %s->Data()",456 fprintf(fmtfp, "(%s) __%s->Data()", 392 457 type_conv[pi->param[i].typ], pi->param[i].varname); 393 458 if(i<pi->paramcnt-1) fprintf(fmtfp, ", "); … … 551 616 552 617 case LANG_C: 618 write_function_header(module, proc); 553 619 if(lineno>=0) { 554 620 fprintf(module->fmtfp, "#line %d \"%s\"\n", -
modules/modgen/proc_setup.cc
r172cdf rd76127 1 1 /* 2 * $Id: proc_setup.cc,v 1. 5 2000-03-30 06:35:45krueger Exp $2 * $Id: proc_setup.cc,v 1.6 2000-05-01 19:14:49 krueger Exp $ 3 3 */ 4 4 … … 63 63 p->language = language; 64 64 p->lineno = lineno; 65 p->flags.auto_header = 1; 66 67 p->flags.do_declaration = 1; 68 p->flags.declaration_done = 0; 65 69 p->flags.do_typecheck = default_do_typecheck; 70 p->flags.typecheck_done = 0; 66 71 p->flags.do_return = default_do_return; 67 p->flags.declaration_done = 0;68 p->flags.typecheck_done = 0;69 72 70 73 return 0; -
modules/modgen/scanner.l
r172cdf rd76127 3 3 * Computer Algebra System SINGULAR * 4 4 ****************************************/ 5 /* $Id: scanner.l,v 1.1 1 2000-04-17 07:21:24krueger Exp $ */5 /* $Id: scanner.l,v 1.12 2000-05-01 19:14:49 krueger Exp $ */ 6 6 #include <stdio.h> 7 7 #include <string.h> … … 13 13 #include "grammar.h" 14 14 15 /* #define DEBUG 3 */ 15 #define DEBUG 3 16 16 17 17 # define YYLP_ERR_NONE 0 … … 40 40 41 41 extern int sectnum; 42 static int oldsectnum = 1; 42 43 extern moddef module_def; 43 44 extern procdef procedure_decl; 45 46 char *sectname[] = { "sect -0", "section 1", 47 "Singular", "procedures", "C-part" 48 }; 49 44 50 struct _states { 45 51 char name[32]; … … 56 62 void switch_state(int state, int new_state, char *name); 57 63 void pop_state(); 64 int return_sect_token(int passed, int old_sect, int new_sect); 58 65 extern int init_modgen(moddef *module_def, char *filename); 59 66 … … 123 130 %x module 124 131 %x COMMENT 132 %x COMMENTB 125 133 %x STRING 126 134 %x SECT2 127 135 %x SECT3 136 %x SECT4 128 137 %x PROCDECL 129 138 %x EXAMPLE … … 142 151 static int quote = 0; /* " */ 143 152 144 <COMMENT, STRING,INITIAL><<EOF>> {153 <COMMENT,COMMENTB,STRING,INITIAL><<EOF>> { 145 154 printf( "EOF encountered inside an action\n"); 146 155 printf("ERRRRROOOOORRR\n"); 147 156 } 157 158 <INITIAL,SECT2,SECT3,SECT4>{ 159 ^"%Singular".* { 160 int passed = (oldsectnum == sectnum) ? 0 : 1; 161 int old_sect = sectnum; 162 163 oldsectnum = sectnum; 164 sectnum = 2; 165 if(!passed) yyless(0); 166 else push_state(YYSTATE, SECT2, "SECT2"); 167 return(return_sect_token(passed, old_sect, sectnum)); 168 } 169 "%Singular".* { 170 int passed = (oldsectnum == sectnum) ? 0 : 1; 171 int old_sect = sectnum; 172 173 oldsectnum = sectnum; 174 sectnum = 2; 175 if(!passed) yyless(0); 176 else push_state(YYSTATE, SECT2, "SECT2"); 177 return(return_sect_token(passed, old_sect, sectnum)); 178 } 179 ^"%procedures".* { 180 int passed = (oldsectnum == sectnum) ? 0 : 1; 181 int old_sect = sectnum; 182 183 oldsectnum = sectnum; 184 sectnum = 3; 185 if(!passed) yyless(0); 186 else push_state(YYSTATE, SECT3, "SECT3"); 187 return(return_sect_token(passed, old_sect, sectnum)); 188 } 189 "%procedures".* { 190 int passed = (oldsectnum == sectnum) ? 0 : 1; 191 int old_sect = sectnum; 192 193 oldsectnum = sectnum; 194 sectnum = 3; 195 if(!passed) yyless(0); 196 else push_state(YYSTATE, SECT3, "SECT3"); 197 return(return_sect_token(passed, old_sect, sectnum)); 198 } 199 ^"%C".* { 200 int passed = (oldsectnum == sectnum) ? 0 : 1; 201 int old_sect = sectnum; 202 203 oldsectnum = sectnum; 204 sectnum = 4; 205 if(!passed) yyless(0); 206 else push_state(YYSTATE, SECT4, "SECT4"); 207 return(return_sect_token(passed, old_sect, sectnum)); 208 } 209 "%C".* { 210 int passed = (oldsectnum == sectnum) ? 0 : 1; 211 int old_sect = sectnum; 212 213 oldsectnum = sectnum; 214 sectnum = 4; 215 if(!passed) yyless(0); 216 else push_state(YYSTATE, SECT4, "SECT4-2"); 217 return(return_sect_token(passed, old_sect, sectnum)); 218 } 219 } 220 148 221 149 222 <INITIAL>{ … … 174 247 push_state(YYSTATE, STRING, "string"); 175 248 } 176 ^"%%".* { 177 sectnum = 2; 178 #if DEBUG 179 printf("Goto section %d\n", sectnum); 180 #endif 181 push_state(YYSTATE, SECT2, "SECT2"); 182 /*line_directive_out( (FILE *) 0, 1 );*/ 183 return SECTEND; 184 } 249 185 250 ^{NAME} { 186 251 lvalp->name = strdup(yytext); … … 192 257 } 193 258 } 259 194 260 <CODEBLOCK>{ 195 261 ^"%}".*{NL} { … … 244 310 245 311 <SECT2>{ 246 ^"%%".* {247 sectnum = 3;248 #if DEBUG249 printf("Goto section %d\n", sectnum);250 #endif251 switch_state(YYSTATE, SECT3, "SECT3");252 /*yyterminate();*/253 /*line_directive_out( (FILE *) 0, 1 );*/254 return SECT2END;255 }256 312 {NL} { yylineno++; } 257 313 {WS} /* ignore */ … … 266 322 return PROCDECLTOK; 267 323 } 324 example { 325 #if DEBUG > 1 326 printf(">>>EXAMPLE\n"); 327 #endif 328 brace1 = 0; /* { */ 329 brace2 = 0; /* ( */ 330 brace3 = 0; /* [ */ 331 push_state(YYSTATE, EXAMPLE, "EXAMPLE"); 332 return EXAMPLETOK; 333 } 334 static { return STATICTOK; } 335 . { printf("SG(%d) <<<'%s' ", yylineno, yytext); } 336 } 337 338 <SECT3>{ 339 {NL} { yylineno++; } 340 {WS} /* ignore */ 341 ; /* ignore */ 342 "/*" push_state(YYSTATE, COMMENT, "COMMENT"); yymore(); 343 "//".*{NL} ++yylineno; ACTION_ECHO; 268 344 example { 269 345 #if DEBUG > 1 … … 300 376 } 301 377 } 302 . { printf(" <<<'%s' ", yytext); }378 . { printf("PR(%d) <<<'%s' ", yylineno, yytext); } 303 379 } 304 380 … … 313 389 } 314 390 315 <SECT 3>{391 <SECT4>{ 316 392 {NL} { yylineno++; } 317 393 .*(\n?) { lvalp->name = yytext; return CODEPART; } … … 319 395 <<EOF>> { sectnum = 0; 320 396 iseof=1; 321 return SECT 3END;397 return SECT4END; 322 398 /*yyterminate();*/ 323 399 } … … 374 450 } 375 451 452 <COMMENTB>{ 453 "*/" { ACTION_ECHO; 454 pop_state(); 455 lvalp->name = yytext; 456 return CMTPART; 457 yymore(); 458 } 459 "*" yymore(); 460 {NL} { yylineno++; yymore(); } 461 . { yymore(); } 462 } 463 376 464 <CODEBLOCK2>{ 377 465 "/*" push_state(YYSTATE, COMMENT, "COMMENT"); yymore(); … … 406 494 } 407 495 {NL} { yylineno++; lvalp->name = yytext; return CODEPART; } 408 "%" { push_state(YYSTATE, PROCCMDBLOCK, "PROCCMDBLOCK"); return '%'; } 409 . { yymore(); } 496 "%" { push_state(YYSTATE, PROCCMDBLOCK, "PROCCMDBLOCK"); 497 procedure_decl.flags.start_of_code = 1; 498 return '%'; } 499 " " { yymore(); } 500 . { yymore(); procedure_decl.flags.start_of_code = 1; } 410 501 411 502 } … … 505 596 } 506 597 598 int return_sect_token( 599 int passed, 600 int old_sect, 601 int new_sect 602 ) 603 { 604 if(passed) { 605 #if DEBUG 606 printf("Go to section '%s' (%d)\n", sectname[new_sect], new_sect); 607 #endif 608 switch(new_sect) { 609 case 2: return SECT2START; 610 case 3: return SECT3START; 611 case 4: return SECT4START; 612 default: return SECTEND; 613 } 614 } else { 615 #if DEBUG 616 printf("End of section '%s' (%d)\n", sectname[old_sect], old_sect); 617 #endif 618 switch(old_sect) { 619 case 2: return SECT2END; 620 case 3: return SECT3END; 621 case 4: return SECT4END; 622 default: return SECTEND; 623 } 624 } 625 } 626 507 627 void add_action(char *new_text) 508 628 { … … 518 638 printf("3>%s<#\n", new_text); 519 639 break; 640 case 4: 641 printf("4>%s<#\n", new_text); 642 break; 520 643 } 521 644 } -
modules/modgen/utils.cc
r172cdf rd76127 1 1 /* 2 * $Id: utils.cc,v 1. 8 2000-03-30 06:35:46krueger Exp $2 * $Id: utils.cc,v 1.9 2000-05-01 19:14:49 krueger Exp $ 3 3 */ 4 4 … … 123 123 vprintf(fmt, ap); 124 124 va_end(ap); 125 return 1;125 return 2; 126 126 }
Note: See TracChangeset
for help on using the changeset viewer.