/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        A N A L Y S E   D E S   E X P R E S S I O N S   D U   P R E - P R O C E S S E U R   ' cpp '  :                             */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        Author of '$xcp/cpp$D/beau_yylex$c' :                                                                                      */
/*                                                                                                                                   */
/*                    Unknown...                                                                                                     */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        Version amelioree de '$xcp/cpp$D/beau_yylex$c' par :                                                                       */
/*                                                                                                                                   */
/*                    Jean-Francois Colonna (LACTAMME, AAAAMMJJhhmmss).                                                              */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

#define   CHAR      char

                                        /* ATTENTION : ne pas mettre :                                                               */
                                        /*                                                                                           */
                                        /* #ifdef    SYSTEME_FX2800_CONCENTRIX_SCC                                                   */
                                        /* #undef    CHAR                                                                            */
                                        /* #define   CHAR unsigned char                                                              */
                                        /* #else     SYSTEME_FX2800_CONCENTRIX_SCC                                                   */
                                        /* #endif    SYSTEME_FX2800_CONCENTRIX_SCC                                                   */
                                        /*                                                                                           */
                                        /* car paradoxalement, cela evite de gros ennuis...                                          */

#ifdef    SYSTEME_HP705_HPUX_CC
#    undef     CHAR
#    define    CHAR      unsigned char
#else     SYSTEME_HP705_HPUX_CC
#endif    SYSTEME_HP705_HPUX_CC

#ifdef    SYSTEME_HP710_HPUX_CC
#    undef     CHAR
#    define    CHAR      unsigned char
#else     SYSTEME_HP710_HPUX_CC
#endif    SYSTEME_HP710_HPUX_CC

#ifdef    SYSTEME_HP720_HPUX_CC
#    undef     CHAR
#    define    CHAR      unsigned char
#else     SYSTEME_HP720_HPUX_CC
#endif    SYSTEME_HP720_HPUX_CC

#ifdef    SYSTEME_HP750_HPUX_CC
#    undef     CHAR
#    define    CHAR      unsigned char
#else     SYSTEME_HP750_HPUX_CC
#endif    SYSTEME_HP750_HPUX_CC

#include  "beau_cpp.I"
#define   isid(a)   ((fastab+COFF)[a]&IB)
#define   IB        1
#define   COFF      0

extern    int       uflag;
                                        /* Ne pas editer (si egal 1) les messages d'erreur du type :                                 */
                                        /*                                                                                           */
                                        /*                  Error : ...: undef symbol ... in preprocessor if                         */
                                        /*                                                                                           */
yylex()
     {
     static    int       ifdef = 0;
     static    CHAR      *op2[] = {"||","&&",">>","<<",">=","<=","!=","=="};
     static    int       val2[] = {OROR,ANDAND,RS,LS,GE,LE,NE,EQ};
     static    CHAR      *opc = "b\bt\tn\nf\fr\r\\\\";
     extern    CHAR      fastab[];
     extern    CHAR      *outp,*inp,*newp;
     extern    int       flslvl;
     register  CHAR      savc,*s;
     CHAR      *skipbl();
     int       val;
     register  CHAR      **p2;
     struct    symtab
          {
          CHAR      *name;
          CHAR      *value;
          } *sp,*lookup();
     for  (;;)
          {
          newp = skipbl(newp);
          if   (*inp == '\n')
               {
                                        /* End of #if                                                                                */
               return(stop);
               }
          else
               {
               }
          savc = *newp;
          *newp = '\0';
          if   ((*inp == '/') && (inp[1] == '*'))
               {
                                        /* Found a comment with -C option, still toss here                                           */
               *newp = savc;
               outp = inp = newp;
               continue;
               }
          else
               {
               }
          for  (p2 = op2+8;--p2 >= op2;)
               {
                                        /* Check 2-char ops                                                                          */
               if   (strcmp(*p2,inp) == 0)
                    {
                    val = val2[p2-op2];
                    goto ret;
                    }
               else
                    {
                    }
               }
          s = "+-*/%<>&^|?:!~(),";
                                        /* Check 1-char ops                                                                          */
          while     (*s)
               {
               if   (*s++ == *inp)
                    {
                    val= *--s;
                    goto ret;
                    }
               else
                    {
                    }
               }
          if   ((*inp<='9') && (*inp>='0'))
                                        /* A number                                                                                  */
               {
               if   (*inp == '0')
                    {
                    yylval= ((inp[1] == 'x') || (inp[1] == 'X')) ? tobinary(inp+2,16) : tobinary(inp+1,8);
                    }
               else
                    {
                    yylval = tobinary(inp,10);
                    }
               val = number;
               }
          else
               {
               if   (isid(*inp))
                    {
                    if   ((strcmp(inp,"defined") == 0) || (strcmp(inp,"dfd") == 0))
                                        /* La fonction 'dfd(...)' a ete rajoute le 19970218103116 afin de raccourcir certaines       */
                                        /* lignes ('v $xiii/di_image$FON dfd').                                                      */
                         {
                         ifdef = 1;
                         ++flslvl;
                         val = DEFINED;
                         }
                    else
                         {
                         if   (ifdef != 0)
                              {
                                        /* Cas de la fonction 'defined(...)' (et de son equivalent 'dfd(...)') :                     */
                              register  CHAR      *p;
                              register  int       savech;
                                        /* Make sure names <= NCPS chars                                                             */
                              if   ((newp-inp) > NCPS)
                                   {
                                   p = inp+NCPS;
                                   }
                              else
                                   {
                                   p = newp;
                                   }
                              savech = *p;
                              *p = '\0';
                              sp = lookup(inp,-1);
                              *p = savech;
                              ifdef = 0;
                              --flslvl;
                              }
                         else
                              {
                                        /* Cas d'une directive '#if' :                                                               */
                              sp = lookup(inp,-1);

                              if   (sp->value == 0)
                                   {
                                   if   (uflag == 0)
                                        {
                                        yypperror("undef symbol %s in preprocessor if",inp);
                                        /* ATTENTION, dans la norme (traduite en particulier par '/lib/cpp'), lorsqu'un symbole      */
                                        /* est inexistant dans une directive '#if', il est considere comme existant avec une valeur  */
                                        /* nulle. Cela me paraissant extrement dangereux, je conserve cela, mais en editant un       */
                                        /* message d'erreur (cette modification a ete faite le 1995031600).                          */
                                        /*                                                                                           */
                                        /* Le 20210301160547, 'yypperror(...)' -a deux arguments- a remplace 'pperror(...)' -qui     */
                                        /* en demandait trois-...                                                                    */
                                        }
                                   else
                                        {
                                        }
                                   }
                              else
                                   {
                                   }
                              }
                         yylval = (sp->value == 0) ? 0 : 1;
                         val = number;
                         }
                    }
               else
                    {
                    if   (*inp == '\'')
                                        /* Character constant                                                                        */
                         {
                         val = number;
                         if   (inp[1] == '\\')
                                        /* Escaped                                                                                   */
                              {
                              CHAR      c;
                              if   (newp[-1] == '\'')
                                   {
                                   newp[-1] = '\0';
                                   }
                              else
                                   {
                                   }
                              s = opc;
                              while     (*s)
                                   {
                                   if   (*s++ != inp[2])
                                        {
                                        ++s;
                                        }
                                   else
                                        {
                                        yylval = *s;
                                        goto ret;
                                        }
                                   }
                              if   ((inp[2] <= '9') && (inp[2] >= '0'))
                                   {
                                   yylval = c = tobinary(inp+2,8);
                                   }
                              else
                                   {
                                   yylval = inp[2];
                                   }
                              }
                         else
                              yylval = inp[1];
                         }
                    else
                         {
                         if   (strcmp("\\\n",inp) == 0)
                              {
                              *newp = savc;
                              continue;
                              }
                         else
                              {
                              *newp = savc;
                              yypperror("Illegal character %c in preprocessor if",*inp);
                                        /* Le 20210301160547, 'yypperror(...)' -a deux arguments- a remplace 'pperror(...)' -qui     */
                                        /* en demandait trois-...                                                                    */
                              continue;
                              }
                         }
                    }
               }
          ret:
                                        /* Check for non-ident after defined (note need the paren!)                                  */
          if   ((ifdef) && (val != '(') && (val != DEFINED))
               {
               yypperror("\"defined\" modifying non-identifier \"%s\" in preprocessor if",inp);
                                        /* Le 20210301160547, 'yypperror(...)' -a deux arguments- a remplace 'pperror(...)' -qui     */
                                        /* en demandait trois-...                                                                    */
               ifdef = 0;
               flslvl--;
               }
          else
               {
               }
          *newp = savc;
          outp = inp = newp;
          return(val);
          }
     }

tobinary(st,b)
CHAR      *st;
     {
     int       n,c,t;
     CHAR      *s;
     n = 0;
     s = st;
     while     (c = *s++)
          {
          switch    (c)
               {
               case '0':
               case '1':
               case '2':
               case '3':
               case '4':
               case '5':
               case '6':
               case '7':
               case '8':
               case '9':
                    t = c-'0';
                    break;
               case 'a':
               case 'b':
               case 'c':
               case 'd':
               case 'e':
               case 'f':
                    t = c-'a';
                    if   (b > 10)
                         break;
               case 'A':
               case 'B':
               case 'C':
               case 'D':
               case 'E':
               case 'F':
                    t = c-'A';
                    if   (b > 10)
                         {
                         break;
                         }
                    else
                         {
                         }
               default:
                    t = -1;
                    if   ((c == 'l') || (c == 'L'))
                         {
                         if   (*s == '\0')
                              {
                              break;
                              }
                         else
                              {
                              }
                         }
                    else
                         {
                         }
                    yypperror("Illegal number %s",st);
                                        /* Le 20210301160547, 'yypperror(...)' -a deux arguments- a remplace 'pperror(...)' -qui     */
                                        /* en demandait trois-...                                                                    */
               }
          if   (t < 0)
               break;
          n = n*b+t;
          }
     return(n);
     }



Copyright © Jean-François Colonna, 2021-2021.
Copyright © CMAP (Centre de Mathématiques APpliquées) UMR CNRS 7641 / Ecole Polytechnique, 2021-2021.