BISON + FLEX grammar - why tokens are being concatenated together

前端 未结 1 1196
[愿得一人]
[愿得一人] 2021-01-26 05:30

I would like to understand why BISON is concatenating two tokens on the following rule

stmt:
  declaration                 { ... }
  | assignment                         


        
相关标签:
1条回答
  • 2021-01-26 05:53

    This flex action is incorrect:

      yylval.id_v = yytext;
    

    yytext points into an internal work buffer. Its contents will change every time the scanner is called. So if you want to keep the string which makes up the token, you must copy the string into your own storage, for example using strdup. (Don't forget to free​ the allocated storage when you are finished with it.)

    0 讨论(0)
提交回复
热议问题