1 | A [^ \n\r\t\\;] |
---|
2 | AO [a-zA-Z] |
---|
3 | W [ \t]+ |
---|
4 | S .* |
---|
5 | %{ |
---|
6 | #undef yywrap |
---|
7 | #define countlines() {char *s=yytext;while(*s!='\0')if(*(s++)=='\n')lineno++;} |
---|
8 | #define getstring() yylval.s=(char *)malloc(yyleng+1);strcpy(yylval.s,yytext) |
---|
9 | #define getshcmd() { int i=0; \ |
---|
10 | while ( yytext[i] == ' ' || yytext[i] == '\t') i++; \ |
---|
11 | i++; /* over the % or $ */ \ |
---|
12 | if (yytext[i] == ' ') i++; \ |
---|
13 | yylval.s=(char *)malloc(yyleng+1-i); \ |
---|
14 | strcpy(yylval.s,&yytext[i]); \ |
---|
15 | } |
---|
16 | #define rtn(st) { extern int verbosef; if (verbosef>3) printf("LEX returning st\n") ; return st; } |
---|
17 | |
---|
18 | #define useonly(nn) { int i; for(i=yyleng-1;i>=(nn);i--) unput(yytext[i]); } |
---|
19 | |
---|
20 | static int parenlevel; |
---|
21 | %} |
---|
22 | %Start MapGE MapTypes MapDests ActGE ActTypes ActOpts WhenGE WhenTypes IfExp IfPExp SetVar Rule |
---|
23 | %e 2000 |
---|
24 | %p 5000 |
---|
25 | %n 2000 |
---|
26 | %k 2000 |
---|
27 | %a 30000 |
---|
28 | %o 30000 |
---|
29 | %% |
---|
30 | \\. { yylval.c = yytext[1]; rtn(ALPHANUM); } |
---|
31 | <MapGE>\n { BEGIN 0; countlines(); rtn(GE_END); } |
---|
32 | <MapGE>{W}+ { BEGIN MapDests; rtn(GE_END); } |
---|
33 | <MapGE>";".* { useonly(1); BEGIN MapTypes; rtn(GE_END); } |
---|
34 | <MapGE>{A} { yylval.c = yytext[0]; rtn(ALPHANUM); } |
---|
35 | <MapGE>. { yylval.c = yytext[0]; rtn(yytext[0]); } |
---|
36 | <MapTypes>{AO}+ { getstring(); BEGIN MapDests; rtn(FILETYPES); } |
---|
37 | <MapTypes>. { rtn(yytext[0]); /* parser error */ } |
---|
38 | <MapDests>({A}|"$"|":")+ { getstring(); rtn(MAPDEST); } |
---|
39 | <ActGE>\n { BEGIN 0; countlines(); rtn(GE_END); } |
---|
40 | <ActGE>{W}+ { BEGIN ActOpts; rtn(GE_END); } |
---|
41 | <ActGE>";".* { useonly(1); BEGIN ActTypes; rtn(GE_END); } |
---|
42 | <ActGE>{A} { yylval.c=yytext[0]; rtn(ALPHANUM); } |
---|
43 | <ActGE>. { yylval.c=yytext[0]; rtn(yytext[0]);} |
---|
44 | <ActTypes>{AO}+ { getstring(); BEGIN ActOpts; rtn(FILETYPES);} |
---|
45 | <ActTypes>. { rtn(yytext[0]); /* error */ } |
---|
46 | <ActOpts>"-"{AO} { yylval.c = yytext[1]; rtn(ACTIONOPT); } |
---|
47 | <WhenGE>\n { BEGIN 0; countlines(); rtn(GE_END); } |
---|
48 | <WhenGE>{W}+ { BEGIN 0; rtn(GE_END); } |
---|
49 | <WhenGE>";".* { useonly(1); BEGIN WhenTypes; rtn(GE_END); } |
---|
50 | <WhenGE>{A} { yylval.c=yytext[0]; rtn(ALPHANUM); } |
---|
51 | <WhenGE>. { yylval.c=yytext[0]; rtn(yytext[0]); } |
---|
52 | <WhenTypes>{AO}+ { getstring(); BEGIN 0; rtn(FILETYPES); } |
---|
53 | <WhenTypes>. { rtn(yytext[0]); /* error */ } |
---|
54 | <SetVar>{A}+ { getstring(); BEGIN Rule; rtn(BOOLVAR); } |
---|
55 | <IfExp>{A}+ { getstring(); BEGIN Rule; rtn(BOOLVAR); } |
---|
56 | <IfExp>"(" { BEGIN IfPExp; parenlevel = 1; rtn('('); /*)*/ } |
---|
57 | <IfPExp>{A}+ { getstring(); rtn(BOOLVAR); } |
---|
58 | <IfPExp>"(" { parenlevel++; rtn('('); /*)*/ } |
---|
59 | <IfPExp>")" { if(--parenlevel==0) BEGIN Rule; /*(*/ rtn(')'); } |
---|
60 | {W} ; |
---|
61 | <Rule>map{W} { BEGIN MapGE; rtn(MAP); } |
---|
62 | <Rule>copy{W} { BEGIN ActGE; rtn(COPY); } |
---|
63 | <Rule>local{W} { BEGIN ActGE; rtn(LOCAL); } |
---|
64 | <Rule>link{W} { BEGIN ActGE; rtn(LINK); } |
---|
65 | <Rule>delete{W} { BEGIN ActGE; rtn(DELETE); } |
---|
66 | <Rule>ignore{W} { BEGIN ActGE; rtn(IGNORE); } |
---|
67 | <Rule>chase{W} { BEGIN ActGE; rtn(CHASE); } |
---|
68 | <Rule>when{W} { BEGIN WhenGE; rtn(WHEN); } |
---|
69 | <Rule>set{W} { BEGIN SetVar; rtn(SET); } |
---|
70 | <Rule>unset{W} { BEGIN SetVar; rtn(UNSET); } |
---|
71 | <Rule>if{W} { BEGIN IfExp; rtn(IF); } |
---|
72 | <Rule>else { BEGIN 0; rtn(ELSE); } |
---|
73 | <Rule>begin { BEGIN 0; rtn(BEGIN_); } |
---|
74 | <Rule>\n { BEGIN 0; countlines(); } |
---|
75 | ^{W}?map{W} { BEGIN MapGE; rtn(MAP); } |
---|
76 | ^{W}?copy{W} { BEGIN ActGE; rtn(COPY); } |
---|
77 | ^{W}?local{W} { BEGIN ActGE; rtn(LOCAL); } |
---|
78 | ^{W}?link{W} { BEGIN ActGE; rtn(LINK); } |
---|
79 | ^{W}?delete{W} { BEGIN ActGE; rtn(DELETE); } |
---|
80 | ^{W}?ignore{W} { BEGIN ActGE; rtn(IGNORE); } |
---|
81 | ^{W}?chase{W} { BEGIN ActGE; rtn(CHASE); } |
---|
82 | ^{W}?when{W} { BEGIN WhenGE; rtn(WHEN); } |
---|
83 | ^{W}?set{W} { BEGIN SetVar; rtn(SET); } |
---|
84 | ^{W}?unset{W} { BEGIN SetVar; rtn(UNSET); } |
---|
85 | ^{W}?if{W} { BEGIN IfExp; rtn(IF); } |
---|
86 | ^{W}?else { BEGIN 0; rtn(ELSE); } |
---|
87 | ^{W}?begin { rtn(BEGIN_); } |
---|
88 | ^{W}?end { rtn(END); } |
---|
89 | ^{W}?"%".*\n { getshcmd(); countlines(); rtn(CSH_CMD);} |
---|
90 | ^{W}?"$".*\n { getshcmd(); countlines(); rtn(SH_CMD);} |
---|
91 | ";".* ; |
---|
92 | . { yylval.c = yytext[0]; return yytext[0]; } |
---|
93 | \n { countlines(); BEGIN 0; } |
---|
94 | %% |
---|
95 | yysetin(i) |
---|
96 | FILE *i; |
---|
97 | { yyin = i; } |
---|
98 | |
---|
99 | int yywrap() |
---|
100 | { |
---|
101 | return 1; |
---|
102 | } |
---|