Hi folks. My friend Nicholas and I are trying to make a compiler for a
simpler language(just expressions by now) with flex and bison using C++.

Using
https://www.gnu.org/software/bison/manual/html_node/A-Complete-C_002b_002b-Example.html
as a guide, we code the repository below, but when We try

bison -d parser.yy -o parser.cc
lex scanner.l
g++ lex.yy.cc parser.cc main.cc -o cppimp


Give us the error in the file

repository : https://github.com/nicholas-barcelos/Cppimp

We try to change headers of place, move definitions of class, but nothing
work. What are we making wrong? Thanks in advance
Commands

bison -d parser.yy -o parser.cc
lex scanner.l 
g++ *.cc -o cppimp

Log

driver.cc: In member function ‘int driver::parse(const string&)’:
driver.cc:18:19: error: no match for call to ‘(yy::parser) ()’
   int res = parse();
                   ^
lex.yy.cc: In function ‘yy::parser::symbol_type yylex(driver&)’:
lex.yy.cc:667:9: error: ‘yy_init’ was not declared in this scope
  if ( !(yy_init) )
         ^~~~~~~
lex.yy.cc:667:9: note: suggested alternative: ‘yy_nxt’
  if ( !(yy_init) )
         ^~~~~~~
         yy_nxt
lex.yy.cc:675:11: error: ‘yy_start’ was not declared in this scope
   if ( ! (yy_start) )
           ^~~~~~~~
lex.yy.cc:675:11: note: suggested alternative: ‘yy_act’
   if ( ! (yy_start) )
           ^~~~~~~~
           yy_act
lex.yy.cc:678:10: error: ‘yyin’ was not declared in this scope
   if ( ! yyin )
          ^~~~
lex.yy.cc:685:10: error: ‘yyout’ was not declared in this scope
   if ( ! yyout )
          ^~~~~
lex.yy.cc:685:10: note: suggested alternative: ‘yy_act’
   if ( ! yyout )
          ^~~~~
          yy_act
lex.yy.cc:317:30: error: ‘yy_buffer_stack’ was not declared in this scope
 #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
                              ^
lex.yy.cc:692:10: note: in expansion of macro ‘YY_CURRENT_BUFFER’
   if ( ! YY_CURRENT_BUFFER ) {
          ^~~~~~~~~~~~~~~~~
lex.yy.cc:317:30: note: suggested alternative: ‘yy_buffer_state’
 #define YY_CURRENT_BUFFER ( (yy_buffer_stack) \
                              ^
lex.yy.cc:692:10: note: in expansion of macro ‘YY_CURRENT_BUFFER’
   if ( ! YY_CURRENT_BUFFER ) {
          ^~~~~~~~~~~~~~~~~
lex.yy.cc:318:48: error: ‘yy_buffer_stack_top’ was not declared in this scope
                           ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
                                                ^
lex.yy.cc:692:10: note: in expansion of macro ‘YY_CURRENT_BUFFER’
   if ( ! YY_CURRENT_BUFFER ) {
          ^~~~~~~~~~~~~~~~~
lex.yy.cc:318:48: note: suggested alternative: ‘yy_buffer_state’
                           ? (yy_buffer_stack)[(yy_buffer_stack_top)] \
                                                ^
lex.yy.cc:692:10: note: in expansion of macro ‘YY_CURRENT_BUFFER’
   if ( ! YY_CURRENT_BUFFER ) {
          ^~~~~~~~~~~~~~~~~
lex.yy.cc:693:4: error: ‘yyensure_buffer_stack’ was not declared in this scope
    yyensure_buffer_stack ();
    ^~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:693:4: note: suggested alternative: ‘yy_buffer_state’
    yyensure_buffer_stack ();
    ^~~~~~~~~~~~~~~~~~~~~
    yy_buffer_state
lex.yy.cc:695:23: error: ‘yyin’ was not declared in this scope
     yy_create_buffer( yyin, YY_BUF_SIZE );
                       ^~~~
lex.yy.cc:695:5: error: ‘yy_create_buffer’ was not declared in this scope
     yy_create_buffer( yyin, YY_BUF_SIZE );
     ^~~~~~~~~~~~~~~~
lex.yy.cc:695:5: note: suggested alternative: ‘yy_new_buffer’
     yy_create_buffer( yyin, YY_BUF_SIZE );
     ^~~~~~~~~~~~~~~~
     yy_new_buffer
lex.yy.cc:698:3: error: ‘yy_load_buffer_state’ was not declared in this scope
   yy_load_buffer_state(  );
   ^~~~~~~~~~~~~~~~~~~~
lex.yy.cc:698:3: note: suggested alternative: ‘yy_buffer_state’
   yy_load_buffer_state(  );
   ^~~~~~~~~~~~~~~~~~~~
   yy_buffer_state
lex.yy.cc:719:12: error: ‘yy_c_buf_p’ was not declared in this scope
   yy_cp = (yy_c_buf_p);
            ^~~~~~~~~~
lex.yy.cc:719:12: note: suggested alternative: ‘yy_bp’
   yy_cp = (yy_c_buf_p);
            ^~~~~~~~~~
            yy_bp
lex.yy.cc:722:13: error: ‘yy_hold_char’ was not declared in this scope
   *yy_cp = (yy_hold_char);
             ^~~~~~~~~~~~
lex.yy.cc:722:13: note: suggested alternative: ‘__u_char’
   *yy_cp = (yy_hold_char);
             ^~~~~~~~~~~~
             __u_char
lex.yy.cc:730:23: error: ‘yy_start’ was not declared in this scope
   yy_current_state = (yy_start);
                       ^~~~~~~~
lex.yy.cc:730:23: note: suggested alternative: ‘yy_act’
   yy_current_state = (yy_start);
                       ^~~~~~~~
                       yy_act
lex.yy.cc:737:6: error: ‘yy_last_accepting_state’ was not declared in this scope
     (yy_last_accepting_state) = yy_current_state;
      ^~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:738:6: error: ‘yy_last_accepting_cpos’ was not declared in this scope
     (yy_last_accepting_cpos) = yy_cp;
      ^~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:750:12: error: ‘yy_last_accepting_cpos’ was not declared in this scope
   yy_cp = (yy_last_accepting_cpos);
            ^~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:751:23: error: ‘yy_last_accepting_state’ was not declared in this 
scope
   yy_current_state = (yy_last_accepting_state);
                       ^~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:365:20: error: ‘yytext’ was not declared in this scope
 #define yytext_ptr yytext
                    ^
lex.yy.cc:380:3: note: in expansion of macro ‘yytext_ptr’
  (yytext_ptr) = yy_bp; \
   ^~~~~~~~~~
lex.yy.cc:757:3: note: in expansion of macro ‘YY_DO_BEFORE_ACTION’
   YY_DO_BEFORE_ACTION;
   ^~~~~~~~~~~~~~~~~~~
lex.yy.cc:365:20: note: suggested alternative: ‘yylex’
 #define yytext_ptr yytext
                    ^
lex.yy.cc:380:3: note: in expansion of macro ‘yytext_ptr’
  (yytext_ptr) = yy_bp; \
   ^~~~~~~~~~
lex.yy.cc:757:3: note: in expansion of macro ‘YY_DO_BEFORE_ACTION’
   YY_DO_BEFORE_ACTION;
   ^~~~~~~~~~~~~~~~~~~
lex.yy.cc:764:8: error: ‘yy_flex_debug’ was not declared in this scope
   if ( yy_flex_debug )
        ^~~~~~~~~~~~~
lex.yy.cc:579:14: error: ‘LexerOutput’ was not declared in this scope
 #define ECHO LexerOutput( yytext, yyleng )
              ^
scanner.l:55:1: note: in expansion of macro ‘ECHO’
 
 ^   
lex.yy.cc:323:35: error: ‘yy_buffer_stack’ was not declared in this scope
 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
                                   ^
lex.yy.cc:902:8: note: in expansion of macro ‘YY_CURRENT_BUFFER_LVALUE’
   if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
        ^~~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:323:35: note: suggested alternative: ‘yy_buffer_state’
 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
                                   ^
lex.yy.cc:902:8: note: in expansion of macro ‘YY_CURRENT_BUFFER_LVALUE’
   if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
        ^~~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:323:53: error: ‘yy_buffer_stack_top’ was not declared in this scope
 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
                                                     ^
lex.yy.cc:902:8: note: in expansion of macro ‘YY_CURRENT_BUFFER_LVALUE’
   if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
        ^~~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:323:53: note: suggested alternative: ‘yy_buffer_state’
 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
                                                     ^
lex.yy.cc:902:8: note: in expansion of macro ‘YY_CURRENT_BUFFER_LVALUE’
   if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
        ^~~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:913:5: error: ‘yy_n_chars’ was not declared in this scope
    (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
     ^~~~~~~~~~
lex.yy.cc:913:5: note: suggested alternative: ‘__u_char’
    (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
     ^~~~~~~~~~
     __u_char
lex.yy.cc:917:46: error: ‘yyin’ was not declared in this scope
    YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin.rdbuf();
                                              ^~~~
lex.yy.cc:323:35: error: ‘yy_buffer_stack’ was not declared in this scope
 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
                                   ^
lex.yy.cc:929:25: note: in expansion of macro ‘YY_CURRENT_BUFFER_LVALUE’
   if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
                         ^~~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:323:35: note: suggested alternative: ‘yy_buffer_state’
 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
                                   ^
lex.yy.cc:929:25: note: in expansion of macro ‘YY_CURRENT_BUFFER_LVALUE’
   if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
                         ^~~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:323:53: error: ‘yy_buffer_stack_top’ was not declared in this scope
 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
                                                     ^
lex.yy.cc:929:25: note: in expansion of macro ‘YY_CURRENT_BUFFER_LVALUE’
   if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
                         ^~~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:323:53: note: suggested alternative: ‘yy_buffer_state’
 #define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)]
                                                     ^
lex.yy.cc:929:25: note: in expansion of macro ‘YY_CURRENT_BUFFER_LVALUE’
   if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
                         ^~~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:929:62: error: ‘yy_n_chars’ was not declared in this scope
   if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
                                                              ^~~~~~~~~~
lex.yy.cc:929:62: note: suggested alternative: ‘__u_char’
   if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] )
                                                              ^~~~~~~~~~
                                                              __u_char
lex.yy.cc:935:23: error: ‘yy_get_previous_state’ was not declared in this scope
    yy_current_state = yy_get_previous_state(  );
                       ^~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:935:23: note: suggested alternative: ‘yy_current_state’
    yy_current_state = yy_get_previous_state(  );
                       ^~~~~~~~~~~~~~~~~~~~~
                       yy_current_state
lex.yy.cc:946:20: error: ‘yy_try_NUL_trans’ was not declared in this scope
    yy_next_state = yy_try_NUL_trans( yy_current_state );
                    ^~~~~~~~~~~~~~~~
lex.yy.cc:967:17: error: ‘yy_get_next_buffer’ was not declared in this scope
   else switch ( yy_get_next_buffer(  ) )
                 ^~~~~~~~~~~~~~~~~~
lex.yy.cc:967:17: note: suggested alternative: ‘yy_new_buffer’
   else switch ( yy_get_next_buffer(  ) )
                 ^~~~~~~~~~~~~~~~~~
                 yy_new_buffer
lex.yy.cc:971:6: error: ‘yy_did_buffer_switch_on_eof’ was not declared in this 
scope
     (yy_did_buffer_switch_on_eof) = 0;
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:973:10: error: ‘yywrap’ was not declared in this scope
     if ( yywrap(  ) )
          ^~~~~~
lex.yy.cc:973:10: note: suggested alternative: ‘yy_bp’
     if ( yywrap(  ) )
          ^~~~~~
          yy_bp
lex.yy.cc:172:32: error: ‘yyin’ was not declared in this scope
 #define YY_NEW_FILE yyrestart( yyin  )
                                ^
lex.yy.cc:993:7: note: in expansion of macro ‘YY_NEW_FILE’
       YY_NEW_FILE;
       ^~~~~~~~~~~
lex.yy.cc:172:21: error: ‘yyrestart’ was not declared in this scope
 #define YY_NEW_FILE yyrestart( yyin  )
                     ^
lex.yy.cc:993:7: note: in expansion of macro ‘YY_NEW_FILE’
       YY_NEW_FILE;
       ^~~~~~~~~~~
lex.yy.cc:1002:24: error: ‘yy_get_previous_state’ was not declared in this scope
     yy_current_state = yy_get_previous_state(  );
                        ^~~~~~~~~~~~~~~~~~~~~
lex.yy.cc:1002:24: note: suggested alternative: ‘yy_current_state’
     yy_current_state = yy_get_previous_state(  );
                        ^~~~~~~~~~~~~~~~~~~~~
                        yy_current_state
lex.yy.cc:615:29: error: ‘LexerError’ was not declared in this scope
 #define YY_FATAL_ERROR(msg) LexerError( msg )
                             ^
lex.yy.cc:1022:3: note: in expansion of macro ‘YY_FATAL_ERROR’
   YY_FATAL_ERROR(
   ^~~~~~~~~~~~~~
lex.yy.cc:615:29: note: suggested alternative: ‘strerror’
 #define YY_FATAL_ERROR(msg) LexerError( msg )
                             ^
lex.yy.cc:1022:3: note: in expansion of macro ‘YY_FATAL_ERROR’
   YY_FATAL_ERROR(
   ^~~~~~~~~~~~~~
scanner.l: In member function ‘void driver::scan_begin()’:
scanner.l:70:5: error: ‘yy_flex_debug’ was not declared in this scope
     if (file.empty () || file == "-")
     ^~~~~~~~~~~~~
scanner.l:72:9: error: ‘yyin’ was not declared in this scope
     else if (!(yyin = fopen (file.c_str (), "r")))
         ^~~~
scanner.l:73:16: error: ‘yyin’ was not declared in this scope
     {
                ^   
scanner.l: In member function ‘void driver::scan_end()’:
scanner.l:83:11: error: ‘yyin’ was not declared in this scope
 }
           ^   
parser.cc: In member function ‘virtual int yy::parser::parse()’:
parser.cc:446:38: error: ‘yylex’ was not declared in this scope
             symbol_type yylookahead (yylex (drv));
                                      ^~~~~
parser.cc:446:38: note: suggested alternative: ‘yylen’
             symbol_type yylookahead (yylex (drv));
                                      ^~~~~
                                      yylen
parser.yy:53:7: error: invalid use of incomplete type ‘class driver’
     | exp                       { drv.result = $1; };
       ^~~
In file included from parser.cc:46:0:
parser.yy:12:11: note: forward declaration of ‘class driver’
     class driver;
           ^~~~~~
parser.tab.cc: In member function ‘virtual int yy::parser::parse()’:
parser.tab.cc:446:38: error: ‘yylex’ was not declared in this scope
             symbol_type yylookahead (yylex (drv));
                                      ^~~~~
parser.tab.cc:446:38: note: suggested alternative: ‘yylen’
             symbol_type yylookahead (yylex (drv));
                                      ^~~~~
                                      yylen
parser.yy:53:7: error: invalid use of incomplete type ‘class driver’
     | exp                       { drv.result = $1; };
       ^~~
In file included from parser.tab.cc:46:0:
parser.yy:12:11: note: forward declaration of ‘class driver’
     class driver;
           ^~~~~~
_______________________________________________
help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison

Reply via email to