Added basic number parser

pull/2/head
Mark 2023-03-20 20:54:43 -07:00
parent 0fe50e8210
commit 83961409a7
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
3 changed files with 15 additions and 1 deletions

View File

@ -2,7 +2,7 @@
- Fix documentation and variable names - Fix documentation and variable names
- implicit multiply - implicit multiply
- Function application - Function application
- Syntax check (parenthesis, argument type) - Syntax check (parenthesis, argument type, position of error)
# Eventually # Eventually
- rationals - rationals

View File

@ -20,6 +20,14 @@ pub fn replace_words(g: &mut Token) -> Result<(), ()> {
replace_words(&mut t)?; replace_words(&mut t)?;
new.push_back(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) => { Token::PreWord(ref s) => {
if s == "to" { if s == "to" {
new.push_back(Token::PreOperator(String::from("to"))); new.push_back(Token::PreOperator(String::from("to")));

View File

@ -11,7 +11,13 @@ pub enum Token {
PreNumber(String), PreNumber(String),
PreWord(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 // Only used in tree
Number(f64),
Multiply(VecDeque<Token>), Multiply(VecDeque<Token>),
Divide(VecDeque<Token>), Divide(VecDeque<Token>),
Add(VecDeque<Token>), Add(VecDeque<Token>),