Re: ANSI C Yacc grammar (
23 Oct 2001 20:24:24 -0400

          From comp.compilers

Related articles
ANSI C Yacc grammar (2001-10-20)
Re: ANSI C Yacc grammar (2001-10-23)
Re: ANSI C Yacc grammar (Axel Kittenberger) (2001-10-23)
Re: ANSI C Yacc grammar (2001-10-27)
| List of all articles for this month |

From: (
Newsgroups: comp.compilers
Date: 23 Oct 2001 20:24:24 -0400
References: 01-10-101
Keywords: C, parse
Posted-Date: 23 Oct 2001 20:24:24 EDT

> Why is this input accepted ? Is it not possible to write a grammar
> which is more close to the ANSI C syntax ? I understand that a yacc
> based grammmer could not do things like type checking and parameter
> checking etc, but a better syntax checking seems possible to me.

The syntax of the grammar is very, very different from the semantics
of the programming language. It may possible to define a grammar which
restricts the syntax in functions called 'main' as well as attempt to
remove all other semantic issues, but the grammar would become far too
complicated for practical use with YACC, the GOLD Parser, JavaCC or
any other parser generator.

For problems like this, it is better to test for semantic problems
after the initial parsing is complete and the program is stored in the
intermediate form.

I have another version of the C grammar on my website, if you are

Anyway, I wish you well on your project.

- Devin D. Cook

Post a followup to this message

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