diff options
| author | Graydon Hoare <[email protected]> | 2010-09-28 14:01:21 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-09-28 14:01:21 -0700 |
| commit | 5a4cb3ef36bc0610284c5e67c239363d3757df71 (patch) | |
| tree | a1648adb11d18d0d3767a5ebf0b6b52d75ca8ed8 /src/comp/front/parser.rs | |
| parent | Translate literal int, char, bool and str types, as well as logging them. (diff) | |
| download | rust-5a4cb3ef36bc0610284c5e67c239363d3757df71.tar.xz rust-5a4cb3ef36bc0610284c5e67c239363d3757df71.zip | |
Translate a modest selection of easy binops.
Diffstat (limited to 'src/comp/front/parser.rs')
| -rw-r--r-- | src/comp/front/parser.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 9596f714..98cb7e1e 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -250,11 +250,13 @@ state fn parse_prefix_expr(parser p) -> @ast.expr { alt (p.peek()) { case (token.NOT) { + p.bump(); auto e = parse_prefix_expr(p); ret @ast.expr_unary(ast.not, e); } case (token.TILDE) { + p.bump(); auto e = parse_prefix_expr(p); ret @ast.expr_unary(ast.bitnot, e); } @@ -263,11 +265,13 @@ state fn parse_prefix_expr(parser p) -> @ast.expr { alt (b) { case (token.MINUS) { + p.bump(); auto e = parse_prefix_expr(p); ret @ast.expr_unary(ast.neg, e); } case (token.STAR) { + p.bump(); auto e = parse_prefix_expr(p); ret @ast.expr_unary(ast.deref, e); } @@ -298,19 +302,16 @@ state fn parse_binops(parser p, auto more = true; while (more) { more = false; - auto t = p.peek(); - alt (t) { - case (token.BINOP(?op)) { - for (tup(token.binop, ast.binop) pair in ops) { + for (tup(token.binop, ast.binop) pair in ops) { + alt (p.peek()) { + case (token.BINOP(?op)) { if (pair._0 == op) { + p.bump(); e = @ast.expr_binary(pair._1, e, sub(p)); more = true; - t = p.peek(); } } } - case (_) { - } } } ret e; @@ -324,12 +325,11 @@ state fn parse_binary_exprs(parser p, auto more = true; while (more) { more = false; - auto t = p.peek(); for (tup(token.token, ast.binop) pair in ops) { - if (pair._0 == t) { + if (pair._0 == p.peek()) { + p.bump(); e = @ast.expr_binary(pair._1, e, sub(p)); more = true; - t = p.peek(); } } } |