Re: Parser ambiguity

Chris F Clark <cfc@shell01.TheWorld.com>
Sun, 15 Mar 2009 20:28:50 -0400

          From comp.compilers

Related articles
Parser ambiguity m.helvensteijn@gmail.com (2009-03-15)
Re: Parser ambiguity cfc@shell01.TheWorld.com (Chris F Clark) (2009-03-15)
Re: Parser ambiguity max@gustavus.edu (Max Hailperin) (2009-03-15)
Re: Parser ambiguity m.helvensteijn@gmail.com (2009-03-16)
Re: Parser ambiguity m.helvensteijn@gmail.com (2009-03-16)
| List of all articles for this month |
From: Chris F Clark <cfc@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: Sun, 15 Mar 2009 20:28:50 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 09-03-066
Keywords: parse
Posted-Date: 15 Mar 2009 21:56:38 EDT

m.helvensteijn@gmail.com writes:


> The problem is that, syntactically, a function-declaration doesn't
> need any sections, and the following example (statement_sequence) is
> ambiguous, because the grammar also allows local { } scopes:
>
> int f()
> {
> int i;
> }


Doesn't your language require a semicolon at the end of a
function-declaration with no body? Most languages of the form you
have described do. If it does, "int f()" cannot be a function
declaration by itself.


If not, you have essentially paraphrased a variation on the
dangling-else problem but with function-declaration replacing if-then
and statement-sequence replacing else. Imagine how much worse that
problem would be if else clauses were legal stand-alone statements.
Well, you don't have to imagine, you have that situation.


If you can fix your language, make it unambiguous, e.g. require a
semicolon if there is no statement sequence following a function
declaration. If not, try to bend the rules so that function
delcarations always bind to the following statement sequence.


Hope this helps,
-Chris


******************************************************************************
Chris Clark Internet: christopher.f.clark@compiler-resources.com
Compiler Resources, Inc. or: compres@world.std.com
23 Bailey Rd Web Site: http://world.std.com/~compres
Berlin, MA 01503 voice: (508) 435-5016
USA fax: (978) 838-0263 (24 hours)


Post a followup to this message

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