1

I have a bison-flex project working on linux ubuntu vmPlayer, and for some reason I have a warning I can't get off.. this is the beginning of my file, and my program (extra.y is bison file) does start with "lines":

%{   
   #include <stdio.h> 
   #include <stdlib.h>  
   #include <string>
   #include <string.h>
#include <iostream>
   #include <map>   
   #include <math.h>
   #include <algorithm>
   int yylex();   
   void yyerror(const char*)       
   char dollarOrWave=' ';
%}

%left OR 
%left AND
%union {
int     int_val;
char*   str_val;
}                         //THIS IS LINE 70 !!

%token<int_val> T_INT              
%token<str_val> STREXP
%type<int_val> expr   
%type<str_val> stringExp
%start lines

%%
lines:            
    line         { }//checkDollars(); }//checkDollars(); }
| lines line     { checkDollars(); numStringVarsFlag=0; }
;

Warning:

extra.y:70 parser name defined to default :"parse"

Searching I've seen that: Bison grammar warnings but it still gives me that warning.. ..HELP??

Community
  • 1
  • 1
mooly
  • 113
  • 1
  • 8
  • 1
    How do you call bison? What is line 70? Are you getting the same warning with this six-line bison file that you provided? I presume not, as `line` is not defined. Can you provide a MWE? – nickie Dec 10 '16 at 23:01
  • aviad@ubuntu:~/Desktop/bison$ rm -f *.h *.c *.o *.exe ; flex extra.lex ; bison -d -v extra.y ---> this is how I call bison and this is where the warning appears.. I edited it , I can't put all my code here, its very long and I don't think its relevant since that warning started when I started the project with fewer code – mooly Dec 10 '16 at 23:21
  • 2
    I cannot reproduce the warning with your code. Please, provide a MWE. – nickie Dec 11 '16 at 00:36
  • added some more code – mooly Dec 11 '16 at 10:18
  • 1
    An MWE is not just "some more code". It's the least possible amount of code that when you (or anyone else) add to an empty file `extra.y` and then run `bison -d -v extra.y`, you get the warning that you mention. With what you currently have, I can still not reproduce it and therefore I cannot help you. – nickie Dec 11 '16 at 11:15

3 Answers3

2

Finally found it.

Add %name parse before %token

Eg:

%name parse
%token NUM

(From: https://bdhacker.wordpress.com/2012/05/05/flex-bison-in-ubuntu/#comment-2669)

opticod
  • 795
  • 8
  • 10
1

You are not using bison; you are using bison++. You should make that clear in your question(s) because it does make a difference.

The warning message you receive is normal in bison++; you can avoid it by explicitly declaring a parser class name.

From man bison++ (assuming the documentation is correctly installed):

%name parser_name
Declare the name of this parser. User for C++ class name, and to render many names unique. default is parse. Must be given before %union and %define, or never.

rici
  • 234,347
  • 28
  • 237
  • 341
-1

You are missing a ';' after the %union {}.

%union {
};
hailinzeng
  • 966
  • 9
  • 24
  • 1
    No. This is not the problem here (although adding a semicolon does not hurt). Look at the [documentation](https://www.gnu.org/software/bison/manual/html_node/Union-Decl.html), especially the last sentence. – nickie Dec 11 '16 at 15:39