How to make YY_INPUT point to a string rather than stdin in Lex & Yacc (Solaris)

后端 未结 5 829
礼貌的吻别
礼貌的吻别 2020-12-01 16:55

I want my yylex() to parse a string rather than a file or standard input. How can I do it with the Lex and Yacc provided with Solaris?

5条回答
  •  日久生厌
    2020-12-01 17:32

    If you are using the real lex and not flex I believe you can simply define your own

    int input(void);
    

    This can return characters from a string or whatever you want.

    Alternatively, I believe you could write the string to a file, and open the file on stream yyin. I suspect this would work with either implementation.

    If using flex then I think you redefine the YY_INPUT() macro,

提交回复
热议问题