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