如何将匹配字符串的yyleng从Lex发送到Yacc? [英] How can I send the yyleng of a matched string from Lex to Yacc?
本文介绍了如何将匹配字符串的yyleng从Lex发送到Yacc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请尝试将匹配字符串的yyleng从我的(.l)文件传递到(.y)文件.这是问题的一个示例:
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:
在Lex文件中:
<state1>.+ { fprintf(yyout, "%d", yyleng); }
在Yacc文件中:
/*我需要知道用于接收yacc文件的特定yyleng的方法.我应该使用全局变量吗?还是有解决此问题的特定方法? */
/* 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.
推荐答案
yyleng
是全局变量;在语法文件中声明它并使用它.
yyleng
is a global variable; declare it in your grammar file and use it.
Flex使用:
typedef size_t yy_size_t;
extern yy_size_t yyleng;
Lex使用:
extern int yyleng;
这篇关于如何将匹配字符串的yyleng从Lex发送到Yacc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文