1

I am writing a parser with Bison and I am getting the following warnings.

fol.y:42 parser name defined to default :"parse"
fol.y:61:  warning:  type clash ('' 'pred') on default action

I have been using Google to search for a way to get rid of them, but have pretty much come up empty handed on what they mean (much less how to fix them) since every post I found with them has a compilation error and the warnings them selves aren't addressed. Could someone tell me what they mean and how to fix them? The relevant code is below. Line 61 is the last semicolon. I cut out the rest of the grammar since it is incredibly verbose.

%union {
    char* var;
    char* name;
    char* pred;
}


%token <var> VARIABLE
%token <name> NAME
%token <pred> PRED

%%


fol:
        declines clauses {cout << "Done parsing with file" << endl;}
        ;
declines:
        declines decline
        |decline
        ;
decline:
        PRED decs
        ;
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
njvb
  • 1,377
  • 3
  • 18
  • 36

2 Answers2

1

The first message is likely just a warning that you didn't include %start parse in the grammar specification.

The second means that somewhere you have rule that is supposed to return a value but you haven't properly specified which type of value it is to return. The PRED returns the pred element of your union; the problem might be that you've not created %type entries for decline and declines. If you have a union, you have to specify the type for most, if not all, rules — or maybe just rules that don't have an explicit action (so as to override the default $$ = $1; action).

I'm not convinced that the problem is in the line you specify, and because we don't have a complete, minimal reproduction of your problem, we can't investigate for you to validate it. The specification for decs may be relevant (I'm not convinced it is, but it might be).

You may get more information from the output of bison -v, which is the y.output file (or something similar).

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • I can find no examples that use %start parse (I am not sure where to include it and just putting it at the top causes a glibc error), and as for the other warning I have other rules that look the same as decline and declines but didn't generate the error. – njvb Apr 20 '12 at 00:48
  • You'd put `%start` after the `%token` lines, probably, though it isn't necessary if the start rule is also the first rule in the grammar. But since we can't see what generated that warning, we can't easily help you resolve it. Likewise, with the other problems; you've been a little too enthusiastic with trimming the grammar while preserving the problem. Given the code above, both `clauses` and `decs` are used but 'not defined as a token and has no rules'. Adding rules `decs: NAME;` and `clauses: VARIABLE;` doesn't help diagnose the problem; `bison` compiles the grammar without warnings. – Jonathan Leffler Apr 20 '12 at 03:07
0

Finally found it.

To fix this:

fol.y:42 parser name defined to default :"parse"

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