home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / Watcher / yylex.l < prev   
Encoding:
Lex Description  |  1990-02-02  |  1.9 KB  |  98 lines

  1. %{
  2. /*
  3.    yylex.l: lex version of the lexical analyzer for watcher.
  4.  
  5.    Kenneth Ingham
  6.  
  7.    Copyright (C) 1989 The University of New Mexico
  8. */
  9.  
  10. #include "defs.h"
  11. #include "y.tab.h"
  12.  
  13. extern int lexverbose;
  14. extern int control_line;
  15. %}
  16.  
  17. %%
  18.  
  19. "."        return '.';
  20. ","        return ',';
  21. ";"        return ';';
  22. ":"        return ':';
  23. "%"        return '%';
  24. "-"        return '-';
  25. "+"        return '+';
  26. "{"        return '{';
  27. "}"        return '}';
  28.  
  29. \([^)]*\)    {    /* pipeline */
  30.             /* start at 1 due to ( */
  31.             yylval.str = strnsave(&yytext[1], yyleng-2);
  32.             yylval.str[yyleng-2] = '\0';
  33.             if (lexverbose)
  34.                 printf("pipeline: '%s'\n", yylval.str);
  35.             return PIPELINE;
  36.         }
  37.  
  38. [0-9]*\.[0-9]+    {    /* float */
  39.             /*
  40.                note a float cannot end in a . since we also
  41.                end entries with '.' and we couldn't tell
  42.                them apart (unless we used lookahead)
  43.             */
  44.  
  45.             yylval.real = (float) atof(yytext);
  46.             if (lexverbose)
  47.                 printf("float: '%f'\n", yylval.real);
  48.             return FLOAT;
  49.         }
  50.  
  51. [0-9]+        {    /* integer */
  52.  
  53.             yylval.integer = atoi(yytext);
  54.             if (lexverbose)
  55.                 printf("integer: '%d'\n", yylval.integer);
  56.             return INTEGER;
  57.         }
  58.  
  59. ('[^\']*')|(\"[^\"]*\")    {    /* string in 's or "s */
  60.             /* copy, *except* for 's */
  61.             yylval.str = strnsave(&yytext[1], yyleng-2);
  62.             yylval.str[yyleng-2] = '\0';
  63.  
  64.             if (lexverbose)
  65.                 printf("string in %cs: '%s'\n", yytext[0],
  66.                        yylval.str);
  67.  
  68.             if (yytext[0] == '"')
  69.                 return QUOTED_STRING;
  70.             else /* string is in 's */
  71.                 return STRING;
  72.         }
  73.  
  74. [a-zA-Z_][a-zA-Z_0-9]*    {/* string */
  75.             yylval.str = strsave(yytext);
  76.  
  77.             if (lexverbose)
  78.                 printf("string: '%s'\n", yytext);
  79.  
  80.             return STRING;
  81.         }
  82.  
  83. [ \t]+        ; /* white space - ignored */
  84.  
  85. \n        { control_line++; } /* newline - ignored except to note it */
  86.  
  87. \#[^\n]*    ; /* comment - ignored */
  88.  
  89. %%
  90.  
  91. /*
  92.    yywrap tells lex whether to stop at end of file or not.  It is
  93.    assummed by lex that if yywrap returns 0 then lex can continue
  94.    looking for tokens.  In our case, EOF means we're done with the
  95.    control file.
  96. */
  97. yywrap() {return 1;}
  98.