From 9891204b026c7660676f456128c94b01ae7f39cf Mon Sep 17 00:00:00 2001 From: David Li Date: Sat, 4 Nov 2017 19:33:45 -0400 Subject: Parse comparison operators --- src/taiga.lalrpop | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'src/taiga.lalrpop') diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop index 6bf750d..6aedf42 100644 --- a/src/taiga.lalrpop +++ b/src/taiga.lalrpop @@ -8,10 +8,36 @@ pub Program: ast::Program = { }; Expression: Box> = { - "+" => Box::new(e1.join_map(*e2, |v1, v2| { + "=" => Box::new(e1.join_map(*e2, |v1, v2| { + ast::Expression::BinOp(ast::BinOp::Eq, Box::new(v1), Box::new(v2)) + })), + "!=" => Box::new(e1.join_map(*e2, |v1, v2| { + ast::Expression::BinOp(ast::BinOp::Neq, Box::new(v1), Box::new(v2)) + })), + => <>, +}; + +ExpressionCmp: Box> = { + ">" => Box::new(e1.join_map(*e2, |v1, v2| { + ast::Expression::BinOp(ast::BinOp::Gt, Box::new(v1), Box::new(v2)) + })), + "<" => Box::new(e1.join_map(*e2, |v1, v2| { + ast::Expression::BinOp(ast::BinOp::Lt, Box::new(v1), Box::new(v2)) + })), + ">=" => Box::new(e1.join_map(*e2, |v1, v2| { + ast::Expression::BinOp(ast::BinOp::Ge, Box::new(v1), Box::new(v2)) + })), + "<=" => Box::new(e1.join_map(*e2, |v1, v2| { + ast::Expression::BinOp(ast::BinOp::Le, Box::new(v1), Box::new(v2)) + })), + => <>, +}; + +ExpressionAdd: Box> = { + "+" => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::Add, Box::new(v1), Box::new(v2)) })), - "-" => Box::new(e1.join_map(*e2, |v1, v2| { + "-" => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::Sub, Box::new(v1), Box::new(v2)) })), => <>, -- cgit v1.2.3