Related articles |
---|
Handing typedefs in yacc generated parsers dibyendu@mazumdar.demon.co.uk (Dibyendu Majumdar) (1999-01-11) |
Re: Handing typedefs in yacc generated parsers desw@cogs.susx.ac.uk (1999-01-15) |
Re: Handing typedefs in yacc generated parsers dibyendu@mazumdar.demon.co.uk (Dibyendu Majumdar) (1999-01-19) |
From: | desw@cogs.susx.ac.uk (Des Watson) |
Newsgroups: | comp.compilers |
Date: | 15 Jan 1999 01:09:00 -0500 |
Organization: | University of Sussex |
References: | 99-01-030 |
Keywords: | C, parse, types |
Dibyendu Majumdar (dibyendu@mazumdar.demon.co.uk) wrote:
: The problem with this approach was that a TYPEDEF_NAME could appear
: anywhere an IDENTIFIER was expected, causing the yacc parser (grammer
: based on K&R2) to fail.
I had this problem when writing a C compiler some while ago. My
approach was to move to the Roskind grammar (and, in fact, this proved
not to be all that much effort). I initially tried adding context
sensitivity to the lexer in a half-hearted way, and I never felt
entirely happy with the results. But your algorithm looks somewhat
more thoughtful than mine...!
A useful program which may break some compilers is:
#include <stdio.h>
typedef char x;
void foo() {
int a=sizeof(x),x,b=sizeof(x);
x=1;
printf("a=%d, b=%d, x=%d\n",a,b,x);
}
void main() {
foo();
}
I forget where this originated (maybe from the Roskind support
information).
Des
Return to the
comp.compilers page.
Search the
comp.compilers archives again.