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