digitalmars.D.learn - is this right??
- BCS (8/8) Jun 16 2009 void main()
- BCS (5/14) Jun 16 2009 (mixin("s")) = 5;
- Ary Borenszweig (34/52) Jun 16 2009 Yes, at that point the parser is parsing statements, so if it finds a
- BCS (3/26) Jun 16 2009 http://d.puremagic.com/issues/show_bug.cgi?id=3073
- Ary Borenszweig (23/52) Jun 17 2009 Not at all!
- hasen (3/15) Jun 16 2009 mixin *expression*
void main() { int s; mixin("s") = 5; } ----- Line 4: found '=' when expecting ';' http://www.digitalmars.com/d/1.0/expression.html#MixinExpression
Jun 16 2009
Hello BCS,void main() { int s; mixin("s") = 5; } ----- Line 4: found '=' when expecting ';' http://www.digitalmars.com/d/1.0/expression.html#MixinExpression(mixin("s")) = 5; Given that the above works, it looks like the parser prematurely commits to a mixin declaration when it finds "mixin (" at function scope. Unless someone spots a flaw in this, I'll post a bug.
Jun 16 2009
BCS escribió:Hello BCS,Yes, at that point the parser is parsing statements, so if it finds a "mixin(...)" it turns it into a statement. I'm thinking about how to fix this. I think the parser should peek the next token after the closing parenthesis. If it's a semicolon, then treat it as a statement-mixin. Else, just invoke parseAssignExp and create a new ExpStatement. I modified this in Descent and it seems to work. :-) Here's the code (in Java, but the idea is simple to translate to C++): // inside Parser::parseStatement case TOKmixin: { Dsymbol d; t = peek(token); if (t.value == TOKlparen) { if (peekPastParen(t).value != TOKsemicolon) { Expression e = parseAssignExp(); s = new ExpStatement(loc(), e); } else { // mixin(string) nextToken(); check(TOKlparen); Expression e = parseAssignExp(); check(TOKrparen); check(TOKsemicolon); s = newCompileStatement(loc(), e); } break; } else { d = parseMixin(); s = newDeclarationStatement(loc(), d); break; } }void main() { int s; mixin("s") = 5; } ----- Line 4: found '=' when expecting ';' http://www.digitalmars.com/d/1.0/expression.html#MixinExpression(mixin("s")) = 5; Given that the above works, it looks like the parser prematurely commits to a mixin declaration when it finds "mixin (" at function scope. Unless someone spots a flaw in this, I'll post a bug.
Jun 16 2009
Hello Ary,BCS escribió:http://d.puremagic.com/issues/show_bug.cgi?id=3073 Hope you don't mind me quoting you.Hello BCS,Yes, at that point the parser is parsing statements, so if it finds a "mixin(...)" it turns it into a statement.void main() { int s; mixin("s") = 5; } ----- Line 4: found '=' when expecting ';' http://www.digitalmars.com/d/1.0/expression.html#MixinExpression(mixin("s")) = 5; Given that the above works, it looks like the parser prematurely commits to a mixin declaration when it finds "mixin (" at function scope. Unless someone spots a flaw in this, I'll post a bug.
Jun 16 2009
BCS escribió:Hello Ary,Not at all! But later when I went to sleep I thought about that a little more, and look at this: 1. mixin("int x = 2;"); 2. mixin("x = 2"); The first should be treated as a MixinStatement, because it ends with a semicolon. The second should be treated as a MixinExpression, because it doesn't end with a semicolon (and it's a perfectly valid expression, it's an assign expression). But according to my patch it'll be treated as a statement and it'll fail. Now this: 3. mixin("int x = 2"); is neither of them. You can only deduce that information if you can extract the contents of the mixin, paste it in the source file and treat the whole line as a statement, and you'd get things right. But now all of those lines can be: mixin(secret()); and now you don't know, you'll have to wait for semantic anlaysis to know that, but then it's too late. But I think my patch is reasonable because it allows you to do more things than before, it's backwards compatible and also you'd almost never do number 2 but instead use number 1.BCS escribió:http://d.puremagic.com/issues/show_bug.cgi?id=3073 Hope you don't mind me quoting you.Hello BCS,Yes, at that point the parser is parsing statements, so if it finds a "mixin(...)" it turns it into a statement.void main() { int s; mixin("s") = 5; } ----- Line 4: found '=' when expecting ';' http://www.digitalmars.com/d/1.0/expression.html#MixinExpression(mixin("s")) = 5; Given that the above works, it looks like the parser prematurely commits to a mixin declaration when it finds "mixin (" at function scope. Unless someone spots a flaw in this, I'll post a bug.
Jun 17 2009
BCS wrote:void main() { int s; mixin("s") = 5; } ----- Line 4: found '=' when expecting ';' http://www.digitalmars.com/d/1.0/expression.html#MixinExpressionmixin *expression* (4+3) = 5;
Jun 16 2009
hasen wrote:BCS wrote:Oh, never mind, AssignExpression can be of the form: ConditionalExpression = AssignExpression my bad.void main() { int s; mixin("s") = 5; } ----- Line 4: found '=' when expecting ';' http://www.digitalmars.com/d/1.0/expression.html#MixinExpressionmixin *expression* (4+3) = 5;
Jun 16 2009
Hello hasen,hasen wrote:Irony: I wrote a lib that abuses the grammer to allow exactly that kind of syntax <g> http://www.dsource.org/projects/scrapple/browser/trunk/backmathBCS wrote:Oh, never mind, AssignExpression can be of the form: ConditionalExpression = AssignExpression my bad.void main() { int s; mixin("s") = 5; } ----- Line 4: found '=' when expecting ';' http://www.digitalmars.com/d/1.0/expression.html#MixinExpressionmixin *expression* (4+3) = 5;
Jun 16 2009