context-free grammar
bearophile
bearophileHUGS at lycos.com
Fri Mar 4 17:58:14 PST 2011
Simen kjaeraas:
> Well, obviously not. The grammar has one and only one meaning for that
> example - that of an a* called b, being set to c. This can be inferred
> with no other context.
This little program:
struct Foo {
int x;
Foo opBinary(string op:"*")(Foo other) {
Foo result = Foo(x * other.x);
return result;
}
void opAssign(Foo other) {
x = other.x;
}
}
void main() {
Foo a, b, c;
a * b = c;
}
Gives:
test.d(10): Error: a is used as a type
test.d(10): Error: cannot implicitly convert expression (c) of type Foo to _error_*
test.d(10): Error: declaration test.main.b is already defined
While this one gives no errors:
struct Foo {
int x;
Foo opBinary(string op:"*")(Foo other) {
Foo result = Foo(x * other.x);
return result;
}
void opAssign(Foo other) {
x = other.x;
}
}
void main() {
Foo a, b, c;
(a * b) = c;
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list