Mercurial > projects > dang
changeset 146:8c09fdaa724e
Parsing for-loop.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Mon, 21 Jul 2008 18:16:50 +0200 |
parents | a14ac9e5c858 |
children | 060b6eb16db9 |
files | lexer/Keyword.d lexer/Token.d parser/Action.d parser/Parser.d |
diffstat | 4 files changed, 47 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/lexer/Keyword.d Mon Jul 21 17:56:33 2008 +0200 +++ b/lexer/Keyword.d Mon Jul 21 18:16:50 2008 +0200 @@ -50,6 +50,7 @@ "if" : Tok.If, "else" : Tok.Else, "while" : Tok.While, + "for" : Tok.For, "switch" : Tok.Switch, "case" : Tok.Case, "default" : Tok.Default,
--- a/lexer/Token.d Mon Jul 21 17:56:33 2008 +0200 +++ b/lexer/Token.d Mon Jul 21 18:16:50 2008 +0200 @@ -100,6 +100,14 @@ } /** + just a shortcut to avoid `token.type == tok.For`. + */ + bool isFor() + { + return type == Tok.For; + } + + /** just a shortcut to avoid `token.type == tok.If`. */ bool isIf() @@ -193,6 +201,7 @@ If, Else, While, + For, Switch, Case, Default, Break, Return, Cast, @@ -274,6 +283,7 @@ Tok.Integer:"Integer", Tok.If:"If", Tok.While:"While", + Tok.For:"For", Tok.Switch:"Switch", Tok.Case:"Case", Tok.Default:"Default",
--- a/parser/Action.d Mon Jul 21 17:56:33 2008 +0200 +++ b/parser/Action.d Mon Jul 21 18:16:50 2008 +0200 @@ -288,6 +288,13 @@ /** */ + StmtT actOnForStmt(ref Token forTok, StmtT init, ExprT cond, ExprT incre, StmtT whileBody) + { + return null; + } + + /** + */ StmtT actOnDeclStmt(DeclT decl) { return null;
--- a/parser/Parser.d Mon Jul 21 17:56:33 2008 +0200 +++ b/parser/Parser.d Mon Jul 21 18:16:50 2008 +0200 @@ -578,6 +578,35 @@ The assignments should be handled as binary expressions? */ } + else if (t.isFor) + { + Token _for = next; + require(Tok.OpenParentheses); + Stmt init = parseStatement(); + + Exp cond; + if ( !isa(Tok.Seperator)) + cond = parseExpression(); + require(Tok.Seperator); + + Exp incre; + if ( !isa(Tok.CloseParentheses)) + incre = parseExpression(); + require(Tok.CloseParentheses); + + Stmt bodyStmt = parseSingleOrCompoundStatement(); + return action.actOnForStmt(_for, init, cond, incre, bodyStmt); + + /* + One of four things: + A declaration of a function/variable `type id ...` + A direct assignment `id = exp;` + An indirect assignment `id.id = exp` + Some sort of free standing expression + + The assignments should be handled as binary expressions? + */ + } else if (t.isBasicType || t.isIdentifier) { Token iden = peek;