1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id$ */ |
---|
5 | |
---|
6 | /* |
---|
7 | * ABSTRACT: generate iparith.inc etc. |
---|
8 | */ |
---|
9 | |
---|
10 | #include <stdlib.h> |
---|
11 | #include <string.h> |
---|
12 | #include <ctype.h> |
---|
13 | #include <stdio.h> |
---|
14 | #include <time.h> |
---|
15 | #include <unistd.h> |
---|
16 | |
---|
17 | #include <Singular/mod2.h> |
---|
18 | #include <Singular/tok.h> |
---|
19 | #include <Singular/grammar.h> |
---|
20 | |
---|
21 | #define ALLOW_PLURAL 1 |
---|
22 | #define NO_PLURAL 0 |
---|
23 | #define COMM_PLURAL 2 |
---|
24 | #define PLURAL_MASK 3 |
---|
25 | |
---|
26 | #define ALLOW_RING 4 |
---|
27 | #define NO_RING 0 |
---|
28 | |
---|
29 | |
---|
30 | /*=============== types =====================*/ |
---|
31 | struct _scmdnames |
---|
32 | { |
---|
33 | const char *name; |
---|
34 | short alias; |
---|
35 | short tokval; |
---|
36 | short toktype; |
---|
37 | }; |
---|
38 | typedef struct _scmdnames cmdnames; |
---|
39 | |
---|
40 | |
---|
41 | struct sValCmd2 |
---|
42 | { |
---|
43 | int p; |
---|
44 | short cmd; |
---|
45 | short res; |
---|
46 | short arg1; |
---|
47 | short arg2; |
---|
48 | short valid_for; |
---|
49 | }; |
---|
50 | struct sValCmd1 |
---|
51 | { |
---|
52 | int p; |
---|
53 | short cmd; |
---|
54 | short res; |
---|
55 | short arg; |
---|
56 | short valid_for; |
---|
57 | }; |
---|
58 | struct sValCmd3 |
---|
59 | { |
---|
60 | int p; |
---|
61 | short cmd; |
---|
62 | short res; |
---|
63 | short arg1; |
---|
64 | short arg2; |
---|
65 | short arg3; |
---|
66 | short valid_for; |
---|
67 | }; |
---|
68 | struct sValCmdM |
---|
69 | { |
---|
70 | int p; |
---|
71 | short cmd; |
---|
72 | short res; |
---|
73 | short number_of_args; /* -1: any, -2: any >0, .. */ |
---|
74 | short valid_for; |
---|
75 | }; |
---|
76 | struct sValAssign_sys |
---|
77 | { |
---|
78 | int p; |
---|
79 | short res; |
---|
80 | short arg; |
---|
81 | }; |
---|
82 | |
---|
83 | struct sValAssign |
---|
84 | { |
---|
85 | int p; |
---|
86 | short res; |
---|
87 | short arg; |
---|
88 | }; |
---|
89 | |
---|
90 | struct sConvertTypes |
---|
91 | { |
---|
92 | int i_typ; |
---|
93 | int o_typ; |
---|
94 | int p; |
---|
95 | int pl; |
---|
96 | }; |
---|
97 | |
---|
98 | |
---|
99 | #define jjWRONG 1 |
---|
100 | #define jjWRONG2 1 |
---|
101 | #define jjWRONG3 1 |
---|
102 | #define XS(A) A |
---|
103 | |
---|
104 | |
---|
105 | #define D(A) 2 |
---|
106 | #define IPARITH |
---|
107 | #define GENTABLE |
---|
108 | #define IPCONV |
---|
109 | #define IPASSIGN |
---|
110 | |
---|
111 | #include "table.h" |
---|
112 | |
---|
113 | const char * Tok2Cmdname(int tok) |
---|
114 | { |
---|
115 | int i = 0; |
---|
116 | if (tok < 0) |
---|
117 | { |
---|
118 | return cmds[0].name; |
---|
119 | } |
---|
120 | if (tok==COMMAND) return "command"; |
---|
121 | if (tok==ANY_TYPE) return "any_type"; |
---|
122 | if (tok==NONE) return "nothing"; |
---|
123 | //if (tok==IFBREAK) return "if_break"; |
---|
124 | //if (tok==VECTOR_FROM_POLYS) return "vector_from_polys"; |
---|
125 | //if (tok==ORDER_VECTOR) return "ordering"; |
---|
126 | //if (tok==REF_VAR) return "ref"; |
---|
127 | //if (tok==OBJECT) return "object"; |
---|
128 | //if (tok==PRINT_EXPR) return "print_expr"; |
---|
129 | if (tok==IDHDL) return "identifier"; |
---|
130 | while (cmds[i].tokval!=0) |
---|
131 | { |
---|
132 | if ((cmds[i].tokval == tok)&&(cmds[i].alias==0)) |
---|
133 | { |
---|
134 | return cmds[i].name; |
---|
135 | } |
---|
136 | i++; |
---|
137 | } |
---|
138 | return cmds[0].name; |
---|
139 | } |
---|
140 | /*---------------------------------------------------------------------*/ |
---|
141 | /** |
---|
142 | * @brief compares to entry of cmdsname-list |
---|
143 | |
---|
144 | @param[in] a |
---|
145 | @param[in] b |
---|
146 | |
---|
147 | @return <ReturnValue> |
---|
148 | **/ |
---|
149 | /*---------------------------------------------------------------------*/ |
---|
150 | static int _gentable_sort_cmds( const void *a, const void *b ) |
---|
151 | { |
---|
152 | cmdnames *pCmdL = (cmdnames*)a; |
---|
153 | cmdnames *pCmdR = (cmdnames*)b; |
---|
154 | |
---|
155 | if(a==NULL || b==NULL) return 0; |
---|
156 | |
---|
157 | /* empty entries goes to the end of the list for later reuse */ |
---|
158 | if(pCmdL->name==NULL) return 1; |
---|
159 | if(pCmdR->name==NULL) return -1; |
---|
160 | |
---|
161 | /* $INVALID$ must come first */ |
---|
162 | if(strcmp(pCmdL->name, "$INVALID$")==0) return -1; |
---|
163 | if(strcmp(pCmdR->name, "$INVALID$")==0) return 1; |
---|
164 | |
---|
165 | /* tokval=-1 are reserved names at the end */ |
---|
166 | if (pCmdL->tokval==-1) |
---|
167 | { |
---|
168 | if (pCmdR->tokval==-1) |
---|
169 | return strcmp(pCmdL->name, pCmdR->name); |
---|
170 | /* pCmdL->tokval==-1, pCmdL goes at the end */ |
---|
171 | return 1; |
---|
172 | } |
---|
173 | /* pCmdR->tokval==-1, pCmdR goes at the end */ |
---|
174 | if(pCmdR->tokval==-1) return -1; |
---|
175 | |
---|
176 | return strcmp(pCmdL->name, pCmdR->name); |
---|
177 | } |
---|
178 | |
---|
179 | /*generic*/ |
---|
180 | const char * iiTwoOps(int t) |
---|
181 | { |
---|
182 | if (t<127) |
---|
183 | { |
---|
184 | static char ch[2]; |
---|
185 | switch (t) |
---|
186 | { |
---|
187 | case '&': |
---|
188 | return "and"; |
---|
189 | case '|': |
---|
190 | return "or"; |
---|
191 | default: |
---|
192 | ch[0]=t; |
---|
193 | ch[1]='\0'; |
---|
194 | return ch; |
---|
195 | } |
---|
196 | } |
---|
197 | switch (t) |
---|
198 | { |
---|
199 | case COLONCOLON: return "::"; |
---|
200 | case DOTDOT: return ".."; |
---|
201 | //case PLUSEQUAL: return "+="; |
---|
202 | //case MINUSEQUAL: return "-="; |
---|
203 | case MINUSMINUS: return "--"; |
---|
204 | case PLUSPLUS: return "++"; |
---|
205 | case EQUAL_EQUAL: return "=="; |
---|
206 | case LE: return "<="; |
---|
207 | case GE: return ">="; |
---|
208 | case NOTEQUAL: return "<>"; |
---|
209 | default: return Tok2Cmdname(t); |
---|
210 | } |
---|
211 | } |
---|
212 | // |
---|
213 | // automatic conversions: |
---|
214 | // |
---|
215 | /*2 |
---|
216 | * try to convert 'inputType' in 'outputType' |
---|
217 | * return 0 on failure, an index (<>0) on success |
---|
218 | */ |
---|
219 | int iiTestConvert (int inputType, int outputType) |
---|
220 | { |
---|
221 | if ((inputType==outputType) |
---|
222 | || (outputType==DEF_CMD) |
---|
223 | || (outputType==IDHDL) |
---|
224 | || (outputType==ANY_TYPE)) |
---|
225 | { |
---|
226 | return -1; |
---|
227 | } |
---|
228 | |
---|
229 | // search the list |
---|
230 | int i=0; |
---|
231 | while (dConvertTypes[i].i_typ!=0) |
---|
232 | { |
---|
233 | if((dConvertTypes[i].i_typ==inputType) |
---|
234 | &&(dConvertTypes[i].o_typ==outputType)) |
---|
235 | { |
---|
236 | //Print("test convert %d to %d (%s -> %s):%d\n",inputType,outputType, |
---|
237 | //Tok2Cmdname(inputType), Tok2Cmdname(outputType),i+1); |
---|
238 | return i+1; |
---|
239 | } |
---|
240 | i++; |
---|
241 | } |
---|
242 | //Print("test convert %d to %d (%s -> %s):0\n",inputType,outputType, |
---|
243 | // Tok2Cmdname(inputType), Tok2Cmdname(outputType)); |
---|
244 | return 0; |
---|
245 | } |
---|
246 | char *iparith_inc; |
---|
247 | void ttGen1() |
---|
248 | { |
---|
249 | iparith_inc=strdup("iparith.xxxxxx"); |
---|
250 | int pid=getpid(); |
---|
251 | iparith_inc[8]=(pid %10)+'0'; pid/=10; |
---|
252 | iparith_inc[9]=(pid %10)+'0'; pid/=10; |
---|
253 | iparith_inc[10]=(pid %10)+'0'; pid/=10; |
---|
254 | iparith_inc[11]=(pid %10)+'0'; pid/=10; |
---|
255 | iparith_inc[12]=(pid %10)+'0'; pid/=10; |
---|
256 | iparith_inc[13]=(pid %10)+'0'; |
---|
257 | FILE *outfile = fopen(iparith_inc,"w"); |
---|
258 | int i,j,l1=0,l2=0; |
---|
259 | fprintf(outfile, |
---|
260 | "/****************************************\n" |
---|
261 | "* Computer Algebra System SINGULAR *\n" |
---|
262 | "****************************************/\n\n"); |
---|
263 | /*-------------------------------------------------------------------*/ |
---|
264 | fprintf(outfile,"// syntax table for Singular\n//\n"); |
---|
265 | fprintf(outfile,"// - search for an exact match of the argument types\n"); |
---|
266 | fprintf(outfile,"// - otherwise search for the first possibility\n"); |
---|
267 | fprintf(outfile,"// with converted types of the arguments\n"); |
---|
268 | fprintf(outfile,"// - otherwise report an error\n//\n"); |
---|
269 | |
---|
270 | int op; |
---|
271 | i=0; |
---|
272 | while ((op=dArith1[i].cmd)!=0) |
---|
273 | { |
---|
274 | if (dArith1[i].p==jjWRONG) |
---|
275 | fprintf(outfile,"// DUMMY "); |
---|
276 | const char *s = iiTwoOps(op); |
---|
277 | fprintf(outfile,"// operation: %s (%s) -> %s\n", |
---|
278 | s, |
---|
279 | Tok2Cmdname(dArith1[i].arg), |
---|
280 | Tok2Cmdname(ABS(dArith1[i].res))); |
---|
281 | i++; |
---|
282 | } |
---|
283 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
284 | i=0; |
---|
285 | while ((op=dArith2[i].cmd)!=0) |
---|
286 | { |
---|
287 | if (dArith2[i].p==jjWRONG2) |
---|
288 | fprintf(outfile,"// DUMMY "); |
---|
289 | const char *s = iiTwoOps(op); |
---|
290 | fprintf(outfile,"// operation: %s (%s, %s) -> %s\n", |
---|
291 | s, |
---|
292 | Tok2Cmdname(dArith2[i].arg1), |
---|
293 | Tok2Cmdname(dArith2[i].arg2), |
---|
294 | Tok2Cmdname(dArith2[i].res)); |
---|
295 | i++; |
---|
296 | } |
---|
297 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
298 | i=0; |
---|
299 | while ((op=dArith3[i].cmd)!=0) |
---|
300 | { |
---|
301 | const char *s = iiTwoOps(op); |
---|
302 | if (dArith3[i].p==jjWRONG3) |
---|
303 | fprintf(outfile,"// DUMMY "); |
---|
304 | fprintf(outfile,"// operation: %s (%s, %s, %s) -> %s\n", |
---|
305 | s, |
---|
306 | Tok2Cmdname(dArith3[i].arg1), |
---|
307 | Tok2Cmdname(dArith3[i].arg2), |
---|
308 | Tok2Cmdname(dArith3[i].arg3), |
---|
309 | Tok2Cmdname(dArith3[i].res)); |
---|
310 | i++; |
---|
311 | } |
---|
312 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
313 | i=0; |
---|
314 | while ((op=dArithM[i].cmd)!=0) |
---|
315 | { |
---|
316 | const char *s = iiTwoOps(op); |
---|
317 | fprintf(outfile,"// operation: %s (...) -> %s", |
---|
318 | s, |
---|
319 | Tok2Cmdname(dArithM[i].res)); |
---|
320 | switch(dArithM[i].number_of_args) |
---|
321 | { |
---|
322 | case -2: |
---|
323 | fprintf(outfile," ( number of arguments >0 )\n"); |
---|
324 | break; |
---|
325 | case -1: |
---|
326 | fprintf(outfile," ( any number of arguments )\n"); |
---|
327 | break; |
---|
328 | default: |
---|
329 | fprintf(outfile," ( %d arguments )\n",dArithM[i].number_of_args); |
---|
330 | break; |
---|
331 | } |
---|
332 | i++; |
---|
333 | } |
---|
334 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
335 | i=0; |
---|
336 | while ((op=dAssign[i].res)!=0) |
---|
337 | { |
---|
338 | fprintf(outfile,"// assign: %s = %s\n", |
---|
339 | Tok2Cmdname(op/*dAssign[i].res*/), |
---|
340 | Tok2Cmdname(dAssign[i].arg)); |
---|
341 | i++; |
---|
342 | } |
---|
343 | /*-------------------------------------------------------------------*/ |
---|
344 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
345 | for (j=257;j<=MAX_TOK+1;j++) |
---|
346 | { |
---|
347 | for(i=257;i<=MAX_TOK+1;i++) |
---|
348 | { |
---|
349 | if ((i!=j) && (j!=IDHDL) && (j!=DEF_CMD) && (j!=ANY_TYPE) |
---|
350 | && iiTestConvert(i,j)) |
---|
351 | { |
---|
352 | fprintf(outfile,"// convert %s -> %s\n", |
---|
353 | Tok2Cmdname(i), Tok2Cmdname(j)); |
---|
354 | if (j==ANY_TYPE) break; |
---|
355 | } |
---|
356 | } |
---|
357 | } |
---|
358 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
359 | char ops[]="=><+*/[.^,%(;"; |
---|
360 | for(i=0;ops[i]!='\0';i++) |
---|
361 | fprintf(outfile,"// token %d : %c\n", (int)ops[i], ops[i]); |
---|
362 | for (i=257;i<=MAX_TOK;i++) |
---|
363 | { |
---|
364 | const char *s=iiTwoOps(i); |
---|
365 | if (s[0]!='$') |
---|
366 | { |
---|
367 | fprintf(outfile,"// token %d : %s\n", i, s); |
---|
368 | } |
---|
369 | } |
---|
370 | /*-------------------------------------------------------------------*/ |
---|
371 | fprintf(outfile,"/*--max. token: %d, gr: %d --*/\n",MAX_TOK,UMINUS); |
---|
372 | /*-------------------------------------------------------------------*/ |
---|
373 | fprintf(outfile,"/*---------------------------------------------*/\n"); |
---|
374 | fprintf(outfile, |
---|
375 | "struct sValCmdTab dArithTab1[]=\n" |
---|
376 | "{\n"); |
---|
377 | for (j=1;j<=MAX_TOK+1;j++) |
---|
378 | { |
---|
379 | for(i=0;dArith1[i].cmd!=0;i++) |
---|
380 | { |
---|
381 | if (dArith1[i].cmd==j) |
---|
382 | { |
---|
383 | fprintf(outfile," { %d,%d },\n",j,i); |
---|
384 | l1++; |
---|
385 | break; |
---|
386 | } |
---|
387 | } |
---|
388 | } |
---|
389 | fprintf(outfile," { 10000,0 }\n};\n"); |
---|
390 | fprintf(outfile,"#define JJTAB1LEN %d\n",l1); |
---|
391 | /*-------------------------------------------------------------------*/ |
---|
392 | fprintf(outfile, |
---|
393 | "struct sValCmdTab dArithTab2[]=\n" |
---|
394 | "{\n"); |
---|
395 | for (j=1;j<=MAX_TOK+1;j++) |
---|
396 | { |
---|
397 | for(i=0;dArith2[i].cmd!=0;i++) |
---|
398 | { |
---|
399 | if (dArith2[i].cmd==j) |
---|
400 | { |
---|
401 | fprintf(outfile," { %d,%d },\n",j,i); |
---|
402 | l2++; |
---|
403 | break; |
---|
404 | } |
---|
405 | } |
---|
406 | } |
---|
407 | fprintf(outfile," { 10000,0 }\n};\n"); |
---|
408 | fprintf(outfile,"#define JJTAB2LEN %d\n",l2); |
---|
409 | fclose(outfile); |
---|
410 | } |
---|
411 | /*-------------------------------------------------------------------*/ |
---|
412 | #if 0 |
---|
413 | void ttGen2() |
---|
414 | { |
---|
415 | FILE *outfile = fopen(iparith_inc,"a"); |
---|
416 | fprintf(outfile, |
---|
417 | "/****************************************\n" |
---|
418 | "* Computer Algebra System SINGULAR *\n" |
---|
419 | "****************************************/\n\n"); |
---|
420 | /*-------------------------------------------------------------------*/ |
---|
421 | fprintf(outfile,"// identifier table for Singular\n//\n"); |
---|
422 | |
---|
423 | fprintf(outfile, |
---|
424 | "cmdnames OLDcmds[] =\n" |
---|
425 | "{ // name-string alias tokval toktype\n" |
---|
426 | "{ \"$INVALID$\", 0, -1, 0},\n"); |
---|
427 | int i=1; |
---|
428 | int m=-1; |
---|
429 | int id_nr=0; |
---|
430 | BOOLEAN f=FALSE; |
---|
431 | loop |
---|
432 | { |
---|
433 | while (cmds[i].tokval!=0) |
---|
434 | { |
---|
435 | if ((cmds[i].tokval!=-1)&&(cmds[i].name!=NULL)) |
---|
436 | { |
---|
437 | if(m==-1) |
---|
438 | { |
---|
439 | m=i; |
---|
440 | f=TRUE; |
---|
441 | } |
---|
442 | else if(strcmp(cmds[m].name,cmds[i].name)>0) |
---|
443 | { |
---|
444 | m=i; |
---|
445 | f=TRUE; |
---|
446 | } |
---|
447 | } |
---|
448 | i++; |
---|
449 | } |
---|
450 | if(f) |
---|
451 | { |
---|
452 | id_nr++; |
---|
453 | fprintf(outfile," {\"%s\", %*d, %3d, ",cmds[m].name, |
---|
454 | 20-strlen(cmds[m].name), |
---|
455 | cmds[m].alias, |
---|
456 | cmds[m].tokval); |
---|
457 | switch(cmds[m].toktype) |
---|
458 | { |
---|
459 | case CMD_1: fprintf(outfile,"CMD_1 },\n"); break; |
---|
460 | case CMD_2: fprintf(outfile,"CMD_2 },\n"); break; |
---|
461 | case CMD_3: fprintf(outfile,"CMD_3 },\n"); break; |
---|
462 | case CMD_12: fprintf(outfile,"CMD_12 },\n"); break; |
---|
463 | case CMD_123 : fprintf(outfile,"CMD_123 },\n"); break; |
---|
464 | case CMD_23: fprintf(outfile,"CMD_23 },\n"); break; |
---|
465 | case CMD_M: fprintf(outfile,"CMD_M },\n"); break; |
---|
466 | case SYSVAR: fprintf(outfile,"SYSVAR },\n"); break; |
---|
467 | case ROOT_DECL: fprintf(outfile,"ROOT_DECL },\n"); break; |
---|
468 | case ROOT_DECL_LIST: fprintf(outfile,"ROOT_DECL_LIST },\n"); break; |
---|
469 | case RING_DECL: fprintf(outfile,"RING_DECL },\n"); break; |
---|
470 | case NONE: fprintf(outfile,"NONE },\n"); break; |
---|
471 | default: if((cmds[m].toktype>' ') |
---|
472 | &&(cmds[m].toktype<127)) |
---|
473 | { |
---|
474 | fprintf(outfile,"'%c' },\n",cmds[m].toktype); |
---|
475 | } |
---|
476 | else |
---|
477 | { |
---|
478 | fprintf(outfile,"%d },\n",cmds[m].toktype); |
---|
479 | } |
---|
480 | break; |
---|
481 | } |
---|
482 | cmds[m].name=NULL; |
---|
483 | m=-1; |
---|
484 | i=1; |
---|
485 | f=FALSE; |
---|
486 | } |
---|
487 | else break; |
---|
488 | } |
---|
489 | fprintf(outfile, |
---|
490 | "/* list of scanner identifiers/only for feread/reservedName */\n"); |
---|
491 | f=FALSE; |
---|
492 | i=1;m=-1; |
---|
493 | loop |
---|
494 | { |
---|
495 | while (cmds[i].tokval!=0) |
---|
496 | { |
---|
497 | if (cmds[i].name!=NULL) |
---|
498 | { |
---|
499 | if(m==-1) |
---|
500 | { |
---|
501 | m=i; |
---|
502 | f=TRUE; |
---|
503 | } |
---|
504 | else if(strcmp(cmds[m].name,cmds[i].name)>0) |
---|
505 | { |
---|
506 | m=i; |
---|
507 | f=TRUE; |
---|
508 | } |
---|
509 | } |
---|
510 | i++; |
---|
511 | } |
---|
512 | if(f) |
---|
513 | { |
---|
514 | fprintf(outfile," {\"%s\", %*d, -1, 0 },\n",cmds[m].name, |
---|
515 | 20-strlen(cmds[m].name), |
---|
516 | 0/*cmds[m].alias*/ |
---|
517 | /*-1 cmds[m].tokval*/ |
---|
518 | /*0 cmds[m].toktype*/); |
---|
519 | cmds[m].name=NULL; |
---|
520 | m=-1; |
---|
521 | i=1; |
---|
522 | f=FALSE; |
---|
523 | } |
---|
524 | else break; |
---|
525 | } |
---|
526 | fprintf(outfile, |
---|
527 | "/* end of list marker */\n" |
---|
528 | " { NULL, 0, 0, 0}\n" |
---|
529 | "};\n" |
---|
530 | "#define LAST_IDENTIFIER %d\n" |
---|
531 | ,id_nr); |
---|
532 | fclose(outfile); |
---|
533 | } |
---|
534 | #endif |
---|
535 | /*---------------------------------------------------------------------*/ |
---|
536 | /** |
---|
537 | * @brief generate cmds initialisation |
---|
538 | **/ |
---|
539 | /*---------------------------------------------------------------------*/ |
---|
540 | |
---|
541 | void ttGen2b() |
---|
542 | { |
---|
543 | int cmd_size = (sizeof(cmds)/sizeof(cmdnames))-1; |
---|
544 | |
---|
545 | FILE *outfile = fopen(iparith_inc,"a"); |
---|
546 | fprintf(outfile, |
---|
547 | "/****************************************\n" |
---|
548 | "* Computer Algebra System SINGULAR *\n" |
---|
549 | "****************************************/\n\n"); |
---|
550 | /*-------------------------------------------------------------------*/ |
---|
551 | fprintf(outfile,"// identifier table for Singular\n//\n"); |
---|
552 | |
---|
553 | fprintf( |
---|
554 | outfile, |
---|
555 | "#ifdef MODULE_GENERATOR\n" |
---|
556 | "#define omAlloc0(A) malloc(A)\n" |
---|
557 | "#endif\n" |
---|
558 | "void iiInitCmdName()\n{\n" |
---|
559 | " sArithBase.nCmdUsed = 0;\n" |
---|
560 | " sArithBase.nCmdAllocated = %d;\n" |
---|
561 | " sArithBase.sCmds = (cmdnames*)omAlloc0(sArithBase.nCmdAllocated*sizeof(cmdnames));\n" |
---|
562 | "\n" |
---|
563 | " // name-string alias tokval toktype index\n", |
---|
564 | cmd_size); |
---|
565 | int m=0; |
---|
566 | int id_nr=0; |
---|
567 | |
---|
568 | qsort(&cmds, cmd_size, sizeof(cmdnames), (&_gentable_sort_cmds)); |
---|
569 | |
---|
570 | for(m=0; m<cmd_size; m++) |
---|
571 | { |
---|
572 | if(cmds[m].tokval>0) id_nr++; |
---|
573 | fprintf(outfile," iiArithAddCmd(\"%s\", %*d, %3d, ",cmds[m].name, |
---|
574 | (int)(20-strlen(cmds[m].name)), |
---|
575 | cmds[m].alias, |
---|
576 | cmds[m].tokval); |
---|
577 | switch(cmds[m].toktype) |
---|
578 | { |
---|
579 | case CMD_1: fprintf(outfile,"CMD_1"); break; |
---|
580 | case CMD_2: fprintf(outfile,"CMD_2"); break; |
---|
581 | case CMD_3: fprintf(outfile,"CMD_3"); break; |
---|
582 | case CMD_12: fprintf(outfile,"CMD_12"); break; |
---|
583 | case CMD_123 : fprintf(outfile,"CMD_123"); break; |
---|
584 | case CMD_23: fprintf(outfile,"CMD_23"); break; |
---|
585 | case CMD_M: fprintf(outfile,"CMD_M"); break; |
---|
586 | case SYSVAR: fprintf(outfile,"SYSVAR"); break; |
---|
587 | case ROOT_DECL: fprintf(outfile,"ROOT_DECL"); break; |
---|
588 | case ROOT_DECL_LIST: fprintf(outfile,"ROOT_DECL_LIST"); break; |
---|
589 | case RING_DECL: fprintf(outfile,"RING_DECL"); break; |
---|
590 | case NONE: fprintf(outfile,"NONE"); break; |
---|
591 | default: |
---|
592 | if((cmds[m].toktype>' ') &&(cmds[m].toktype<127)) |
---|
593 | { |
---|
594 | fprintf(outfile,"'%c'",cmds[m].toktype); |
---|
595 | } |
---|
596 | else |
---|
597 | { |
---|
598 | fprintf(outfile,"%d",cmds[m].toktype); |
---|
599 | } |
---|
600 | break; |
---|
601 | #if 0 |
---|
602 | fprintf(outfile," iiArithAddCmd(\"%s\", %*d, -1, 0 );\n", |
---|
603 | cmds[m].name, 20-strlen(cmds[m].name), |
---|
604 | 0/*cmds[m].alias*/ |
---|
605 | /*-1 cmds[m].tokval*/ |
---|
606 | /*0 cmds[m].toktype*/); |
---|
607 | #endif |
---|
608 | } |
---|
609 | fprintf(outfile,", %d);\n", m); |
---|
610 | } |
---|
611 | fprintf(outfile, "/* end of list marker */\n"); |
---|
612 | fprintf(outfile, |
---|
613 | " sArithBase.nLastIdentifier = %d;\n", |
---|
614 | id_nr); |
---|
615 | |
---|
616 | |
---|
617 | fprintf(outfile, |
---|
618 | "}\n" |
---|
619 | "#define LAST_IDENTIFIER %d\n" |
---|
620 | ,id_nr); |
---|
621 | fclose(outfile); |
---|
622 | } |
---|
623 | /*-------------------------------------------------------------------*/ |
---|
624 | #if 0 |
---|
625 | void ttGen3() |
---|
626 | { |
---|
627 | FILE *outfile = fopen("mpsr_tok.inc","w"); |
---|
628 | fprintf(outfile, |
---|
629 | "/****************************************\n" |
---|
630 | "* Computer Algebra System SINGULAR *\n" |
---|
631 | "****************************************/\n\n"); |
---|
632 | /*-------------------------------------------------------------------*/ |
---|
633 | fprintf(outfile,"// token table for Singular\n//\n"); |
---|
634 | |
---|
635 | fprintf(outfile, |
---|
636 | "short vtok[] =\n" |
---|
637 | "{\n"); |
---|
638 | // operations with 1 arg: =========================================== |
---|
639 | int i=0; |
---|
640 | while (dArith1[i].cmd!=0) |
---|
641 | { |
---|
642 | if ((dArith1[i].p!=jjWRONG) |
---|
643 | &&((i==0)||(dArith1[i].cmd!=dArith1[i-1].cmd))) |
---|
644 | { |
---|
645 | fprintf(outfile," %d,\n",dArith1[i].cmd); |
---|
646 | } |
---|
647 | i++; |
---|
648 | } |
---|
649 | // operations with 2 args: =========================================== |
---|
650 | i=0; |
---|
651 | while (dArith2[i].cmd!=0) |
---|
652 | { |
---|
653 | if ((dArith2[i].p!=jjWRONG2) |
---|
654 | &&((i==0)||(dArith2[i].cmd!=dArith2[i-1].cmd))) |
---|
655 | { |
---|
656 | fprintf(outfile," %d,\n",dArith2[i].cmd); |
---|
657 | } |
---|
658 | i++; |
---|
659 | } |
---|
660 | // operations with 3 args: =========================================== |
---|
661 | i=0; |
---|
662 | while (dArith3[i].cmd!=0) |
---|
663 | { |
---|
664 | if ( |
---|
665 | ((i==0)||(dArith3[i].cmd!=dArith3[i-1].cmd))) |
---|
666 | { |
---|
667 | fprintf(outfile," %d,\n",dArith3[i].cmd); |
---|
668 | } |
---|
669 | i++; |
---|
670 | } |
---|
671 | // operations with many args: =========================================== |
---|
672 | i=0; |
---|
673 | while (dArithM[i].cmd!=0) |
---|
674 | { |
---|
675 | if ( |
---|
676 | ((i==0)||(dArithM[i].cmd!=dArithM[i-1].cmd))) |
---|
677 | { |
---|
678 | fprintf(outfile," %d,\n",dArithM[i].cmd); |
---|
679 | } |
---|
680 | i++; |
---|
681 | } |
---|
682 | // ==================================================================== |
---|
683 | fprintf(outfile, |
---|
684 | "/* end of list marker */\n" |
---|
685 | " %d };\n",MAX_TOK); |
---|
686 | fclose(outfile); |
---|
687 | } |
---|
688 | #endif |
---|
689 | void ttGen4() |
---|
690 | { |
---|
691 | FILE *outfile = fopen("plural_cmd.xx","w"); |
---|
692 | int i; |
---|
693 | const char *old_s=""; |
---|
694 | fprintf(outfile, |
---|
695 | "@c *****************************************\n" |
---|
696 | "@c * Computer Algebra System SINGULAR *\n" |
---|
697 | "@c *****************************************\n\n"); |
---|
698 | /*-------------------------------------------------------------------*/ |
---|
699 | fprintf(outfile,"@multicolumn .45 .45\n"); |
---|
700 | int op; |
---|
701 | i=0; |
---|
702 | while ((op=dArith1[i].cmd)!=0) |
---|
703 | { |
---|
704 | if (dArith1[i].p!=jjWRONG) |
---|
705 | { |
---|
706 | const char *s = iiTwoOps(op); |
---|
707 | if ((s!=NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0)) |
---|
708 | { |
---|
709 | old_s=s; |
---|
710 | #ifdef HAVE_PLURAL |
---|
711 | switch (dArith1[i].valid_for & PLURAL_MASK) |
---|
712 | { |
---|
713 | case NO_PLURAL: |
---|
714 | fprintf(outfile,"@item @ref{%s} @tab @code{---}\n",s); |
---|
715 | break; |
---|
716 | case ALLOW_PLURAL: |
---|
717 | fprintf(outfile,"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s); |
---|
718 | break; |
---|
719 | case COMM_PLURAL: |
---|
720 | fprintf(outfile,"@item @ref{%s} @tab %s\n",s,s); |
---|
721 | break; |
---|
722 | } |
---|
723 | #endif |
---|
724 | #ifdef HAVE_RINGS |
---|
725 | #endif |
---|
726 | } |
---|
727 | } |
---|
728 | i++; |
---|
729 | } |
---|
730 | fprintf(outfile,"@c ---------------------------------------------\n"); |
---|
731 | i=0; |
---|
732 | while ((op=dArith2[i].cmd)!=0) |
---|
733 | { |
---|
734 | if (dArith2[i].p!=jjWRONG2) |
---|
735 | { |
---|
736 | const char *s = iiTwoOps(op); |
---|
737 | if ((s!=NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0)) |
---|
738 | { |
---|
739 | old_s=s; |
---|
740 | #ifdef HAVE_PLURAL |
---|
741 | switch (dArith2[i].valid_for & PLURAL_MASK) |
---|
742 | { |
---|
743 | case NO_PLURAL: |
---|
744 | fprintf(outfile,"@item @ref{%s} @tab @code{---}\n",s); |
---|
745 | break; |
---|
746 | case ALLOW_PLURAL: |
---|
747 | fprintf(outfile,"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s); |
---|
748 | break; |
---|
749 | case COMM_PLURAL: |
---|
750 | fprintf(outfile,"@item @ref{%s} @tab %s\n",s,s); |
---|
751 | break; |
---|
752 | } |
---|
753 | #endif |
---|
754 | #ifdef HAVE_RINGS |
---|
755 | #endif |
---|
756 | } |
---|
757 | } |
---|
758 | i++; |
---|
759 | } |
---|
760 | fprintf(outfile,"@c ---------------------------------------------\n"); |
---|
761 | i=0; |
---|
762 | while ((op=dArith3[i].cmd)!=0) |
---|
763 | { |
---|
764 | const char *s = iiTwoOps(op); |
---|
765 | if (dArith3[i].p!=jjWRONG3) |
---|
766 | { |
---|
767 | if ((s!=NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0)) |
---|
768 | { |
---|
769 | old_s=s; |
---|
770 | #ifdef HAVE_PLURAL |
---|
771 | switch (dArith3[i].valid_for & PLURAL_MASK) |
---|
772 | { |
---|
773 | case NO_PLURAL: |
---|
774 | fprintf(outfile,"@item @ref{%s} @tab @code{---}\n",s); |
---|
775 | break; |
---|
776 | case ALLOW_PLURAL: |
---|
777 | fprintf(outfile,"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s); |
---|
778 | break; |
---|
779 | case COMM_PLURAL: |
---|
780 | fprintf(outfile,"@item @ref{%s} @tab %s\n",s,s); |
---|
781 | break; |
---|
782 | } |
---|
783 | #endif |
---|
784 | #ifdef HAVE_RINGS |
---|
785 | #endif |
---|
786 | } |
---|
787 | } |
---|
788 | i++; |
---|
789 | } |
---|
790 | fprintf(outfile,"@c ---------------------------------------------\n"); |
---|
791 | i=0; |
---|
792 | while ((op=dArithM[i].cmd)!=0) |
---|
793 | { |
---|
794 | const char *s = iiTwoOps(op); |
---|
795 | if ((s!=NULL) && (isalpha(s[0])) && (strcmp(s,old_s)!=0)) |
---|
796 | { |
---|
797 | old_s=s; |
---|
798 | #ifdef HAVE_PLURAL |
---|
799 | switch (dArithM[i].valid_for & PLURAL_MASK) |
---|
800 | { |
---|
801 | case NO_PLURAL: |
---|
802 | fprintf(outfile,"@item @ref{%s} @tab @code{---}\n",s); |
---|
803 | break; |
---|
804 | case ALLOW_PLURAL: |
---|
805 | fprintf(outfile,"@item @ref{%s} @tab @ref{%s (plural)}\n",s,s); |
---|
806 | break; |
---|
807 | case COMM_PLURAL: |
---|
808 | fprintf(outfile,"@item @ref{%s} @tab %s\n",s,s); |
---|
809 | break; |
---|
810 | } |
---|
811 | #endif |
---|
812 | #ifdef HAVE_RINGS |
---|
813 | #endif |
---|
814 | } |
---|
815 | i++; |
---|
816 | } |
---|
817 | fprintf(outfile,"@c ---------------------------------------------\n"); |
---|
818 | fprintf(outfile,"@end table\n"); |
---|
819 | fclose(outfile); |
---|
820 | } |
---|
821 | /*-------------------------------------------------------------------*/ |
---|
822 | |
---|
823 | // some special cmds which do not fit in with the others, and |
---|
824 | // nevertheless need to be transmitted |
---|
825 | short ExtraCmds[] = |
---|
826 | { |
---|
827 | OPTION_CMD, |
---|
828 | NAMES_CMD, |
---|
829 | // RESERVEDNAME_CMD, |
---|
830 | PROC_CMD, |
---|
831 | MAP_CMD, |
---|
832 | PACKAGE_CMD, |
---|
833 | '=', |
---|
834 | 0 |
---|
835 | }; |
---|
836 | |
---|
837 | // This returns 1 if tok is a token which can appear in a Singular |
---|
838 | // (quoted) command, and 0 otherwise |
---|
839 | short IsCmdToken(short tok) |
---|
840 | { |
---|
841 | int i = 0; |
---|
842 | // cmds with one arg |
---|
843 | while (dArith1[i].cmd != 0) |
---|
844 | if (dArith1[i].cmd == tok) return 1; |
---|
845 | else i++; |
---|
846 | |
---|
847 | // cmds with two args |
---|
848 | i=0; |
---|
849 | while (dArith2[i].cmd != 0) |
---|
850 | if (dArith2[i].cmd == tok) return 1; |
---|
851 | else i++; |
---|
852 | |
---|
853 | // cmds with three args |
---|
854 | i=0; |
---|
855 | while (dArith3[i].cmd != 0) |
---|
856 | if (dArith3[i].cmd == tok) return 1; |
---|
857 | else i++; |
---|
858 | |
---|
859 | // cmds with many args |
---|
860 | i=0; |
---|
861 | while (dArithM[i].cmd != 0) |
---|
862 | if (dArithM[i].cmd == tok) return 1; |
---|
863 | else i++; |
---|
864 | |
---|
865 | // cmds which are somewhat special (like those having 0 args) |
---|
866 | i=0; |
---|
867 | while (ExtraCmds[i] != 0) |
---|
868 | if (ExtraCmds[i] == tok) return 1; |
---|
869 | else i++; |
---|
870 | |
---|
871 | return 0; |
---|
872 | } |
---|
873 | |
---|
874 | int main() |
---|
875 | { |
---|
876 | ttGen4(); |
---|
877 | ttGen1(); |
---|
878 | ttGen2b(); |
---|
879 | rename(iparith_inc,"iparith.inc"); |
---|
880 | rename("plural_cmd.xx","plural_cmd.inc"); |
---|
881 | return 0; |
---|
882 | } |
---|