简体   繁体   English

如何在Flex中定义布尔值(2)

[英]How to define a boolean in Flex (2)

I am writing a scanner for my compiler project using flex and writing it in decaf (a language similar to C/C++ & Java), my scanner is up and running, except it fails in identifying boolean constants (true, false) I wrote below pattern and C code: 我正在使用flex为我的编译器项目编写一个扫描仪,并以decaf (类似于C / C ++和Java的语言)编写它,我的扫描仪已启动并正在运行,除了它无法识别我在下面编写的布尔常量(真,假)模式和C代码:

"true" { yylval.boolConstant = 1;
       return T_BoolConstant; }

"false" { yylval.boolConstant = 0;
        return T_BoolConstant; }

but instead of returning T_BoolConstant it keeps returning as T_Identifier . 但是它不返回T_BoolConstant而是返回为T_Identifier Basically scanner is recognizing both "true" & "false" as text valid to be considered as identifier not as boolean binary variable. 基本上,扫描程序会同时将“ true”和“ false”识别为有效文本,以将其视为标识符而不是布尔二进制变量。

There is this answer for similar type of question but still it doesn't work for me! 对于类似问题,也有答案,但对我而言仍然无效!

Any guess why it isn't returning true/false ? 任何猜测为什么它不返回true / false?

This will be because you have your rule for identifiers above these rules. 这是因为您的标识符规则高于这些规则。 Flex matches rules top to bottom. Flex从上到下匹配规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM