home *** CD-ROM | disk | FTP | other *** search
/ messroms.de / 2007-01-13_www.messroms.de.zip / VZ200 / TOOLS / ZCCSRC.ZIP / scc / lex.c < prev    next >
C/C++ Source or Header  |  2000-03-01  |  2KB  |  170 lines

  1. /*    File lex.c: 2.1 (83/03/20,16:02:09) */
  2. /*% cc -O -c %
  3.  *
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include "defs.h"
  8. #include "data.h"
  9. #include "proto.h"
  10.  
  11. /*
  12.  *    semicolon enforcer
  13.  *
  14.  *    called whenever syntax requires a semicolon
  15.  *
  16.  */
  17. void ns(void)
  18. {
  19.     if (!match(";"))
  20.         error("missing semicolon");
  21. }
  22.  
  23. void junk(void)
  24. {
  25.     if (an(inbyte()))
  26.         while (an(ch()))
  27.             gch();
  28.     else
  29.         while (an(ch()))
  30.         {
  31.             if (ch() == 0)
  32.                 break;
  33.             gch();
  34.         }
  35.     blanks();
  36. }
  37.  
  38. int endst(void)
  39. {
  40.     blanks();
  41.     return ((streq(line + lptr, ";") | (ch() == 0)));
  42. }
  43.  
  44. void needbrack(char *str)
  45. {
  46.     if (!match(str))
  47.     {
  48.         error("missing bracket");
  49.         comment();
  50.         outstr(str);
  51.         nl();
  52.     }
  53. }
  54.  
  55. /*
  56.  *    test if given character is alpha
  57.  */
  58. int alpha(char c)
  59. {
  60.     c = c & 127;
  61.     return (((c >= 'a') & (c <= 'z')) |
  62.             ((c >= 'A') & (c <= 'Z')) |
  63.             (c == '_'));
  64. }
  65.  
  66. /*
  67.  *    test if given character is numeric
  68.  */
  69. int numeric(char c)
  70. {
  71.     c = c & 127;
  72.     return ((c >= '0') & (c <= '9'));
  73. }
  74.  
  75. /*
  76.  *    test if given character is alphanumeric
  77.  */
  78. int an(char c)
  79. {
  80.     return ((alpha(c)) | (numeric(c)));
  81. }
  82.  
  83. int sstreq(char *str1)
  84. {
  85.     return (streq(line + lptr, str1));
  86. }
  87.  
  88. int streq(char str1[], char str2[])
  89. {
  90.     int k;
  91.  
  92.     k = 0;
  93.     while (str2[k])
  94.     {
  95.         if ((str1[k] != str2[k]))
  96.             return (0);
  97.         k++;
  98.     }
  99.     return (k);
  100. }
  101.  
  102. int astreq(char str1[], char str2[], int len)
  103. {
  104.     int k;
  105.  
  106.     k = 0;
  107.     while (k < len)
  108.     {
  109.         if ((str1[k] != str2[k]))
  110.             break;
  111.         if (str1[k] == 0)
  112.             break;
  113.         if (str2[k] == 0)
  114.             break;
  115.         k++;
  116.     }
  117.     if (an(str1[k]))
  118.         return (0);
  119.     if (an(str2[k]))
  120.         return (0);
  121.     return (k);
  122. }
  123.  
  124. int match(char *lit)
  125. {
  126.     int k;
  127.  
  128.     blanks();
  129.     if (0!=(k = streq(line + lptr, lit)))
  130.     {
  131.         lptr = lptr + k;
  132.         return (1);
  133.     }
  134.     return (0);
  135. }
  136.  
  137. int amatch(char *lit, int len)
  138. {
  139.     int k;
  140.  
  141.     blanks();
  142.     if (0!=(k = astreq(line + lptr, lit, len)))
  143.     {
  144.         lptr = lptr + k;
  145.         while (an(ch()))
  146.             inbyte();
  147.         return (1);
  148.     }
  149.     return (0);
  150. }
  151.  
  152. void blanks(void)
  153. {
  154.     for (;;)
  155.     {
  156.         while (ch() == 0)
  157.         {
  158.             preprocess();
  159.             if (feof(input))
  160.                 break;
  161.         }
  162.         if (ch() == ' ')
  163.             gch();
  164.         else if (ch() == 9)
  165.             gch();
  166.         else
  167.             return;
  168.     }
  169. }
  170.