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
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/// 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
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* 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-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* Maps a token to a record specifying the corresponding binary
|
|
|
|
* operator and its precedence
|
|
|
|
*/
|
2012-08-20 14:23:37 -05:00
|
|
|
fn token_to_binop(tok: token) -> Option<ast::binop> {
|
2012-08-06 14:34:08 -05:00
|
|
|
match tok {
|
2012-08-20 14:23:37 -05:00
|
|
|
BINOP(STAR) => Some(mul),
|
|
|
|
BINOP(SLASH) => Some(div),
|
|
|
|
BINOP(PERCENT) => Some(rem),
|
2012-04-26 18:13:59 -05:00
|
|
|
// 'as' sits between here with 11
|
2012-08-20 14:23:37 -05:00
|
|
|
BINOP(PLUS) => Some(add),
|
|
|
|
BINOP(MINUS) => Some(subtract),
|
|
|
|
BINOP(SHL) => Some(shl),
|
|
|
|
BINOP(SHR) => Some(shr),
|
|
|
|
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-26 18:13:59 -05:00
|
|
|
}
|
2012-04-17 22:41:04 -05:00
|
|
|
}
|