source: git/Singular/gentable.cc @ c12c262

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