问题
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