How can I send yyleng strings matching from Lex to Yacc?

Please, I'm trying to transfer the yyleng of the matched line from my (.l) file to the (.y) file. Here is an example of a problem:

In the Lex file:

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

In the Yacc file:

/ * I need to know the methodology used to get the specific yyleng yacc file. Should I use global variables? Or is there a specific way to solve this problem? * /

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

+1
lex bison yacc
source share
2 answers

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; 
+3
source share

Define your own yytype and pass all values ​​to it

+1
source share

All Articles