我正在尝试注释一个flex程序,但是编译器给了我这些错误:
chef.l:21:坏字符:/ cook.l:21:坏字符:* Chef.l:21:启动条件INW声明了两次Chef.l:21:坏字符::
我该如何解决此问题?
%{
/* chef.x - convert English on stdin to Mock Swedish on stdout
*
* The WC definition matches any word character, and the NW definition matches
* any non-word character. Two start conditions are maintained: INW (in word)
* and NIW (not in word). The first rule passes TeX commands without change.
*
* HISTORY
*
* Apr 26, 1993; John Hagerman: Added ! and ? to the Bork Bork Bork rule.
*
* Apr 15, 1992; John Hagerman: Created.
*/
static int i_seen = 0; /* There is a variable called i_seen and assign value to 0 */
%}
WC [A-Za-z'] /* WC is assigned to any words that are characters */
NW [^A-Za-z'] /* NW is assigned to any words that are non-characters */
%start INW NIW /* INW: inclusive NIW: exclusive */
%%
\\[^ \n]+ ECHO; /* If find one more character that is not a new line character, copy yytext to scanner output */
{NW} { BEGIN NIW; i_seen = 0; ECHO; } /* If find a character, i_seen = 0, copy yytext to scanner output */
[.!?]$ { BEGIN NIW; i_seen = 0;
printf("%c\nBork Bork Bork!",yytext[0]); } /* If find any .!? at the end of the line, i_seen = 0, print the first character in yytext, in next line, print Bork Bork.. */
<NIW>"bork"/{NW} ECHO; /* If bork followed by a non-character, copy to output */
<NIW>"Bork"/{NW} ECHO; /* If Bork followed by a non-character, copy to output */
"an" { BEGIN INW; printf("un"); } /* Encounter an, active INW, print un */
"An" { BEGIN INW; printf("Un"); } /* Encounter An, ..., print Un */
"au" { BEGIN INW; printf("oo"); } /* Encounter au, ..., print oo */
"Au" { BEGIN INW; printf("Oo"); } /* Encounter Au, ..., print Oo */
"a"/{WC} { BEGIN INW; printf("e"); } /* Encoutner a followed by a character, ..., print e */
"A"/{WC} { BEGIN INW; printf("E"); } /* Encounter A followed by a character, ..., print E */
"en"/{NW} { BEGIN INW; printf("ee"); } /* Encounter en followed by a non-character, ..., print ee */
<INW>"ew" { BEGIN INW; printf("oo"); } /* If bork followed by a non-character and encounter ew , ..., print oo */
<INW>"e"/{NW} { BEGIN INW; printf("e-a"); } /* If INW and e followed by NW, ..., print e-a */
<NIW>"e" { BEGIN INW; printf("i"); } /* If NIW and encounter e, ..., print i */
<NIW>"E" { BEGIN INW; printf("I"); } /* If NIW and encounter E, ..., print I */
<INW>"f" { BEGIN INW; printf("ff"); } /* If INW and encounter f, ..., print ff */
<INW>"ir" { BEGIN INW; printf("ur"); } /* If INW and encounter ir, ..., print ur */
<INW>"i" { BEGIN INW; printf(i_seen++ ? "i" : "ee"); } /* If INW and encounter i, ..., print i_seen++ ? "i" : "ee" */
<INW>"ow" { BEGIN INW; printf("oo"); } /* If INW and encounter ow, ..., print oo */
<NIW>"o" { BEGIN INW; printf("oo"); } /* If NIW and encounter o, ..., print oo */
<NIW>"O" { BEGIN INW; printf("Oo"); } /* If NIW and encounter O, ..., print Oo */
<INW>"o" { BEGIN INW; printf("u"); } /* If INW and encounter o, ..., print u */
"the" { BEGIN INW; printf("zee"); } /* If encounter the, ..., print zee */
"The" { BEGIN INW; printf("Zee"); } /* If encounter The, ..., print Zee */
"th"/{NW} { BEGIN INW; printf("t"); } /* If ecounter th followed by NW, print t */
<INW>"tion" { BEGIN INW; printf("shun"); } /* If INW and encounter tion, ..., print shun */
<INW>"u" { BEGIN INW; printf("oo"); } /* If INW and encounter u, ..., print oo */
<INW>"U" { BEGIN INW; printf("Oo"); } /* If INW and encounter U, ..., print Oo */
"v" { BEGIN INW; printf("f"); } /* If encounter v, ..., print f */
"V" { BEGIN INW; printf("F"); } /* If encounter V, ..., print F */
"w" { BEGIN INW; printf("v"); } /* If encounter w, ..., print v */
"W" { BEGIN INW; printf("V"); } /* If encounter W, ..., print V */
. { BEGIN INW; ECHO; } /* If encounter any other words, ..., copy yytext to scanner output */
缩进您的评论。 (除非它们在代码块中。)
Flex将第一个字符不是空格的行视为定义(在第一部分)或规则(在第二部分)。
缩进的行直接写入生成的扫描仪。如果他们是评论,那会没事的。
定义和大多数其他flex声明不能包含注释。