May 25, 2006
In article <e53f58$15dc$1@digitaldaemon.com>, Bill Baxter says...
>
>In article <e4tv46$2007$1@digitaldaemon.com>, Dave says...
>>
>>Walter Bright wrote:
>>> It has grammatical ambiguities. Consider:
>>> 
>>> int foo(int x, y);
>>> 
>>> Is the second a declaration of y of type int, or is it a parameter of type y?
>>
>So what about a semi colon or colon or something instead of the comma?
>
>int foo(int x ; y, float z);
>int foo(int x : y : z);

Or even a space for that matter:

int foo(int x y z, real z);

But when you say there's a grammatical ambiguity, can there actually be variables with the same names as types?  Isn't that against the rules?  So it's just a low level syntactical ambiguity you're talking about, right?  At the time you see the ', real' there's ambiguity but only until you check if 'real' is a type or not.

In other words
int foo(int x, real)
has to be one int arg, one real arg, and not two int args, one named 'x', the
other named 'real'.  Right?


Bill
May 25, 2006

Bill Baxter wrote:
> [snip]
> 
> But when you say there's a grammatical ambiguity, can there actually be variables with the same names as types?  Isn't that against the rules?  So it's just a low level syntactical ambiguity you're talking about, right?  At the time you see the ', real' there's ambiguity but only until you check if 'real' is a type or not.

That's the problem.  That can't be done in a context-free grammar[1]. This means that the stages of parsing and semantic analysis aren't independent, which is a big deal to Walter (and for good reason).

It's a good idea, and I like it; but you need to find a way to express it unambiguously.

	-- Daniel Keep

[1] Note: this is based on my somewhat shaky understanding of what "context free grammar" means.  I could very well be wrong, but my intuition tells me otherwise.

-- 

v1sw5+8Yhw5ln4+5pr6OFma8u6+7Lw4Tm6+7l6+7D a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP    http://hackerkey.com/
May 25, 2006
Daniel Keep wrote:
> [1] Note: this is based on my somewhat shaky understanding of what
> "context free grammar" means.  I could very well be wrong, but my
> intuition tells me otherwise.

In this instance, you're right.
May 26, 2006
In article <e53f58$15dc$1@digitaldaemon.com>, Bill Baxter says...

>
>So what about a semi colon or colon or something instead of the comma?
>
>int foo(int x ; y, float z);
>int foo(int x : y : z);

My old proposal was to use a colon to disambiguate declarations. So

int foo (int x, int y, int z, float value);

could also be written as:

int foo (int : x, y, z; float value);

My proposal went further, forcing to use a colon for multiple declarations:

int a;         // OK
int b, c;      // error
int : d;       // also OK
int : e, f, g; // OK

Ciao

---
http://www.mariottini.net/roberto/
1 2
Next ›   Last »