2012-04-17 20:41:04 -07:00
|
|
|
export as_prec;
|
|
|
|
export unop_prec;
|
2012-04-26 16:13:59 -07:00
|
|
|
export token_to_binop;
|
|
|
|
|
|
|
|
import token::*;
|
|
|
|
import token::token;
|
|
|
|
import ast::*;
|
2012-04-17 20:41:04 -07:00
|
|
|
|
2012-07-04 22:53:12 +01:00
|
|
|
/// Unary operators have higher precedence than binary
|
2012-04-26 16:13:59 -07:00
|
|
|
const unop_prec: uint = 100u;
|
2012-04-17 20:41:04 -07:00
|
|
|
|
2012-07-04 22:53:12 +01:00
|
|
|
/**
|
|
|
|
* Precedence of the `as` operator, which is a binary operator
|
|
|
|
* but is not represented in the precedence table.
|
|
|
|
*/
|
2012-04-26 16:13:59 -07:00
|
|
|
const as_prec: uint = 11u;
|
2012-04-17 20:41:04 -07:00
|
|
|
|
2012-07-04 22:53:12 +01:00
|
|
|
/**
|
|
|
|
* Maps a token to a record specifying the corresponding binary
|
|
|
|
* operator and its precedence
|
|
|
|
*/
|
2012-04-26 16:13:59 -07:00
|
|
|
fn token_to_binop(tok: token) -> option<ast::binop> {
|
|
|
|
alt tok {
|
2012-08-03 19:59:04 -07:00
|
|
|
BINOP(STAR) => some(mul),
|
|
|
|
BINOP(SLASH) => some(div),
|
|
|
|
BINOP(PERCENT) => some(rem),
|
2012-04-26 16:13:59 -07:00
|
|
|
// 'as' sits between here with 11
|
2012-08-03 19:59:04 -07: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 16:13:59 -07:00
|
|
|
}
|
2012-04-17 20:41:04 -07:00
|
|
|
}
|