How do I use C++ in flex and bison?

后端 未结 5 1556
清歌不尽
清歌不尽 2020-12-16 06:03

I have a project for school where we need to use flex and bison. I want to use C++ so that I have access to STL and my own classes that I wrote. We were provided with the fo

5条回答
  •  粉色の甜心
    2020-12-16 07:08

    For using flex with C++:
     1: read the flex docs:
     2: use flex -+ -o file.cc parser.ll
     3: In the .ll file:
    
    %option c++
    %option yyclass="Your_class_name"
    %option batch
    
     4: In your .hh file, derive Your_class_name from  public yyFlexLexer
     5: you can then use your_class_instance.yylex()
    

提交回复
热议问题