Re: Looking for LL(k) C grammar

George Neuner <gneuner2@comcast.net>
Mon, 05 Nov 2007 11:28:46 -0500

          From comp.compilers

Related articles
Looking for LL(k) C grammar italo@spwinternet.com.br (Italo Tasso) (2007-11-03)
Re: Looking for LL(k) C grammar Ruslan@Shevchenko.Kiev.UA (rssh) (2007-11-05)
Re: Looking for LL(k) C grammar gneuner2@comcast.net (George Neuner) (2007-11-05)
| List of all articles for this month |
From: George Neuner <gneuner2@comcast.net>
Newsgroups: comp.compilers
Date: Mon, 05 Nov 2007 11:28:46 -0500
Organization: Compilers Central
References: 07-11-007
Keywords: C, LL(1)
Posted-Date: 06 Nov 2007 10:40:46 EST

On Sat, 3 Nov 2007 09:51:13 -0200, "Italo Tasso"
<italo@spwinternet.com.br> wrote:


>I am trying to make a recursive descent parser for a simplified
>version of C. It doesn't have to be predictive, but it would be good
>to have no backup.


Recursive descent is predictive by nature.


You can't realistically avoid "backing up" in an RD parser if your
language is LL(k>1), but you can reduce the impact. Unreading a token
or two is very fast ... it's when you have to clean up partial parse
results and undo complex actions like tables updates that backtracking
becomes painful. The best remedy is to implement the parser in a GC'd
language (C and C++ have GC libraries) and code important data
structures in a functional style as much as possible so you can just
abandon the updates if necessary.




>I started with the grammar in the K&R book.


Which is incomplete.


C is fairly complex to parse. Depending on what your subset consists
of, you may be better off just locating an existing grammar written
for your parser tool and pruning the stuff you don't need.


George


Post a followup to this message

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