4

I want to use YY_BUFFER_STATE yy_scan_string(const char *str) and other functions like yyparse() in my main.cpp, I did things:

extern "C"{
extern YY_BUFFER_STATE yy_scan_string(const char *str);
}

But there is a error error:YY_BUFFER_STATE' does not name a type`, then I did:

extern yy_buffer_state;
typedef yy_buffer_state *YY_BUFFER_STATE;
extern int yyparse();
extern YY_BUFFER_STATE yy_scan_buffer(char *, size_t);

But the same problem also, how to do it, thanks, really appreciate your help!!

Here is the main.cpp file. #include "main.h"

 #include <string.h>
 extern "C"{void scan_string(const char* str);}
 int yyparse();
 void test::getvalue(int& var)
 {
    if (var!=0)
        std::cout<<"True"<<std::endl;
    else
        std::cout<<"False"<<std::endl;
  }

  int main(){
     std::string str="T+F";
     //how to send str as an Input to parse?

     yyparse();
     return 0;
   }
CJAN.LEE
  • 1,108
  • 1
  • 11
  • 20

1 Answers1

5

The simplest solution is probably to add a separate function in your grammar file that in turn call yy_scan_string.

/* Stuff... */

%%

/* Grammar */

%%

void scan_string(const char* str)
{
    yy_switch_to_buffer(yy_scan_string(str));
}

Then call scan_string from your code.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • How to fix it, actually, I just put as your suggestion. – CJAN.LEE Sep 24 '12 at 13:35
  • Maybe you should show us a bit more of your code, and what you're doing when you get that error. Seems to me like you most probably have some other syntax error in your file. – rici Sep 25 '12 at 02:34
  • good, put the function in the **.y file, and call it in the **.cc file, avoid direct call in .cc file. – lemon Jul 12 '13 at 08:10