[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Forcing multiple parse stacks to 'reduce'

From: Derek M Jones
Subject: Re: Forcing multiple parse stacks to 'reduce'
Date: Wed, 02 Mar 2005 16:07:53 +0000


>>typedef x y;
>>typedef i j;
>>is a syntactically valid function definition.
>So it seems, but I have not been able to figure out which function. :-)

The syntax does not permit an empty declaration.  So x must
be the declarator.  The second typedef is simply a declaration
and is not necessary for this to be a syntactically correct
function definition.  It's presence simply increases to the
amazement factor.

> The
>problem is that C has some grammar difficulties.

The C declaration grammar was designed to mimic
the syntax of how the declarator would appear in an
expression.  Irrespective of whether this is a good idea
in itself, the resulting declaration syntax is not people

My current problem is (courtesy of the last documentation
update)  a reported ambiguity in:

static foo (bar);
static int foo (lose);

Both declarations parse ok when they are the only line in a
file.  Putting both lines together gives a surprising ambiguity

>I have some vague memory that somebody found (fairly late, in the 90'ies) a
>grammar transformation to make C becoming LALR(1) (modulo the usual context
>tweaks for "typedef", etc.) Then you would not need using the %glr option.
>You might check the newsgroup comp.compilers and its FAQ, published there

I have a lalr(1) grammar for C (who doesn't?).  The first edition
of Harbison&Steele list the output from such a tool for C.

My interest is in measuring visible source (see ; skip to
table 26; the source of many of the tools can be found
at: ) and using a
grammar that is as close as possible to that given in the
C Standard has many advantages.  Performance is not
an issue (not that I think that nondeterministic parsing would
be a  performance bottleneck).


Derek M Jones                                           tel: +44 (0) 1252 520 
Knowledge Software Ltd                            mailto:address@hidden
Applications Standards Conformance Testing

reply via email to

[Prev in Thread] Current Thread [Next in Thread]