Mercurial > projects > dang
diff parser/Parser.d @ 5:2c5a8f4c254a
Added very simple if support.
* No else
* Still no logical operators, always tests != 0
author | Anders Halager <halager@gmail.com> |
---|---|
date | Fri, 18 Apr 2008 11:46:00 +0200 |
parents | 2168f4cb73f1 |
children | 2ce5209f1954 |
line wrap: on
line diff
--- a/parser/Parser.d Fri Apr 18 11:07:46 2008 +0200 +++ b/parser/Parser.d Fri Apr 18 11:46:00 2008 +0200 @@ -92,6 +92,26 @@ ret.exp = parseExpression(); require(Tok.Seperator); return ret; + + case Tok.If: + lexer.next; + require(Tok.OpenParentheses); + auto condition = parseExpression(); + require(Tok.CloseParentheses); + + Stmt[] stmts; + if (lexer.peek.type == Tok.OpenBrace) + { + lexer.next; + while(lexer.peek.type != Tok.CloseBrace) + stmts ~= parseStatement(); + lexer.next; + } + else + stmts ~= parseStatement(); + + return new IfStmt(condition, stmts); + case Tok.Identifier: Token n = lexer.peek(1); switch(n.type)