【问题标题】:Lex file unrecognized ruleLex 文件无法识别的规则
【发布时间】:2013-05-19 01:17:16
【问题描述】:

我正在尝试运行以下程序,但出现无法识别的规则:37。不知道为什么它在第 37 行给我这个错误。

命令:$ lex mycsv2html.l

%{                      //Definition Section 

#include <stdin.h>                         
#include <stdout.h>
int c;
extern int yylval;
%}


%%                      // Rule Section
" "       ;
[\n]     {
            c = yytext[0];
            yylval = c - '\n';
            return(br);
          }
["]     {
            c = yytext[0];
            yylval = c - '';
            return('');
          }
[<]     {
            c = yytext[0];
            yylval = c - '';
            return('&lt');
          }

[>]     {
            c = yytext[0];
            yylval = c - '';
            return('&gt');
          }

int main(void)                            //C Code Section
{
    /* Call the lexer, then quit. */
    yylex();
    return 0;
}

【问题讨论】:

  • 您会发现特殊字符规则只需返回 yytext[0] 并在语法中将它们作为文字引用,例如: “

标签: linux lex


【解决方案1】:

您应该在第二部分(规则)和第三部分(C 代码)之间添加%%

.....
[>]     {
        c = yytext[0];
        yylval = c - '';
        return('&gt');
      }

%% // HERE

int main(void)                            //C Code Section
.....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多