Changeset fb0ad9a in git


Ignore:
Timestamp:
Jun 6, 2014, 7:22:07 PM (10 years ago)
Author:
Hans Schoenemann <hannes@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
257a6088d9ed9376744c6ee6bc85af8dc6f426f9
Parents:
daf33cafc0fabbaa48beaca0cabac5a28ba4164e
Message:
restructured gentable/tok.h etc. to generate doc.
Location:
Singular
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • Singular/gentable.cc

    rdaf33c rfb0ad9a  
    1212#include <time.h>
    1313#include <unistd.h>
    14 
    15 
    16 
    17 
    18 #include <kernel/mod2.h>
     14#include <sys/types.h>
     15#include <sys/stat.h>
     16
     17// need to include all tokens: *_CMD:
     18#include "grammar.h"
    1919#include "tok.h"
    20 #include "grammar.h"
    2120
    2221// to produce convert_table.texi for doc:
    23 //#define CONVERT_TABLE 1
     22#define CONVERT_TABLE 1
    2423
    2524// bits 0,1 for PLURAL
     
    2726#define ALLOW_PLURAL     1
    2827#define COMM_PLURAL      2
    29 #define  PLURAL_MASK     3
     28#define PLURAL_MASK      3
    3029
    3130// bit 2 for RING-CF
     
    3635#define NO_ZERODIVISOR   8
    3736#define ALLOW_ZERODIVISOR  0
     37 #define ZERODIVISOR_MASK 8
    3838
    3939// bit 4 for warning, if used at toplevel
     
    188188
    189189  return strcmp(pCmdL->name, pCmdR->name);
     190}
     191
     192static int _texi_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  char *ls=strdup(pCmdL->name);
     207  char *rs=strdup(pCmdR->name);
     208  char *s=ls;
     209  while (*s) { *s=tolower(*s); s++; }
     210  s=rs;
     211  while (*s) { *s=tolower(*s); s++; }
     212
     213  /* tokval=-1 are reserved names at the end */
     214  if (pCmdL->tokval==-1)
     215  {
     216    if (pCmdR->tokval==-1)
     217       { int r=strcmp(ls,rs); free(ls); free(rs); return r; }
     218    /* pCmdL->tokval==-1, pCmdL goes at the end */
     219    free(ls);free(rs);
     220    return 1;
     221  }
     222  /* pCmdR->tokval==-1, pCmdR goes at the end */
     223  if(pCmdR->tokval==-1)
     224  { free(ls);free(rs);return -1;}
     225
     226  { int r=strcmp(ls,rs); free(ls); free(rs); return r; }
    190227}
    191228
     
    291328          s,
    292329          Tok2Cmdname(dArith1[i].arg),
    293           Tok2Cmdname(ABS(dArith1[i].res)));
     330          Tok2Cmdname(dArith1[i].res));
    294331    i++;
    295332  }
     
    437474  fclose(outfile);
    438475}
    439 /*-------------------------------------------------------------------*/
    440 #if 0
    441 void ttGen2()
    442 {
    443   FILE *outfile = fopen(iparith_inc,"a");
    444   fprintf(outfile,
    445   "/****************************************\n"
    446   "*  Computer Algebra System SINGULAR     *\n"
    447   "****************************************/\n\n");
    448 /*-------------------------------------------------------------------*/
    449   fprintf(outfile,"// identifier table for Singular\n//\n");
    450 
    451   fprintf(outfile,
    452   "cmdnames OLDcmds[] =\n"
    453   "{  // name-string     alias  tokval toktype\n"
    454   "{ \"$INVALID$\",            0,  -1, 0},\n");
    455   int i=1;
    456   int m=-1;
    457   int id_nr=0;
    458   BOOLEAN f=FALSE;
    459   loop
    460   {
    461     while (cmds[i].tokval!=0)
    462     {
    463       if ((cmds[i].tokval!=-1)&&(cmds[i].name!=NULL))
    464       {
    465         if(m==-1)
    466         {
    467           m=i;
    468           f=TRUE;
    469         }
    470         else if(strcmp(cmds[m].name,cmds[i].name)>0)
    471         {
    472           m=i;
    473           f=TRUE;
    474         }
    475       }
    476       i++;
    477     }
    478     if(f)
    479     {
    480       id_nr++;
    481       fprintf(outfile,"  {\"%s\", %*d, %3d, ",cmds[m].name,
    482                                              20-strlen(cmds[m].name),
    483                                              cmds[m].alias,
    484                                              cmds[m].tokval);
    485       switch(cmds[m].toktype)
    486       {
    487         case CMD_1:            fprintf(outfile,"CMD_1 },\n"); break;
    488         case CMD_2:            fprintf(outfile,"CMD_2 },\n"); break;
    489         case CMD_3:            fprintf(outfile,"CMD_3 },\n"); break;
    490         case CMD_12:           fprintf(outfile,"CMD_12 },\n"); break;
    491         case CMD_123 :         fprintf(outfile,"CMD_123 },\n"); break;
    492         case CMD_23:           fprintf(outfile,"CMD_23 },\n"); break;
    493         case CMD_M:            fprintf(outfile,"CMD_M },\n"); break;
    494         case SYSVAR:           fprintf(outfile,"SYSVAR },\n"); break;
    495         case ROOT_DECL:        fprintf(outfile,"ROOT_DECL },\n"); break;
    496         case ROOT_DECL_LIST:   fprintf(outfile,"ROOT_DECL_LIST },\n"); break;
    497         case RING_DECL:        fprintf(outfile,"RING_DECL },\n"); break;
    498         case NONE:             fprintf(outfile,"NONE },\n"); break;
    499         default:               if((cmds[m].toktype>' ')
    500                                &&(cmds[m].toktype<127))
    501                                {
    502                                  fprintf(outfile,"'%c' },\n",cmds[m].toktype);
    503                                }
    504                                else
    505                                {
    506                                  fprintf(outfile,"%d },\n",cmds[m].toktype);
    507                                }
    508                                break;
    509       }
    510       cmds[m].name=NULL;
    511       m=-1;
    512       i=1;
    513       f=FALSE;
    514     }
    515     else break;
    516   }
    517   fprintf(outfile,
    518 "/* list of scanner identifiers/only for feread/reservedName */\n");
    519   f=FALSE;
    520   i=1;m=-1;
    521   loop
    522   {
    523     while (cmds[i].tokval!=0)
    524     {
    525       if (cmds[i].name!=NULL)
    526       {
    527         if(m==-1)
    528         {
    529           m=i;
    530           f=TRUE;
    531         }
    532         else if(strcmp(cmds[m].name,cmds[i].name)>0)
    533         {
    534           m=i;
    535           f=TRUE;
    536         }
    537       }
    538       i++;
    539     }
    540     if(f)
    541     {
    542       fprintf(outfile,"  {\"%s\", %*d,  -1, 0 },\n",cmds[m].name,
    543                                              20-strlen(cmds[m].name),
    544                                              0/*cmds[m].alias*/
    545                                              /*-1 cmds[m].tokval*/
    546                                              /*0 cmds[m].toktype*/);
    547       cmds[m].name=NULL;
    548       m=-1;
    549       i=1;
    550       f=FALSE;
    551     }
    552     else break;
    553   }
    554   fprintf(outfile,
    555 "/* end of list marker */\n"
    556 "  { NULL, 0, 0, 0}\n"
    557 "};\n"
    558 "#define LAST_IDENTIFIER %d\n"
    559   ,id_nr);
    560   fclose(outfile);
    561 }
    562 #endif
    563476/*---------------------------------------------------------------------*/
    564477/**
     
    649562  fclose(outfile);
    650563}
    651 /*-------------------------------------------------------------------*/
    652 #if 0
    653 void ttGen3()
    654 {
    655   FILE *outfile = fopen("mpsr_tok.inc","w");
    656   fprintf(outfile,
    657   "/****************************************\n"
    658   "*  Computer Algebra System SINGULAR     *\n"
    659   "****************************************/\n\n");
    660 /*-------------------------------------------------------------------*/
    661   fprintf(outfile,"// token table for Singular\n//\n");
    662 
    663   fprintf(outfile,
    664   "short vtok[] =\n"
    665   "{\n");
    666   // operations with 1 arg: ===========================================
    667   int i=0;
    668   while (dArith1[i].cmd!=0)
    669   {
    670     if ((dArith1[i].p!=jjWRONG)
    671     &&((i==0)||(dArith1[i].cmd!=dArith1[i-1].cmd)))
    672     {
    673       fprintf(outfile,"  %d,\n",dArith1[i].cmd);
    674     }
    675     i++;
    676   }
    677   // operations with 2 args: ===========================================
    678   i=0;
    679   while (dArith2[i].cmd!=0)
    680   {
    681     if ((dArith2[i].p!=jjWRONG2)
    682     &&((i==0)||(dArith2[i].cmd!=dArith2[i-1].cmd)))
    683     {
    684       fprintf(outfile,"  %d,\n",dArith2[i].cmd);
    685     }
    686     i++;
    687   }
    688   // operations with 3 args: ===========================================
    689   i=0;
    690   while (dArith3[i].cmd!=0)
    691   {
    692     if (
    693     ((i==0)||(dArith3[i].cmd!=dArith3[i-1].cmd)))
    694     {
    695       fprintf(outfile,"  %d,\n",dArith3[i].cmd);
    696     }
    697     i++;
    698   }
    699   // operations with many args: ===========================================
    700   i=0;
    701   while (dArithM[i].cmd!=0)
    702   {
    703     if (
    704     ((i==0)||(dArithM[i].cmd!=dArithM[i-1].cmd)))
    705     {
    706       fprintf(outfile,"  %d,\n",dArithM[i].cmd);
    707     }
    708     i++;
    709   }
    710   // ====================================================================
    711   fprintf(outfile,
    712   "/* end of list marker */\n"
    713   " %d };\n",MAX_TOK);
     564void ttGen2c()
     565{
     566  int cmd_size = (sizeof(cmds)/sizeof(cmdnames))-1;
     567
     568  FILE *outfile = fopen("reference_table.texi","w");
     569  fprintf(outfile, "@menu\n");
     570/*-------------------------------------------------------------------*/
     571  qsort(&cmds, cmd_size, sizeof(cmdnames), (&_texi_sort_cmds));
     572
     573  int m;
     574  for(m=0; m<cmd_size; m++)
     575  {
     576    // assume that cmds[0].tokval== -1 and all others with tokval -1 at the end
     577    if(cmds[m].tokval>0)
     578    {
     579      fprintf(outfile,"* %s::\n",cmds[m].name);
     580    }
     581  }
     582  fprintf(outfile, "@end menu\n@c ---------------------------\n");
     583  for(m=0; m<cmd_size; m++)
     584  {
     585    // assume that cmds[0].tokval== -1 and all others with tokval -1 at the end
     586    if(cmds[m].tokval>0)
     587    {
     588      fprintf(outfile,"@node %s,",cmds[m].name);
     589      // next:
     590      if (cmds[m+1].tokval>0)
     591        fprintf(outfile,"%s,",cmds[m+1].name);
     592      else
     593        fprintf(outfile,",");
     594      // prev:
     595      if (cmds[m-1].tokval>0)
     596        fprintf(outfile,"%s,",cmds[m-1].name);
     597      else
     598        fprintf(outfile,",");
     599      // up:, and header
     600      fprintf(outfile,"Functions\n"
     601      "@subsection %s\n"
     602      "@cindex %s\n",cmds[m].name,cmds[m].name);
     603      fprintf(outfile,"@include %s.part\n",cmds[m].name);
     604      char partName[50];
     605      sprintf(partName,"%s.part",cmds[m].name);
     606      struct stat buf;
     607      if (lstat(partName,&buf)!=0)
     608      {
     609        int op,i;
     610        int only_field=0,only_comm=0,no_zerodiv=0;
     611        FILE *part=fopen(partName,"w");
     612        fprintf(part,"@table @code\n@item @strong{Syntax:}\n");
     613        if ((cmds[m].toktype==CMD_1)
     614        || (cmds[m].toktype==CMD_12)
     615        || (cmds[m].toktype==CMD_13)
     616        || (cmds[m].toktype==CMD_123))
     617        {
     618          op= cmds[m].tokval;
     619          i=0;
     620          while ((dArith1[i].cmd!=op) && (dArith1[i].cmd!=0)) i++;
     621          while (dArith1[i].cmd==op)
     622          {
     623            if (dArith1[i].p!=jjWRONG)
     624            {
     625              fprintf(part,"@code{%s (} %s @code{)}\n",cmds[m].name,Tok2Cmdname(dArith1[i].arg));
     626              fprintf(part,"@item @strong{Type:}\n%s\n",Tok2Cmdname(dArith1[i].res));
     627              if ((dArith1[i].valid_for & ALLOW_PLURAL)==0)
     628                only_comm=1;
     629              if ((dArith1[i].valid_for & ALLOW_RING)==0)
     630                only_field=1;
     631              if ((dArith1[i].valid_for & ZERODIVISOR_MASK)==NO_ZERODIVISOR)
     632                no_zerodiv=1;
     633            }
     634            i++;
     635          }
     636        }
     637        if ((cmds[m].toktype==CMD_23)
     638        || (cmds[m].toktype==CMD_12)
     639        || (cmds[m].toktype==CMD_2)
     640        || (cmds[m].toktype==CMD_123))
     641        {
     642          op= cmds[m].tokval;
     643          i=0;
     644          while ((dArith2[i].cmd!=op) && (dArith2[i].cmd!=0)) i++;
     645          while (dArith2[i].cmd==op)
     646          {
     647            if (dArith2[i].p!=jjWRONG)
     648            {
     649              fprintf(part,"@code{%s (} %s, %s @code{)}\n",cmds[m].name,Tok2Cmdname(dArith2[i].arg1),Tok2Cmdname(dArith2[i].arg2));
     650              fprintf(part,"@item @strong{Type:}\n%s\n",Tok2Cmdname(dArith2[i].res));
     651              if ((dArith2[i].valid_for & ALLOW_PLURAL)==0)
     652                 only_comm=1;
     653              if ((dArith2[i].valid_for & ALLOW_RING)==0)
     654                 only_field=1;
     655              if ((dArith2[i].valid_for & ZERODIVISOR_MASK)==NO_ZERODIVISOR)
     656                no_zerodiv=1;
     657            }
     658            i++;
     659          }
     660        }
     661        if ((cmds[m].toktype==CMD_23)
     662        || (cmds[m].toktype==CMD_13)
     663        || (cmds[m].toktype==CMD_3)
     664        || (cmds[m].toktype==CMD_123))
     665        {
     666          op= cmds[m].tokval;
     667          i=0;
     668          while ((dArith3[i].cmd!=op) && (dArith3[i].cmd!=0)) i++;
     669          while (dArith3[i].cmd==op)
     670          {
     671            if (dArith3[i].p!=jjWRONG)
     672            {
     673              fprintf(part,"@code{%s (} %s, %s, %s @code{)}\n",cmds[m].name,
     674                Tok2Cmdname(dArith3[i].arg1),
     675                Tok2Cmdname(dArith3[i].arg2),
     676                Tok2Cmdname(dArith3[i].arg3));
     677              fprintf(part,"@item @strong{Type:}\n%s\n",Tok2Cmdname(dArith3[i].res));
     678              if ((dArith3[i].valid_for & ALLOW_PLURAL)==0)
     679                only_comm=1;
     680              if ((dArith3[i].valid_for & ALLOW_RING)==0)
     681                only_field=1;
     682              if ((dArith3[i].valid_for & ZERODIVISOR_MASK)==NO_ZERODIVISOR)
     683                no_zerodiv=1;
     684            }
     685            i++;
     686          }
     687        }
     688        if (cmds[m].toktype==CMD_M)
     689        {
     690          op= cmds[m].tokval;
     691          i=0;
     692          while ((dArithM[i].cmd!=op) && (dArithM[i].cmd!=0)) i++;
     693          while (dArithM[i].cmd==op)
     694          {
     695            if (dArithM[i].p!=jjWRONG)
     696            {
     697              fprintf(part,"@code{%s (} ... @code{)}\n",cmds[m].name);
     698              fprintf(part,"@item @strong{Type:}\n%s\n",Tok2Cmdname(dArithM[i].res));
     699              if ((dArithM[i].valid_for & ALLOW_PLURAL)==0)
     700                only_comm=1;
     701              if ((dArithM[i].valid_for & ALLOW_RING)==0)
     702                only_field=1;
     703              if ((dArithM[i].valid_for & ZERODIVISOR_MASK)==NO_ZERODIVISOR)
     704                no_zerodiv=1;
     705            }
     706            i++;
     707          }
     708        }
     709        if (only_comm)
     710              fprintf(part,"@item @strong{Remark:}\n"
     711                           "only for commutive polynomial rings\n");
     712        if (only_field)
     713              fprintf(part,"@item @strong{Remark:}\n"
     714                           "only for polynomial rings over fields\n");
     715        if (no_zerodiv)
     716              fprintf(part,"@item @strong{Remark:}\n"
     717                           "only for polynomial rings over domains\n");
     718        fprintf(part,"@item @strong{Purpose:}\n"
     719                     "@item @strong{Example:}\n"
     720                     "@smallexample\n"
     721                     "@c example\n"
     722                     "@c example\n"
     723                     "@end smallexample\n"
     724                     "@c ref\n"
     725                     "@c See\n"
     726                     "@c ref{....};\n"
     727                     "@c ref{....}.\n"
     728                     "@c ref\n");
     729        fclose(part);
     730      }
     731    }
     732  }
    714733  fclose(outfile);
    715734}
    716 #endif
     735/*-------------------------------------------------------------------*/
    717736void ttGen4()
    718737{
     
    846865  fprintf(outfile,"@end table\n");
    847866  fclose(outfile);
    848 }
    849 /*-------------------------------------------------------------------*/
    850 
    851   // some special cmds which do not fit in with the others, and
    852   // nevertheless need to be transmitted
    853 short ExtraCmds[] =
    854 {
    855   OPTION_CMD,
    856   NAMES_CMD,
    857 //  RESERVEDNAME_CMD,
    858   PROC_CMD,
    859   MAP_CMD,
    860   PACKAGE_CMD,
    861   '=',
    862   0
    863 };
    864 
    865 // This returns 1 if tok is a token which can appear in a Singular
    866 // (quoted) command, and 0 otherwise
    867 short IsCmdToken(short tok)
    868 {
    869   int i = 0;
    870   // cmds with one arg
    871   while (dArith1[i].cmd != 0)
    872     if (dArith1[i].cmd == tok) return 1;
    873     else i++;
    874 
    875   // cmds with two args
    876   i=0;
    877   while (dArith2[i].cmd != 0)
    878     if (dArith2[i].cmd == tok) return 1;
    879     else i++;
    880 
    881   // cmds with three args
    882   i=0;
    883   while (dArith3[i].cmd != 0)
    884     if (dArith3[i].cmd == tok) return 1;
    885     else i++;
    886 
    887   // cmds with many args
    888   i=0;
    889   while (dArithM[i].cmd != 0)
    890     if (dArithM[i].cmd == tok) return 1;
    891     else i++;
    892 
    893   // cmds which are somewhat special (like those having 0 args)
    894   i=0;
    895   while (ExtraCmds[i] != 0)
    896     if (ExtraCmds[i] == tok) return 1;
    897     else i++;
    898 
    899   return 0;
    900 }
     867  rename("plural_cmd.xx","plural_cmd.inc");
     868}
     869/*-------------------------------------------------------------------*/
    901870
    902871int main()
    903872{
    904   ttGen4();
     873  //ttGen4();
    905874  ttGen1();
    906875  ttGen2b();
     876  //ttGen2c();
    907877  rename(iparith_inc,"iparith.inc");
    908   rename("plural_cmd.xx","plural_cmd.inc");
    909878  return 0;
    910879}
  • Singular/tok.h

    rdaf33c rfb0ad9a  
    88*/
    99
    10 #ifndef MYYSTYPE
    11 #include <kernel/structs.h>
    12 #endif
    1310#ifndef UMINUS
    1411#include <Singular/grammar.h>
     
    3734#define ANY_TYPE          UMINUS+3
    3835#define IDHDL             UMINUS+4
    39 #define NSHDL             UMINUS+5
    4036
    4137enum {
Note: See TracChangeset for help on using the changeset viewer.