RubbishBin/LexicalParser/pl_start.l

28 lines
665 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* 简单词法分析器 */
/* 功能能够识别出以小写字母ab结尾的所有字符串仅含大小写字母并给打印'Hit!' */
/* 说明在下面的begin和end之间添加代码注意格式 */
/* 提示你只需要保证合法的输入以ab结尾的字符串有结果不合法的输入将会包含在.规则中~ */
%{
#include <stdio.h>
%}
%%
/* begin */
[a-zA-Z]*ab {printf("%s: Hit!\n", yytext);}
/* end */
\n {}
. {}
%%
int yywrap() { return 1; }
int main(int argc, char **argv)
{
if (argc > 1) {
if (!(yyin = fopen(argv[1], "r"))) {
perror(argv[1]);
return 1;
}
}
while (yylex());
return 0;
}