D:\UnxUtils>a
did I have fun?
did: is a verb
I: is not a verb
have: is a verb
fun: is not a verb
?
^Z
D:\UnxUtils>
//example.txt
did I have fun?
If our time is usefully employed, it will either turn out some useful and important piece of work which will fetch its price in the market, or it will add to our experience and increase our capacities so as to enable us to earn money when the proper opportunity comes. Let those, who think nothing of wasting time, remember this.
lex 与yacc ch1-02.l 识别单词 正确代码如下:
%{
/*
* 例1-1 单词识别程序 ch1-02.l
* 识别单词是否是动词
*/
%}
%%
[\t ]+ /*意味着空格的正闭包,忽略空白*/;
is |
am |
are |
were |
was |
be |
being |
been |
do |
does |
did |
will |
would |
should |
can |
could |
has |
have |
had |
go {printf("%s: is a verb\n",yytext);}
[a-zA-Z]+ {printf("%s: is not a verb\n",yytext);}
.|\n {ECHO;/*通常的默认状态:输出匹配模式,复制标点或其它字符*/}
%%
int main()
{
yyin = fopen("example.txt","r");
yylex();
fclose(yyin);
}
int yywrap()
{
return 1;
}
D:\UnxUtils>a
did I have fun?
did: is a verb
I: is not a verb
have: is a verb
fun: is not a verb
?
^Z
D:\UnxUtils>a
did: is a verb
I: is not a verb
have: is a verb
fun: is not a verb
?
If: is not a verb
our: is not a verb
time: is not a verb
is: is a verb
usefully: is not a verb
employed: is not a verb
,it: is not a verb
will: is a verb
either: is not a verb
turn: is not a verb
out: is not a verb
some: is not a verb
useful: is not a verb
and: is not a verb
important: is not a verb
piece: is not a verb
of: is not a verb
work: is not a verb
which: is not a verb
will: is a verb
fetch: is not a verb
its: is not a verb
price: is not a verb
in: is not a verb
the: is not a verb
market: is not a verb
,or: is not a verb
it: is not a verb
will: is a verb
add: is not a verb
to: is not a verb
our: is not a verb
experience: is not a verb
and: is not a verb
increase: is not a verb
our: is not a verb
capacities: is not a verb
so: is not a verb
as: is not a verb
to: is not a verb
enable: is not a verb
us: is not a verb
to: is not a verb
earn: is not a verb
money: is not a verb
when: is not a verb
the: is not a verb
proper: is not a verb
opportunity: is not a verb
comes: is not a verb
.Let: is not a verb
those: is not a verb
,who: is not a verb
think: is not a verb
nothing: is not a verb
of: is not a verb
wasting: is not a verb
time: is not a verb
,remember: is not a verb
this: is not a verb
.