From 83961409a75dee76b03d913dcf435fbe3c72ba54 Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 20 Mar 2023 20:54:43 -0700 Subject: [PATCH] Added basic number parser --- README.md | 2 +- src/parser/replace_words.rs | 8 ++++++++ src/parser/tokenize.rs | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e16c4d8..3d21f6b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ - Fix documentation and variable names - implicit multiply - Function application - - Syntax check (parenthesis, argument type) + - Syntax check (parenthesis, argument type, position of error) # Eventually - rationals diff --git a/src/parser/replace_words.rs b/src/parser/replace_words.rs index 12c77bb..f53a05d 100644 --- a/src/parser/replace_words.rs +++ b/src/parser/replace_words.rs @@ -20,6 +20,14 @@ pub fn replace_words(g: &mut Token) -> Result<(), ()> { replace_words(&mut t)?; new.push_back(t); }, + Token::PreNumber(ref s) => { + let n = match s.parse() { + Ok(n) => n, + Err(_) => panic!() + }; + + new.push_back(Token::Number(n)); + } Token::PreWord(ref s) => { if s == "to" { new.push_back(Token::PreOperator(String::from("to"))); diff --git a/src/parser/tokenize.rs b/src/parser/tokenize.rs index 928c7c9..c0cf05b 100644 --- a/src/parser/tokenize.rs +++ b/src/parser/tokenize.rs @@ -11,7 +11,13 @@ pub enum Token { PreNumber(String), PreWord(String), + // All PreGroups should vanish after operator folding + // All PreOperators should become Operators + // All PreNumbers should become Numbers + // All PreWords should become TODO. + // Only used in tree + Number(f64), Multiply(VecDeque), Divide(VecDeque), Add(VecDeque),