From f934912007eced76f45491442202412894fc96ec Mon Sep 17 00:00:00 2001 From: Jake Date: Thu, 5 Sep 2024 02:17:42 -0700 Subject: [PATCH] Fix everything --- src/parse.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/parse.rs b/src/parse.rs index 580bc1f..a0040ad 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -8,6 +8,7 @@ pub trait Parser { fn parse(&mut self, tokens: Vec) -> Token; } +#[derive(Debug)] pub struct ParserState { function_mode: bool, verbose: bool, @@ -16,6 +17,7 @@ pub struct ParserState { local_memory: HashMap, function_stack: Vec, function_memory: HashMap>, + token_index: usize, } impl Parser for ParserState { @@ -529,11 +531,9 @@ impl Parser for ParserState { self.function_mode = false; self.token_stack.append(&mut tokens.clone()); - let mut i = 0; - // Parse postfix notation - while i < self.token_stack.len() { - let token = self.token_stack[i].clone(); + while self.token_index < self.token_stack.len() { + let token = self.token_stack[self.token_index].clone(); if self.verbose { println!( @@ -605,7 +605,8 @@ impl Parser for ParserState { } } } - i += 1; + self.token_index += 1; + continue; } _ => { @@ -616,7 +617,7 @@ impl Parser for ParserState { self.match_token_type(token); } - i += 1; + self.token_index += 1; } if self.verbose { @@ -679,6 +680,7 @@ pub fn create_parser(verbose: bool) -> ParserState { stack: Vec::::new(), token_stack: Vec::::new(), function_stack: Vec::::new(), + token_index: 0, } }