开发者

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

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>.+    {   fprint开发者_JAVA技巧f(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.


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;


Define you own yytype and pass any values over it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜