Re: advice needed re: parsing C decl syntax

Pedz Thing <ihnp4!bobkat!pedz>
Wed, 10 Dec 86 16:23:48 cst

          From comp.compilers

Related articles
advice needed re: parsing C decl syntax!tarvydas@csri (Paul Tarvydas) (1986-12-06)
Re: advice needed re: parsing C decl syntax harvard!rutgers!seismo!rochester!ken (SKY) (1986-12-08)
Re: advice needed re: parsing C decl syntax ihnp4!tektronix!tekchips.TEK.COM!stevev (Steve Vegdahl) (1986-12-09)
Re: advice needed re: parsing C decl syntax ihnp4!bobkat!pedz (Pedz Thing) (1986-12-10)
Re: advice needed re: parsing C decl syntax steve@basser.oz (1986-12-10)
Re: advice needed re: parsing C decl syntax ihnp4!utzoo!henry (1986-12-16)
| List of all articles for this month |

Newsgroups: mod.compilers
Date: Wed, 10 Dec 86 16:23:48 cst
From: Pedz Thing <ihnp4!bobkat!pedz>
References: <284@ima.UUCP>
Organization: Digital Lynx; Dallas TX

I recently wrote a C interpreter (which of course must parse also). I
found the particular problem mentioned to not be that bad. The
declaration of a function (or a variable) and the actual definition of
a function was handled by the same code. Roughly I had a routine
which I called declaration. This called something which picked up the
declarative part (like the int i or the char *p(arg)). I put the list
of arguments in a place to be found later by `declaration'. Then I
would look to see if I found a function and if I was not looking at a
semi-colon. If that was the case, I assumed I had a function
definition and parsed it.

The part I found to be tricky was the code which picked up the `int i'
or the `char *p[4](arg)'. It turns out that this is not very
recursive. I did this in a loop which continued until I did not see
anything I liked. In that look I picked up the *'s, followed by a
name, followed by the []'s or ()'s for functions. The ()'s used for
grouping was the reason for the loop. If you want more details, I
could send you part of the code.

However, I would like to end with a statement about yacc. As was
pointed out, the problem with yacc is not the speed nor the size. It
is rather difficult to write a good grammar for C which yacc will
accept and still provides useful screening of illegal input. I have
written one which correctly knows about lvalue's. It knows the
difference between functions and pointers to functions so that the
items inside a struct (for example) are always pointers to functions
and not functions. It also has 0 shift/reduce conflicts (as reported
out of yacc). All the other grammars I have looked at fail miserably
in these reguards. The code produced (tables and driver) is 8K I
think. (The reason I did not use it was because of legal problems
with ATT which I still have not heard a definate answer on.)
Perry Smith

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.