这里是输入文件,.l文件,.y文件和输出。递归解析
问题是,解析器将无法递归识别方向..
它是确定只是第一...
我用同样的规则识别端口及其工作
但不是在案件方向的..
也它不显示与规则(COUT语句)相关.Y文件代码
输入文件。
start a b c d //ports
a:O b:I c:B d:O //direction of ports
.L文件
[\t]+ {}
[\n] {line_num++; cout"line_num:" line_num; }
start { cout< "beggining of file"; return START;}
[a-zA-Z0-9_\-]+:[IOB] {cout<<"\ndirection:" << strdup(yytext); return DR; }
[a-zA-Z0-9_\-]+ {cout<<"\nfound name:" strdup(yytext); return NAME;}
.Y文件语法
doc : START ports dir
ports : NAME ports { cout<<"\port in .y" $1;}
| NAME { cout<<"\nport in .y" $1;}
;
dir : DR dir { cout<<"\ndirection in .y" $1;}
| DR { cout<<"\ndirection in .y"<<$1; }
;
输出。文件
开始
found name:a
found name:b
found name:c
found name:d
line no-2
direction:a:O
我没有看到放弃普通空间的lex规则,也就是我看到'[\ t] +',或者只是'\ s +'。你确定输入文件的第二行是用制表符分隔的,而不是空格吗? – 2013-02-27 14:23:56
[\ t] +是完美的工作...我已经多次使用这个规则... – user2114865 2013-02-28 05:33:03