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 >
Wrap
Text File
|
2001-06-11
|
2KB
|
117 lines
%{
#include "foad.h"
#include "parser.h"
extern char *progname; /* program's name */
extern int debug;
#define L_DEBUG (debug > 2)
%}
WS [ \t]+
DATA [^ \t]
BCC [Bb][Cc]{2}
FROM [Fr][Rr][Oo][Mm]
CC [Cc]{2}
TO [Tt][Oo]
R [Rr][Ee][Ss][Ee][Nn][Tt]-
%s bcc
%s cc
%s to
%%
\n {
if (L_DEBUG)
fprintf(stderr, "%s: lexer \\n\n", progname);
return('\n');
}
^({R})?{TO}:{WS}.*$ {
if (L_DEBUG)
fprintf(stderr, "%s: lexer to: %s\n", progname, yytext);
BEGIN(to);
yylval.cptr = strdup(index(yytext, ':') + 1);
return T_TO;
}
<to>^{WS}.+$ {
if (L_DEBUG)
fprintf(stderr, "%s: lexer to continuation: %s\n",
progname, yytext);
yylval.cptr = strdup(yytext);
return T_TO_CONT;
}
^({R})?{CC}:{WS}.*$ {
if (L_DEBUG)
fprintf(stderr, "%s: lexer cc: %s\n", progname, yytext);
BEGIN(cc);
yylval.cptr = strdup(index(yytext, ':') + 1);
return T_CC;
}
<cc>^{WS}.+$ {
if (L_DEBUG)
fprintf(stderr, "%s: lexer cc continuation: %s\n",
progname, yytext);
yylval.cptr = strdup(yytext);
return T_CC_CONT;
}
^({R})?{BCC}:{WS}.*$ {
if (L_DEBUG)
fprintf(stderr, "%s: lexer bcc: %s\n", progname,
yytext);
BEGIN(cc);
yylval.cptr = strdup(index(yytext, ':') + 1);
return T_BCC;
}
<bcc>^{WS}.+$ {
if (L_DEBUG)
fprintf(stderr, "%s: lexer bcc continuation: %s\n",
progname, yytext);
yylval.cptr = strdup(yytext);
return T_BCC_CONT;
}
^{FROM}:{WS}.*$ {
if (L_DEBUG)
fprintf(stderr, "%s: lexer from: %s\n", progname,
yytext);
BEGIN(0);
yylval.cptr = strdup(index(yytext, ':') + 1);
return T_FROM;
}
<INITIAL>^{WS}.+$ {
if (L_DEBUG)
fprintf(stderr, "%s: lexer continuation: %s\n", progname, yytext);
return T_CONT;
}
^{DATA}+:{WS}.*$ {
if (L_DEBUG)
fprintf(stderr, "%s: lexer header: %s\n", progname, yytext);
BEGIN(0);
return T_LINE; }
. {
if (L_DEBUG)
fprintf(stderr, "%s: lexer char: %c\n", progname, yytext[0]);
BEGIN(0);
/*return(conf_text[0]);*/
}
%%
yyerror (char *s)
{
if (s != NULL)
fprintf(stderr, "%s: %s at or near %s\n", progname, s, yytext);
else
fprintf(stderr, "%s: header parser error at %s\n", progname, yytext);
}
yywrap(void)
{
return(1);
}