home *** CD-ROM | disk | FTP | other *** search
/ ftp.shrubbery.net / 2015-02-07.ftp.shrubbery.net.tar / ftp.shrubbery.net / pub / foad / foad-0.3.tar.gz / foad-0.3.tar / foad-0.3 / lexer.l < prev    next >
Text File  |  2001-06-11  |  2KB  |  117 lines

  1. %{
  2. #include "foad.h"
  3. #include "parser.h"
  4.  
  5. extern char            *progname;        /* program's name */
  6. extern int        debug;
  7.  
  8. #define    L_DEBUG        (debug > 2)
  9. %}
  10.  
  11. WS      [ \t]+
  12. DATA    [^ \t]
  13. BCC    [Bb][Cc]{2}
  14. FROM    [Fr][Rr][Oo][Mm]
  15. CC    [Cc]{2}
  16. TO    [Tt][Oo]
  17. R    [Rr][Ee][Ss][Ee][Nn][Tt]-
  18.  
  19. %s bcc
  20. %s cc
  21. %s to
  22.  
  23. %%
  24. \n        {
  25.           if (L_DEBUG)
  26.             fprintf(stderr, "%s: lexer \\n\n", progname);
  27.           return('\n');
  28.         }
  29.  
  30. ^({R})?{TO}:{WS}.*$    {
  31.           if (L_DEBUG)
  32.             fprintf(stderr, "%s: lexer to: %s\n", progname, yytext);
  33.           BEGIN(to);
  34.           yylval.cptr = strdup(index(yytext, ':') + 1);
  35.           return T_TO;
  36.         }
  37. <to>^{WS}.+$    {
  38.           if (L_DEBUG)
  39.             fprintf(stderr, "%s: lexer to continuation: %s\n",
  40.                 progname, yytext);
  41.           yylval.cptr = strdup(yytext);
  42.           return T_TO_CONT;
  43.         }
  44.  
  45. ^({R})?{CC}:{WS}.*$    {
  46.           if (L_DEBUG)
  47.             fprintf(stderr, "%s: lexer cc: %s\n", progname, yytext);
  48.           BEGIN(cc);
  49.           yylval.cptr = strdup(index(yytext, ':') + 1);
  50.           return T_CC;
  51.         }
  52. <cc>^{WS}.+$    {
  53.           if (L_DEBUG)
  54.             fprintf(stderr, "%s: lexer cc continuation: %s\n",
  55.                 progname, yytext);
  56.           yylval.cptr = strdup(yytext);
  57.           return T_CC_CONT;
  58.         }
  59.  
  60. ^({R})?{BCC}:{WS}.*$    {
  61.           if (L_DEBUG)
  62.             fprintf(stderr, "%s: lexer bcc: %s\n", progname,
  63.                 yytext);
  64.           BEGIN(cc);
  65.           yylval.cptr = strdup(index(yytext, ':') + 1);
  66.           return T_BCC;
  67.         }
  68. <bcc>^{WS}.+$    {
  69.           if (L_DEBUG)
  70.             fprintf(stderr, "%s: lexer bcc continuation: %s\n",
  71.                 progname, yytext);
  72.           yylval.cptr = strdup(yytext);
  73.           return T_BCC_CONT;
  74.         }
  75.  
  76. ^{FROM}:{WS}.*$    {
  77.           if (L_DEBUG)
  78.             fprintf(stderr, "%s: lexer from: %s\n", progname,
  79.                 yytext);
  80.           BEGIN(0);
  81.           yylval.cptr = strdup(index(yytext, ':') + 1);
  82.           return T_FROM;
  83.         }
  84.  
  85. <INITIAL>^{WS}.+$    {
  86.           if (L_DEBUG)
  87.             fprintf(stderr, "%s: lexer continuation: %s\n", progname, yytext);
  88.           return T_CONT;
  89.         }
  90.  
  91. ^{DATA}+:{WS}.*$        {
  92.           if (L_DEBUG)
  93.             fprintf(stderr, "%s: lexer header: %s\n", progname, yytext);
  94.           BEGIN(0);
  95.           return T_LINE; }
  96.  
  97. .        {
  98.           if (L_DEBUG)
  99.             fprintf(stderr, "%s: lexer char: %c\n", progname, yytext[0]);
  100.           BEGIN(0);
  101.           /*return(conf_text[0]);*/
  102.         }
  103. %%
  104.  
  105. yyerror (char *s)
  106. {
  107.     if (s != NULL)
  108.        fprintf(stderr, "%s: %s at or near %s\n", progname, s, yytext);
  109.     else  
  110.        fprintf(stderr, "%s: header parser error at %s\n", progname, yytext);
  111. }
  112.  
  113. yywrap(void)
  114. {
  115.     return(1);
  116. }
  117.