Ian Lance Taylor wrote:

I'm sure Joseph could explain the reasons better, but some of the
problems with the bison parser were 1) it's hard to generate good
error messages at the right places; 2) C is not LALR(1) (at least, not
in a natural sense) because of the declaration syntax; 3) it made it a
lot easier to add OpenMP support.

For me, 1) is decisive, GNAT uses a hand written parser for that
reason, and there we did a reasonably fair test, since Gerry Fisher
did a really VERY good table driven parser (using much more sophisticated approaches than BISON and similar tools, that generated
really quite good messages, but still not as good as what can be
done by hand, where for example we take note of indentation in
generating messages, e.g. consider the following very common
cut-and-paste error.

     1. package body p is
     2.    procedure p1 is
     3.    begin
     4.       null;
     5.    end;
     6.
     7.    procedure p2;
     8.    procedure p3;
     9.    procedure p4 is
                        |
        >>> "is" should be ";"

    10.    procedure p5;
    11.    procedure p6;
    12.
    13.    procedure p2 is begin null; end;
    14.    procedure p3 is begin null; end;
    15.    procedure p4 is begin null; end;
    16.    procedure p5 is begin null; end;
    17.    procedure p6 is begin null; end;
    18. end;

All other Ada compilers I know would complain at the end. You can
see this more clearly by indenting the above program in accordance
with the way it is written:

package body p is
   procedure p1 is
   begin
      null;
   end;

   procedure p2;
   procedure p3;
   procedure p4 is
      procedure p5;
      procedure p6;

      procedure p2 is begin null; end;
      procedure p3 is begin null; end;
      procedure p4 is begin null; end;
      procedure p5 is begin null; end;
      procedure p6 is begin null; end;
   end;

What looks wrong here is the unexpected end, there is nothing
"wrong" syntactically in a left to right scan till that point.

If you give this indented version (which makes it clear that the
dclarations after the "is" really *are* intended for procedure
p4, you get


     1. package body p is
     2.    procedure p1 is
     3.    begin
     4.       null;
     5.    end;
     6.
     7.    procedure p2;
     8.    procedure p3;
     9.    procedure p4 is
    10.       procedure p5;
    11.       procedure p6;
    12.
    13.       procedure p2 is begin null; end;
    14.       procedure p3 is begin null; end;
    15.       procedure p4 is begin null; end;
    16.       procedure p5 is begin null; end;
    17.       procedure p6 is begin null; end;
    18.    end;
          12
        >>> missing "begin" for procedure "p4" at line 9
        >>> "end p4;" expected

Here is another example:

     1. procedure q is
     2. begin
     3.    x := a b;
                 |
        >>> binary operator expected

     4.    x := a
                 |
        >>> missing ";"

     5.    b;
     6. end;

Reply via email to