From d1301b30e68cead21054ea644f9d4aaae8e216e8 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 12 Sep 2017 02:30:27 -0700 Subject: [PATCH] Added infra for operators --- src/schala_lang/parsing.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 2f36bb7..4b7f7c1 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -293,7 +293,8 @@ param_list := (identifier type_anno+ Comma)* type_anno := Colon type -expression := primary +expression := precedence_expr +precedence_expr := primary primary := literal literal := TRUE | FALSE | number_literal | str_literal @@ -373,6 +374,22 @@ pub enum TypeBody { pub enum Expression { IntLiteral(u64), FloatLiteral(f64), + BinExp(Operator, Box, Box) +} + +#[derive(Debug, PartialEq)] +pub struct Operator { + op: [char; 5] //operators can be at most 5 characters long +} + +impl Operator { + fn get_precedence(&self) -> i32 { + match self.op[0] { + '+' | '-' => 10, + '*' | '/' | '%' => 20, + _ => 30, + } + } } impl Parser { @@ -420,7 +437,9 @@ impl Parser { } fn expression(&mut self) -> ParseResult { - self.primary() + let lhs = self.primary()?; + //self.primary() + Ok(lhs) } fn primary(&mut self) -> ParseResult {