简体   繁体   English

在词法分析期间访问 Flex 状态

[英]Accessing States of Flex during lexical analysis

So, I have created al file for my lexical analysis.所以,我为我的词法分析创建了 al 文件。 I have defined one pattern as follows我定义了一种模式如下

<str,chars,comment,text_block,text_block_chars><<EOF>>  {printf("%d", yy_top_state()); showError("", EOF_ERROR); return(0);}

Here I want to give the error depending on what state it was.在这里,我想根据 state 给出错误。 I know that there is yy_top_state() and yy_current_buffer() functions in my lex.yy.c file which stores the current state. However I cant access those function.我知道我的 lex.yy.c 文件中有 yy_top_state() 和 yy_current_buffer() 函数,它存储当前的 state。但是我无法访问那些 function。

Can someone tell me if there are any other way I can access my current state through.l file only.有人可以告诉我是否有任何其他方法可以仅通过 .l 文件访问我当前的 state。

(Here str, chars, etc. are the states and showError() is some other function that I have defined) (这里的 str、chars 等是状态,showError() 是我定义的其他一些 function)

Thank you.谢谢你。

The current state is available through the macro YY_START (and also YYSTATE ).当前的 state 可通过宏YY_START (以及YYSTATE )获得。 The value is a small integer, with INITIAL having the value 0.该值是一个小的 integer,其中INITIAL的值为 0。

As far as I know, there is no way of getting the symbolic name of the start condition at runtime.据我所知,无法在运行时获取开始条件的符号名称。 State names are preprocessor macros, so they're long gone before the lexer is compiled, and they are not available outside of the generated lexer. State 名称是预处理器宏,因此在编译词法分析器之前它们早已消失,并且在生成的词法分析器之外不可用。 But it would be easy enough to build a lookup table (in the lexer).但是构建一个查找表(在词法分析器中)会很容易。

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

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