【发布时间】:2017-10-08 20:31:08
【问题描述】:
在我更具体的案例之前,我的 flex 描述似乎有一个全部内容。我确定这是我的错字,但我不知道是哪个规则导致我的其余规则无法匹配。我相信可能的嫌疑人是我创建的字符串描述。但是我仍然不确定,正在寻找答案。
branch.l 文件:
%option noyywrap
%{
#include "global.h"
%}
delim [\t ]
ws {delim}+
digit [0-9]
num {digit}+
alpha [_a-zA-Z]
identifier {alpha}({alpha}|{digit})*
relation [<]|[>]|[>][=]|[<][=]|[=][=]|[!][=]
string ["][a-zA-Z0-9]*["]
%%
{ws} {/* skip blanks and tabs */}
{num} {
tokenval = atoi(yytext);
return NUM;
}
{identifier} {
if (strlen(yytext) >= BSIZE) {
error("compiler error");
}
tokensym = lookup(yytext, ID);
tokensym->count += 1;
return (int)tokensym->token;
}
"BEGIN" {return BEGN;}
"IF" {return IF;}
"THEN" {return THEN;}
"ELSE" {return ELSE;}
"GOTO" {return GOTO;}
"NULL" {return NUL;}
"READ" {return READ;}
"PRINT" {return PRINT;}
"*" {return '*';}
"+" {return '+';}
"-" {return '-';}
"/" {return '/';}
"(" {return '(';}
")" {return ')';}
"=" {return '=';}
"." {return '.';}
"\n" {lineno++;}
";" {return ';';}
"END" {return DONE;}
<<EOF>> {return DONE;}
{relation} {return RELATION;}
{string} {return STRING;}`
这些都是无与伦比的规则......
branch.l:33: warning, rule cannot be matched
branch.l:34: warning, rule cannot be matched
branch.l:35: warning, rule cannot be matched
branch.l:36: warning, rule cannot be matched
branch.l:37: warning, rule cannot be matched
branch.l:38: warning, rule cannot be matched
branch.l:39: warning, rule cannot be matched
branch.l:40: warning, rule cannot be matched
branch.l:51: warning, rule cannot be matched
我不知道如何添加行号。但警告指的是 BEGIN - PRINT 和 ELSE 行。
【问题讨论】:
标签: parsing flex-lexer