# HG changeset patch # User aziz # Date 1184365862 0 # Node ID c7b250662c74205f778db97c295bd22946c4eaae # Parent 82c5cfc7d6d33977f1815710b03f08c5cf80209a - Added class ScopeStatement. - Fix: didn't creat class instance in parseStatements(). - Implemented parseIfStatement(). diff -r 82c5cfc7d6d3 -r c7b250662c74 trunk/src/Parser.d --- a/trunk/src/Parser.d Fri Jul 13 20:49:01 2007 +0000 +++ b/trunk/src/Parser.d Fri Jul 13 22:31:02 2007 +0000 @@ -1109,7 +1109,7 @@ Statements parseStatements() { - Statements statements; + auto statements = new Statements(); while (token.type != T.RBrace && token.type != T.EOF) statements ~= parseStatement(); return statements; @@ -1136,11 +1136,78 @@ case_Declaration: // TODO: parse Declaration break; + case T.If: + s = parseIfStatement(); + break; default: } return s; } + /+ + ScopeStatement: + NonEmptyStatement + BlockStatement + BlockStatement: + { } + { StatementList } + +/ + Statement parseScopeBlockStatement() + { + Statement s; + if (token.type == T.LBrace) + { + nT(); + auto ss = new Statements(); + while (token.type != T.RBrace && token.type != T.EOF) + ss ~= parseStatement(); + require(T.RBrace); + s = ss; + } + else + s = parseStatement(); + return new ScopeStatement(s); + } + + Statement parseIfStatement() + { + assert(token.type == T.If); + nT(); + + Type type; + string ident; + Expression condition; + Statement ifBody, elseBody; + + require(T.LParen); + // auto Identifier = Expression + if (token.type == T.Auto) + { + nT(); + ident = requireIdentifier(); + require(T.Assign); + } + else + { + // Declarator = Expression + bool failed; + type = try_(parseDeclarator(ident), failed); + if (!failed) + { + require(T.Assign); + } + } + condition = parseExpression(); + require(T.RParen); + ifBody = parseScopeBlockStatement(); + if (token.type == T.Else) + { + nT(); + elseBody = parseScopeBlockStatement(); + } + return new IfStatement(type, ident, condition, ifBody, elseBody); + } + /+++++++++++++++++++++++++++++ + Expression parsing methods + +++++++++++++++++++++++++++++/ diff -r 82c5cfc7d6d3 -r c7b250662c74 trunk/src/Statements.d --- a/trunk/src/Statements.d Fri Jul 13 20:49:01 2007 +0000 +++ b/trunk/src/Statements.d Fri Jul 13 22:31:02 2007 +0000 @@ -3,6 +3,8 @@ License: GPL2 +/ module Statements; +import Expressions; +import Types; class Statement { @@ -18,6 +20,15 @@ } } +class ScopeStatement : Statement +{ + Statement s; + this(Statement s) + { + this.s = s; + } +} + class LabeledStatement : Statement { string label; @@ -41,7 +52,19 @@ class IfStatement : Statement { - + Type type; + string ident; + Expression condition; + Statement ifBody; + Statement elseBody; + this(Type type, string ident, Expression condition, Statement ifBody, Statement elseBody) + { + this.type = type; + this.ident = ident; + this.condition = condition; + this.ifBody = ifBody; + this.elseBody = elseBody; + } } class ConditionalStatement : Statement