bloudraak / lemon-parser-generator

Automatically exported from code.google.com/p/lemon-parser-generator
GNU General Public License v2.0
0 stars 0 forks source link

Lemon doesn't produce a header with function prototypes #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
When using lemon, programs complain about not having the function prototypes.
It would be nice if lemon could output function prototypes in the header file.

Original issue reported on code.google.com by archeng...@gmail.com on 22 Dec 2008 at 10:25

GoogleCodeExporter commented 9 years ago
Yes, this would be a great addition.  I found myself wanting this feature as 
well.  I 
ended up adding the prototypes to the header file manually with my Makefile.

I also manually add the %token_type definition to the header file, it would be 
nice if 
there were a place to put the token definition in the header file as well.

Original comment by Eric.L.H...@gmail.com on 25 Mar 2010 at 5:49

GoogleCodeExporter commented 9 years ago
On line 4019, I inserted the attached code. It worked for me.

A few issues that make this harder than you'd think:

1. I had to scan for structs and forward-declare them as well, or else the 
declarations wouldn't compile. I don't forward-declare classes (can lemon be 
compiled 
as C++?), nor do I add typedefs. So there still could be problems.

2. I had to include <stdio.h> and <stddef.h> to get FILE, size_t, ptrdiff_t, 
etc. But 
I would have to add <time.h> to get time_t. I'm not sure what others I would 
need.

3. By adding this stuff, I've created a dependency on lempar.c in lemon.c, 
which 
sorta defeats the purpose of having a template file in the first place.

Despite all that I've attached my "fix" since it's a fairly common problem.

Original comment by andrew.p...@gmail.com on 29 Mar 2010 at 11:01

Attachments:

GoogleCodeExporter commented 9 years ago
I just realized the correct line number was 4016 (I think) because I had added 
a 
warning comment at the top of my source file saying that I had tainted it.

My code goes right after the line:
  out = file_open(lemp,".h","wb");
  if( out ){

I have attached a proper patch file for lemon.c this time. Sorry about that, 
guys.

Original comment by andrew.p...@gmail.com on 29 Mar 2010 at 11:17

Attachments: