From 13e7a55d3924f77fccf8b97a2373dfb29eba6e5a Mon Sep 17 00:00:00 2001 From: David Li Date: Sat, 4 Nov 2017 19:38:55 -0400 Subject: Parse logical operators --- src/ast.rs | 3 +++ src/taiga.lalrpop | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ast.rs b/src/ast.rs index ab9493e..4eea431 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -38,6 +38,7 @@ pub struct Program(pub Box>); pub enum UnaryOp { Pos, Neg, + Not, } #[derive(Debug)] @@ -53,6 +54,8 @@ pub enum BinOp { Lt, Ge, Le, + And, + Or, } #[derive(Debug)] diff --git a/src/taiga.lalrpop b/src/taiga.lalrpop index 6aedf42..68238eb 100644 --- a/src/taiga.lalrpop +++ b/src/taiga.lalrpop @@ -8,10 +8,24 @@ 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::And, Box::new(v1), Box::new(v2)) + })), + "||" => Box::new(e1.join_map(*e2, |v1, v2| { + ast::Expression::BinOp(ast::BinOp::Or, Box::new(v1), Box::new(v2)) + })), + "!" => Box::new(WithLocation::new( + ast::Expression::UnaryOp(ast::UnaryOp::Not, e), + l, r + )), + => <>, +}; + +ExpressionEq: Box> = { + "=" => 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| { + "!=" => Box::new(e1.join_map(*e2, |v1, v2| { ast::Expression::BinOp(ast::BinOp::Neq, Box::new(v1), Box::new(v2)) })), => <>, -- cgit v1.2.3