Simple Flex/Bison C++

前端 未结 1 1929
野的像风
野的像风 2020-12-29 08:14

I already looked for my answer but I didn\'t get any quick response for a simple example.

I want to compile a flex/bison scanner+parser using g++ just because I want

相关标签:
1条回答
  • 2020-12-29 08:59

    You need the extern "C" {} for yylex to be in shady.l:

    %{
        extern "C"
        {
            int yylex(void);
        }
    
        #include "shady.tab.h"
    %}
    
    %%
    
    "MOV"|"mov" { return T_MOV; }
    "NOP"|"nop" { return T_NOP; }
    
    ...etc...
    

    Also, after adding a dummy grammar rule, I was able to build and run this with just:

      559  flex shady.l
      560  bison -d shady.y
      561  g++ shady.tab.c lex.yy.c 
    
    0 讨论(0)
提交回复
热议问题