How can I send the yyleng of a matched string from Lex to Yacc?

纵饮孤独 提交于 2019-12-23 03:09:10

问题


Please i am trying to pass the yyleng of a matched string from my (.l) file to the (.y) file. Here is a sample of the issue:

In the Lex File:

<state1>.+    {   fprintf(yyout, "%d", yyleng);    } 

In the Yacc File:

/* I need to know the methodology used to receive a specific yyleng to the yacc file. Shall I use global variables? or there is a specific way for dealing with this issue? */

Thanks in advance for your help! ~ Any suggestions are highly appreciated.


回答1:


yyleng is a global variable; declare it in your grammar file and use it.

Flex uses:

typedef size_t yy_size_t;
extern yy_size_t yyleng;

Lex uses:

extern int yyleng;



回答2:


Define you own yytype and pass any values over it



来源:https://stackoverflow.com/questions/4519082/how-can-i-send-the-yyleng-of-a-matched-string-from-lex-to-yacc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!