[antlr-interest] cgram problem

Jan Obdrzalek obdrzalek at gmail.com
Mon Nov 20 07:20:50 PST 2006


Hello,

I think I've encountered a problem in the cgram C grammar. The code
below can pass "gcc -c -std=c89" (i.e. should be allright as far as
ISO C89 standard is concerned), but GnuCParser from cgram crashes on
it.

<<< test.c <<<
void a(void){
	int a=5;
	struct s *ps=({
	typedef int T;
	T t;
	&a;
	});
	return;
}
>>> test.c >>>

I've tried to investigate the problem and found that it looks to be
caused by the following sequence of steps:
- when the parser first encounters the initializer of ps (which is a
compound statement),  the action of opening new scope is not executed
because the parser is in "guess mode"
- for the same reason the new type T not added to the symbol table
- when "T t" is encountered, the check whether T is a tyoedef name
fails, since there is no typedef name T in our current symbol table

Have I missed something, or is it genuine error in cgram? Is there an
easy way to fix this?

Thanks,
Jan


More information about the antlr-interest mailing list