How does flex support bison-location exactly?

前端 未结 8 1109
轮回少年
轮回少年 2020-12-24 07:38

I\'m trying to use flex and bison to create a filter, because I want get certain grammar elements from a complex language. My plan is to use flex + bison to recognise the gr

8条回答
  •  温柔的废话
    2020-12-24 08:06

    So, I got this to "work", but with a couple of extra steps (I may have overlooked them here ... apologies in that case):

    1. In parser.y, I had to say:

      #define YYLEX_PARAM &yylval, &yylloc
      

      even with %locations and bison --locations, to get it to pass the data.

    2. In lexer.l I had to use -> instead of . for yylloc

    3. Also in lexer.l, I reset the column in the action:

      [\n] { yycolumn = 1; }
      

    Obviously a bit more complex, for \r etc, but at least I got it to work.

提交回复
热议问题