1
votes

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.

2
See near duplicate question (asking about yytext instead of yyleng):Jonathan Leffler

2 Answers

3
votes

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;
1
votes

Define you own yytype and pass any values over it