Mercurial > projects > dang
changeset 123:6a5f745d351c
Parsing <<, >> and >>>.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Sun, 25 May 2008 21:07:48 +0200 |
parents | 95dfe2f48dcf |
children | aa3bb5d8ba0c |
files | ast/Exp.d lexer/Lexer.d lexer/Token.d parser/Action.d parser/Parser.d tests/parser/shift_1.d |
diffstat | 6 files changed, 36 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ast/Exp.d Sun May 25 20:30:09 2008 +0200 +++ b/ast/Exp.d Sun May 25 21:07:48 2008 +0200 @@ -179,9 +179,11 @@ Add, Sub, Mul, Div, Mod, + + LeftShift, RightShift, UnsignedRightShift, } - char[][] getOp = ["=","==","!=","<","<=",">",">=","+","-","*","/","%"]; + char[][] getOp = ["=","==","!=","<","<=",">",">=","+","-","*","/","%","<<",">>",">>>"]; this(SLoc op_loc, Operator op, Exp left, Exp right) {
--- a/lexer/Lexer.d Sun May 25 20:30:09 2008 +0200 +++ b/lexer/Lexer.d Sun May 25 21:07:48 2008 +0200 @@ -188,12 +188,22 @@ { if(source[position] == '=') return Token(Tok.Le, Loc(position++ - 1), 2); + if(source[position] == '<') + return Token(Tok.LeftShift, Loc(position++ - 1), 2); return Token(Tok.Lt, Loc(position - 1), 1); } Token ge() { if(source[position] == '=') return Token(Tok.Ge, Loc(position++ - 1), 2); + if(source[position] == '>') + if(source[position+1] == '>') + { + position += 2; + return Token(Tok.UnsignedRightShift, Loc(position - 1), 3); + } + else + return Token(Tok.RightShift, Loc(position++ - 1), 2); return Token(Tok.Gt, Loc(position - 1), 1); } Token plus()
--- a/lexer/Token.d Sun May 25 20:30:09 2008 +0200 +++ b/lexer/Token.d Sun May 25 21:07:48 2008 +0200 @@ -95,6 +95,7 @@ Assign, Plus, Minus, Star, Slash, Percent, + LeftShift, RightShift, UnsignedRightShift, Comma, /* Symbols */ @@ -183,6 +184,9 @@ Tok.Star:"Star", Tok.Slash:"Slash", Tok.Percent:"Percent", + Tok.LeftShift:"LeftShift", + Tok.RightShift:"RightShift", + Tok.UnsignedRightShift:"UnsignedRightShift", Tok.Integer:"Integer", Tok.If:"If", Tok.While:"While",
--- a/parser/Action.d Sun May 25 20:30:09 2008 +0200 +++ b/parser/Action.d Sun May 25 21:07:48 2008 +0200 @@ -17,6 +17,8 @@ Add, Sub, Mul, Div, Mod, + + LeftShift, RightShift, UnsignedRightShift, }
--- a/parser/Parser.d Sun May 25 20:30:09 2008 +0200 +++ b/parser/Parser.d Sun May 25 21:07:48 2008 +0200 @@ -706,7 +706,11 @@ {Tok.Star, 5, true, Operator.Mul}, {Tok.Slash, 5, true, Operator.Div}, - {Tok.Percent, 5, true, Operator.Mod} + {Tok.Percent, 5, true, Operator.Mod}, + + {Tok.LeftShift, 8, true, Operator.LeftShift}, + {Tok.RightShift, 8, true, Operator.RightShift}, + {Tok.UnsignedRightShift, 8, true, Operator.UnsignedRightShift} ]; BinOp* binary(Tok t) {