home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 173_01 / pr.lxi < prev    next >
Text File  |  1979-12-31  |  3KB  |  117 lines

  1.  
  2. /*
  3.  * Token analyser for HOC
  4.  */
  5. white   = [\n\t ];              /* End of a word        */
  6. alpha   = [a-zA-Z];
  7. number  = [0-9];
  8. any     = (alpha|number)*;
  9. operator = [\41\43-\57\72-\77\133-\140\173-\175];
  10. quote   = ["];
  11. string  = (white|alpha|number|operator)*;
  12. int     = number(number)*;
  13. eol     = [;];                 /* End of input line    */
  14. /* ignore  = [\41-\100]; */
  15. illegal = [\0-\377];           /* Skip over junk       */
  16.  
  17. %{
  18. #define TRUE 1
  19. #define FALSE 0
  20. char            line[133];
  21. char            *linep          = &line[0];
  22. int             col, line_cnt;
  23. char            buff[80], *str_token, *print_token;
  24. int             is_eof          = 0;
  25. int             wordct          = 0;
  26. int             flg_case = FALSE;
  27. int             str_len;
  28.  
  29. extern void getline();
  30. #include "stdlib.h"
  31. #define T_EOL   1
  32. #define SYMBOLE LEXSKIP
  33. #define STRING  LEXSKIP
  34. #define INTEGER LEXSKIP
  35. #define FLOAT   LEXSKIP
  36. #define HEADER  LEXSKIP
  37. #define COMMAND LEXSKIP
  38. int int_x;
  39.  
  40.  
  41. void main(argc,argv)
  42. int argc;
  43. char *argv[];
  44. {
  45.         int    i;
  46.         line_cnt = 1;
  47.         col = 1;
  48.         printf("Lexical analyser for HOC -- Test Program\n");
  49. /*      lexin = fopen("test.lxi", "r"); */
  50.         while ((i = yylex()) != 0) {
  51.                 /*
  52.                  * If the "end-of-line" token is  returned
  53.                  * AND  we're really at the end of a line,
  54.                  * read the next line.  Note that T_EOL is
  55.                  * returned  twice when the program starts
  56.                  * because of the nature of the look-ahead
  57.                  * algorithms.
  58.                  */
  59.         }
  60.         exit(0);
  61. }
  62. %}
  63. %%
  64.  
  65. white(white)*  {
  66.                           return(LEXSKIP);
  67.        }
  68. quote string quote {
  69.     gettoken(buff, sizeof(buff) );
  70.     printf("string: %s\n", buff);
  71.     return(STRING);
  72. }
  73. int             {
  74.                           gettoken( buff, sizeof(buff) );
  75.                           int_x = atoi(buff);
  76.                           printf("Integer %d \n", int_x );
  77.                           return(INTEGER);
  78.                 }
  79. ("." int | int "." | int "." int) {
  80.                           gettoken( buff, sizeof(buff) );
  81.                           printf("Float %s\n", buff );
  82.                           return(FLOAT);
  83.                 }
  84.  
  85. "h" "e" "a" "d" "e" "r"     {
  86.                         str_token = gets( buff );
  87.                         printf("printf(\"%s\");\n",str_token);
  88.                         return(HEADER);
  89.                 }
  90. alpha any {
  91.                 gettoken( buff, sizeof(buff) );
  92.                 printf("Symbole: %s\n", buff);
  93.                 return(SYMBOLE);
  94.                 }
  95. "@" alpha any  {
  96.                gettoken( buff, sizeof(buff) );
  97.                printf("Command: %s\n", buff); return(COMMAND);
  98.                }
  99. "@" "(" int "," int ")"
  100.                {
  101.                gettoken( buff, sizeof(buff) );
  102.                printf("Locator: %s\n", buff); return(COMMAND);
  103.                }
  104. operator       {
  105.                gettoken( buff, sizeof(buff) );
  106.                printf("Operator = %c\n", buff[0]);
  107.                return( buff[0] );
  108.                }
  109. eol            {
  110.                         return(T_EOL);
  111.                }
  112. %%
  113.  
  114.        return( buff[0] );
  115.                }
  116. eol            {
  117.