2012-04-17 22:41:04 -05:00
|
|
|
export as_prec;
|
|
|
|
export unop_prec;
|
2012-04-26 18:13:59 -05:00
|
|
|
export token_to_binop;
|
|
|
|
|
|
|
|
import token::*;
|
|
|
|
import token::token;
|
|
|
|
import ast::*;
|
2012-04-17 22:41:04 -05:00
|
|
|
|
|
|
|
#[doc = "Unary operators have higher precedence than binary"]
|
2012-04-26 18:13:59 -05:00
|
|
|
const unop_prec: uint = 100u;
|
2012-04-17 22:41:04 -05:00
|
|
|
|
|
|
|
#[doc = "
|
|
|
|
Precedence of the `as` operator, which is a binary operator
|
|
|
|
but is not represented in the precedence table.
|
|
|
|
"]
|
2012-04-26 18:13:59 -05:00
|
|
|
const as_prec: uint = 11u;
|
2012-04-17 22:41:04 -05:00
|
|
|
|
2012-04-26 18:13:59 -05:00
|
|
|
#[doc = "Maps a token to a record specifying the corresponding binary
|
|
|
|
operator and its precedence"]
|
|
|
|
fn token_to_binop(tok: token) -> option<ast::binop> {
|
|
|
|
alt tok {
|
|
|
|
BINOP(STAR) { some(mul) }
|
|
|
|
BINOP(SLASH) { some(div) }
|
|
|
|
BINOP(PERCENT) { some(rem) }
|
|
|
|
// 'as' sits between here with 11
|
|
|
|
BINOP(PLUS) { some(add) }
|
|
|
|
BINOP(MINUS) { some(subtract) }
|
2012-05-22 16:59:15 -05:00
|
|
|
BINOP(SHL) { some(shl) }
|
|
|
|
BINOP(SHR) { some(shr) }
|
2012-04-26 18:13:59 -05:00
|
|
|
BINOP(AND) { some(bitand) }
|
|
|
|
BINOP(CARET) { some(bitxor) }
|
|
|
|
BINOP(OR) { some(bitor) }
|
|
|
|
LT { some(lt) }
|
|
|
|
LE { some(le) }
|
|
|
|
GE { some(ge) }
|
|
|
|
GT { some(gt) }
|
|
|
|
EQEQ { some(eq) }
|
|
|
|
NE { some(ne) }
|
|
|
|
ANDAND { some(and) }
|
|
|
|
OROR { some(or) }
|
|
|
|
_ { none }
|
|
|
|
}
|
2012-04-17 22:41:04 -05:00
|
|
|
}
|