From 17304c82fd99374246fbc78fc166ac80f9b777c4 Mon Sep 17 00:00:00 2001 From: mathias Date: Sat, 14 Dec 2019 22:17:34 +0100 Subject: [PATCH] #17 parsing support for comparison expressions --- src/ast.rs | 2 ++ src/lexer.rs | 6 ++++++ src/parser.rs | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/ast.rs b/src/ast.rs index 1af7875a86..07c9093dc1 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -42,4 +42,6 @@ pub enum Operator { Minus, Multiplication, Division, + OperatorEqual, + OperatorNotEqual, } diff --git a/src/lexer.rs b/src/lexer.rs index 35d9519f17..3c37eefcfe 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -51,6 +51,12 @@ pub enum Token { #[token = "/"] OperatorDivision, + #[token = "="] + OperatorEqual, + + #[token = "<>"] + OperatorNotEqual, + #[regex = r"[0-9]+(\.(0-9)+)?"] LiteralNumber, } diff --git a/src/parser.rs b/src/parser.rs index 59174dd9ea..9efb4ca124 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -117,6 +117,26 @@ fn parse_primary_expression(lexer: &mut RustyLexer) -> Result parse_additive_expression(lexer) } +fn parse_equality_expression(lexer: &mut RustyLexer) -> Result { + let left = parse_compare_expression(lexer); + let operator = match lexer.token { + OperatorEqual => Operator::Equal, + OperatorNotEqual => Operator::NotEqual, + _ => return Ok(left), + }; + lexer.advance(); + let right = parse_primary_expression(lexer)?; + Ok(Statement::BinaryExpression { + operator, + left: Box::new(left), + right: Box::new(right), + }) +} + +fn parse_compare_expression(lexer: &mut RustyLexer) -> Result { + +} + fn parse_additive_expression(lexer: &mut RustyLexer) -> Result { let left = parse_multiplication_expression(lexer)?; let operator = match lexer.token {