Mercurial > projects > dang
changeset 62:78a6808b2e0f new_gen
Added support for "%" - modulus / reminder
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 29 Apr 2008 16:34:11 +0200 |
parents | 575c267bdd1f |
children | 932bb3c6b80b |
files | ast/Exp.d gen/CodeGen.d lexer/Lexer.d lexer/Token.d parser/Parser.d |
diffstat | 5 files changed, 14 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/ast/Exp.d Tue Apr 29 15:11:39 2008 +0200 +++ b/ast/Exp.d Tue Apr 29 16:34:11 2008 +0200 @@ -78,7 +78,8 @@ i.env = f.env; f.env.add(i); f.env.find(i).type = t; - auto var = new VarDecl(new Identifier(t.name), i, null); + auto ty = new Identifier(t.name); + auto var = new VarDecl(ty, i, null); Exp[] args; args ~= i; args ~= this.args;
--- a/gen/CodeGen.d Tue Apr 29 15:11:39 2008 +0200 +++ b/gen/CodeGen.d Tue Apr 29 16:34:11 2008 +0200 @@ -40,6 +40,7 @@ op.Sub : &b.buildSub, op.Mul : &b.buildMul, op.Div : &b.buildSDiv, + op.Mod : &b.buildSRem, op.Eq : mixin(genBuildCmp("EQ")), op.Ne : mixin(genBuildCmp("NE")), op.Lt : mixin(genBuildCmp("SLT")),
--- a/lexer/Lexer.d Tue Apr 29 15:11:39 2008 +0200 +++ b/lexer/Lexer.d Tue Apr 29 16:34:11 2008 +0200 @@ -39,7 +39,7 @@ foreach( char c ; "0123456789") charTable[c] = CharType.Number; - foreach( char c ; "(){};:.,=!<>+-*/") + foreach( char c ; "(){};:.,=!<>+-*/%") charTable[c] = CharType.Symbol; foreach( char c ; " \n") @@ -63,6 +63,7 @@ symbolFunctions['-'] = ⊂ symbolFunctions['*'] = &mul; symbolFunctions['/'] = ÷ + symbolFunctions['%'] = &mod; } /** @@ -244,6 +245,11 @@ return Token(Tok.Div, Location(position - 1, this.source), 1); } } + + Token mod() + { + return Token(Tok.Mod, Location(position - 1, this.source), 1); + } Token lexNumber () {
--- a/lexer/Token.d Tue Apr 29 15:11:39 2008 +0200 +++ b/lexer/Token.d Tue Apr 29 16:34:11 2008 +0200 @@ -101,7 +101,7 @@ /* Basic operators */ Assign, Add, Sub, - Mul, Div, + Mul, Div, Mod, Comma, /* Symbols */ @@ -176,6 +176,7 @@ Tok.Sub:"Sub", Tok.Mul:"Mul", Tok.Div:"Div", + Tok.Mod:"Mod", Tok.Integer:"Integer", Tok.If:"If", Tok.While:"While",
--- a/parser/Parser.d Tue Apr 29 15:11:39 2008 +0200 +++ b/parser/Parser.d Tue Apr 29 16:34:11 2008 +0200 @@ -419,7 +419,8 @@ {Tok.Sub, 3, true, Operator.Sub}, {Tok.Mul, 5, true, Operator.Mul}, - {Tok.Div, 5, true, Operator.Div} + {Tok.Div, 5, true, Operator.Div}, + {Tok.Mod, 5, true, Operator.Mod} ]; BinOp* binary(Tok t) {