在执行任何规则之前,如何在FLEX中初始化?

发布于 2025-02-09 07:18:30 字数 178 浏览 1 评论 0原文

我的Lexer规则依赖于被人群的数组。因此,在执行任何规则之前,我需要初始化数组。我可以使用yy_user_action进行初始化(检查全局标志以查看是否未设置,如果是这样,请调用INIT函数),但这会非常效率,因为它检查了该数组是否被初始化对于每个规则。有没有办法表达出来:“在执行任何规则之前运行此代码。”?

My lexer rules rely on an array being populated. So, before any rules are executed, I need to initialize the array. I could use YY_USER_ACTION to do the initializing (check a global flag to see if it's not set, if so call the init function) but that would be very inefficient as it checks to see if the array is initialized for every rule. Is there a way in Flex to express: "Run this code before executing any rules."?

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

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

发布评论

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

评论(1

離人涙 2025-02-16 07:18:30

就是这样做的。
(您说您使用的是专门使用的。其他LEX实现可能不支持它。)

您与提到的yy_user_action相似。

%code {
    void populateArray();
    #define YY_USER_INIT populateArray();
%}

%%

// Rules

%%

void populateArray()
{
    //...
}

The macro YY_USER_INIT does exactly that.
(You said you're using specifically Flex. Other Lex implementations may not support it.)

You use it similarly to the mentioned YY_USER_ACTION.

%code {
    void populateArray();
    #define YY_USER_INIT populateArray();
%}

%%

// Rules

%%

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