我写了一个lex程序,但我在第9行有一个错误。 [英] I write a lex program but I have an error on line 9.
本文介绍了我写了一个lex程序,但我在第9行有一个错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个程序,该程序通过{和}括起来的.txt元素进行识别。程序将结果打印在另一个.txt文件中。当我运行命令lex b4.l时,我在第9行有两个错误
坏字符类和无法识别的规则
我尝试过:
%{
#include< stdio.h>
%}
word [ab] +
nr [3-9] [0-9] [0-9] | [1-9] [0,9] {3 ,}
el {nr} |([az] [az})* [az}
list{{el}(,{el})+}
%%
{list} {printf(%s \ n,yylex);}
(。* {word}。*){2,} \ n {ECHO;}
。| \\\
;
%%
int main(int argc,char ** argv){
FILE * g;
if(argc> 0)
yyin = fopen(argv [1],r);
if(!(g = fopen(a.txt,w)))
fprintf(stderr,error);
else
yyout = g;
yylex();
}
解决方案
Quote:el {nr} |([az] [az})* [az}
以上规则对我来说不正确(什么是
[az}
?)
I write a program that recognizes from a .txt elements enclosed by "{" and "}". The program print the result in another .txt file. When I run the command lex b4.l I have two errors on line 9
"bad character class" and "unrecognized rule"
What I have tried:
%{ #include<stdio.h> %} word [ab]+" " nr [3-9][0-9][0-9]|[1-9][0,9]{3,} el {nr}|([a-z][a-z})*[a-z} list "{"{el}(,{el})+"}" %% {list} {printf("%s\n",yylex);} (.*{word}.*){2,}\n {ECHO;} .|\n; %% int main(int argc, char**argv){ FILE *g; if(argc>0) yyin = fopen(argv[1], "r"); if(!(g=fopen("a.txt", "w"))) fprintf(stderr, "error"); else yyout=g; yylex(); }
解决方案
Quote:el {nr}|([a-z][a-z})*[a-z}
The above rule looks incorrect to me (what is
[a-z}
?).
这篇关于我写了一个lex程序,但我在第9行有一个错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文