Flex扫描仪是否会自动将选项卡转换为空格?

发布于 2025-02-08 09:35:42 字数 461 浏览 1 评论 0原文

我的输入包括:a选项卡b选项卡c

我写了一个带有两个规则的扫描仪:一条规则匹配的字符串中不包含一个选项卡。另一个规则在选项卡上匹配。对于第一个规则,我输出匹配的字符串。我希望第一个规则将三次激活,将“ A”第一次输出“ A”,第三次和“ C”第三次。相反,该规则被激活一次并输出:ab c。为什么?看来Flex(或扫描仪)已将输入中的选项卡转换为空格。我的诊断正确吗?如何关闭这种行为?我不想将选项卡转换为空间。

这是我的扫描仪:

%option noyywrap
%%
[^\t]+      { fprintf(stdout,"Got %s with length %d, \n",yytext,yyleng); }
\t          { fprintf(stdout, "Found a tab\n"); }
%%
int main()
{yylex();}

My input consists of: A tab B tab C

I wrote a scanner with two rules: one rule matches on strings that don't contain a tab. The other rule matches on tabs. For the first rule, I output the string that was matched. I expected the first rule to be activated three times, outputting "A" the first time, "B" the second time, and "C" the third time. Instead, the rule is activated once and outputs: A B C. Why? It appears that Flex (or the scanner) has converted the tabs in the input to spaces. Is my diagnosis correct? How to turn off that behavior? I don't want the tabs converted to spaces.

Here's my scanner:

%option noyywrap
%%
[^\t]+      { fprintf(stdout,"Got %s with length %d, \n",yytext,yyleng); }
\t          { fprintf(stdout, "Found a tab\n"); }
%%
int main()
{yylex();}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燃情 2025-02-15 09:35:42

不,Flex永远不会将选项卡转换为空格 - 它不会对输入字符进行任何转换。因此,您可能还有其他一些将您的选项卡转换为空格的东西。也许您的编辑已经在您要馈送到程序的文件上这样做。

No, flex does not ever convert tabs to spaces -- it does not do any conversion of input characters. So you probably have something else that has converted your tabs into spaces. Perhaps your editor has done so on the file you're feeding to your program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文