# HG changeset patch # User aziz # Date 1185448442 0 # Node ID 984d48932bcea527b214e2f9526cc14188e1babf # Parent 7bc220cdbffc0ae2a8edacf25ed6bbca777e48fd - Added class EmptyStatement. - Setting token in constructor. - No need to save token in try_(). - Added case T.For and T.Semicolon. diff -r 7bc220cdbffc -r 984d48932bce trunk/src/Parser.d --- a/trunk/src/Parser.d Wed Jul 25 18:44:00 2007 +0000 +++ b/trunk/src/Parser.d Thu Jul 26 11:14:02 2007 +0000 @@ -25,6 +25,7 @@ this(char[] srcText, string fileName) { lx = new Lexer(srcText, fileName); + token = &lx.token; } char* prev; @@ -40,7 +41,6 @@ do { lx.nextToken(); - token = &lx.token; if (!trying) { writef("\33[32m%s\33[0m", token.type); @@ -68,7 +68,6 @@ writef("\33[31mtry_\33[0m"); ++trying; // auto len = errors.length; - auto oldToken = token; auto oldCount = errorCount; auto lexerState = lx.getState(); auto result = parseMethod(); @@ -77,7 +76,6 @@ { lexerState.restore(); // Restore state of the Lexer object. // errors = errors[0..len]; // Remove errors that were added when parseMethod() was called. - token = oldToken; errorCount = oldCount; success = false; } @@ -448,6 +446,7 @@ init = si; break; } + assert(token.type == T.LBrace); //goto default; default: init = parseAssignExpression(); @@ -1444,6 +1443,9 @@ case T.Do: s = parseDoWhileStatement(); break; + case T.For: + s = parseForStatement(); + break; case T.Foreach, T.Foreach_reverse: s = parseForeachStatement(); break; @@ -1538,6 +1540,9 @@ case T.LBrace: s = parseScopeStatement(); break; + case T.Semicolon: + s = new EmptyStatement(); + break; default: bool success; auto expression = try_(parseExpression(), success); @@ -1549,7 +1554,7 @@ } else { - // TODO: issue error msg and return IllegalStatement. + error(MID.ExpectedButFound, "Statement", token.srcText); s = new IllegalStatement(token.type); nT(); } @@ -2598,6 +2603,7 @@ e = new CharLiteralExpression(token.type); break; case T.String: + // TODO: The Lexer doesn't allocate the tokens on the heap yet. So Token* will not work here. Token*[] stringLiterals; do { diff -r 7bc220cdbffc -r 984d48932bce trunk/src/Statements.d --- a/trunk/src/Statements.d Wed Jul 25 18:44:00 2007 +0000 +++ b/trunk/src/Statements.d Thu Jul 26 11:14:02 2007 +0000 @@ -31,6 +31,13 @@ } } +class EmptyStatement : Statement +{ + this() + { + } +} + class FunctionBody { Statement funcBody, inBody, outBody;