bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: generated code


From: Hans Aberg
Subject: Re: generated code
Date: Mon, 17 Jan 2005 19:33:53 +0100
User-agent: Microsoft-Outlook-Express-Macintosh-Edition/5.0.6

At 01:36 -0800 2005/01/17, Paul Eggert wrote:
>address@hidden writes:
>
>> there is no `default:' in the `switch(yyn)' at `yyreduce:'
>> in the generated code, and using cvs development version.
>> It gives warning message with `gcc -Wswitch-default'.
>> solutions? should there be a `default:' statement?
>
>I don't see why not.  I installed this patch:

You need really to check why it has dropped out and be careful with what you
put in there: The default switch statement is only needed when there is a
rule without an explicit action, so that the default action $$ = $1 can be
implemented. In the past, in the C output, this default action was actually
executed without the switch statement. So therefore, a "default: break;"
would be acceptable.

However, under C++ two things happens: First the old C model would execute
$$ = $1 more than once, I think, which may be illegal under C++ with some
classes. So  therefore the default action was moved into the switch
statement. Therefore, I have in my C++ code (written in pseudocode):
  switch (n_) {
    default:
      // Action default value:
      // When rule length > 0: $$ = $1.
      // When rule length = 0, $$ = semantic_type() (initialization value).
      if (rule_length_ > 0) {
        yyval = *$1;
#if YYLSP_NEEDED
        yyloc = address@hidden;
#endif
      }
      else {
        yyval = semantic_type();
#if YYLSP_NEEDED
        yyloc = location_type();
#endif
      }
      break;
  ...
}
Here, as you can see, I need also to treat the case when there is a zero
length rule. Under C, there is no immediate analogue to the default
constructor, so it drops out.

The second thing that happens is when a Bison typed parser is used; then the
default action is actually
    $<type_name>$ = $<type_name>1
Under C, these all are the same. But under C++, these may change from rule
to rule having an default action. (It actually depends on which
implementation model is used under C++.) If this happens under C++, then one
probably cannot have a default action in the switch statement, but each rule
must have its own default action (or actually, one for each <type_name>).

Now, I do not whether these things have bearing on the C parser. But just to
be user, I think one needs to check those things out, so that one guys makes
some changes and the other zeroes them out.

  Hans Aberg






reply via email to

[Prev in Thread] Current Thread [Next in Thread]