这里是输入文件、.l 文件、.y 文件和输出。
问题是解析器无法递归识别方向..
它只是首先识别...
我使用相同的规则来识别端口及其工作
但不是在方向的情况下..
它也没有显示与规则关联的 .y 文件代码(cout 语句)
输入文件 。
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