String input to flex lexer

前端 未结 8 571
梦如初夏
梦如初夏 2020-11-29 04:42

I want to create a read-eval-print loop using flex/bison parser. Trouble is, the flex generated lexer wants input of type FILE* and i would like it to be char*. Is there an

8条回答
  •  执念已碎
    2020-11-29 04:49

    Here is what I needed to do :

    extern yy_buffer_state;
    typedef yy_buffer_state *YY_BUFFER_STATE;
    extern int yyparse();
    extern YY_BUFFER_STATE yy_scan_buffer(char *, size_t);
    
    int main(int argc, char** argv) {
    
      char tstr[] = "line i want to parse\n\0\0";
      // note yy_scan_buffer is is looking for a double null string
      yy_scan_buffer(tstr, sizeof(tstr));
      yy_parse();
      return 0;
    }
    

    you cannot extern the typedef, which make sense when you think about it.

提交回复
热议问题