From 9f828dde673f6b9da28936d99098540ed844200e Mon Sep 17 00:00:00 2001 From: vanten Date: Sat, 30 Sep 2023 22:14:12 +0200 Subject: [PATCH] Deleted unnecesary code --- src/assembler.rs | 5 ++++ src/ast.rs | 15 +----------- src/main.rs | 1 + src/parse.rs | 64 ------------------------------------------------ 4 files changed, 7 insertions(+), 78 deletions(-) create mode 100644 src/assembler.rs diff --git a/src/assembler.rs b/src/assembler.rs new file mode 100644 index 0000000..4ed5762 --- /dev/null +++ b/src/assembler.rs @@ -0,0 +1,5 @@ +use std::collections::HashMap; + +fn parse_label(line: String, line_i: i64) { + +} \ No newline at end of file diff --git a/src/ast.rs b/src/ast.rs index 5cc83c1..dda9bcf 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -39,24 +39,11 @@ pub enum BinOp { Minus, } -#[derive(Debug, Clone)] -pub enum ValueNode { - Literal(Literal), - Operator(Operator), - Variable(String), -} - #[derive(Debug, Clone)] pub enum Literal { Int(i64), } -#[derive(Debug, Clone)] -pub enum Operator { - Add(Box, Box), - Sub(Box, Box), -} - #[derive(Debug, Clone)] pub struct AssemblerState { pub functions: HashMap, @@ -467,7 +454,7 @@ C-OUT RAM-IN 0xFF ; Store address after jump in ram } impl Node for Unary { - fn to_assembly(&self, state: &mut AssemblerState) -> String { + fn to_assembly(&self, _state: &mut AssemblerState) -> String { todo!() } } diff --git a/src/main.rs b/src/main.rs index 6a7b6db..4b4b724 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ mod ast; mod parse; +mod assembler; mod tokeniser; fn main() { diff --git a/src/parse.rs b/src/parse.rs index 7f8e335..b15424c 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,71 +1,7 @@ -use std::collections::{HashMap, HashSet}; - use crate::ast::*; use crate::tokeniser::Keyword; use crate::tokeniser::Token; -fn parse_math(tokens: &Vec) -> ValueNode { - let mut prioritizing_order: HashMap> = HashMap::new(); - prioritizing_order.insert(0, HashSet::from([Token::Plus, Token::Minus])); - - let mut ordered_binops: Vec = Vec::new(); - let mut ordered_binops_indexes: Vec = Vec::new(); - - if tokens.len() == 1 { - return match &tokens[0] { - Token::Number(n) => ValueNode::Literal(Literal::Int(n.parse::().unwrap())), - Token::Identifier(identifier) => ValueNode::Variable(identifier.to_owned()), - _ => todo!(), - }; - } - - for j in prioritizing_order.keys() { - let mut i = 0; - let current_order_binops = prioritizing_order.get(j).unwrap(); - - while i < tokens.len() { - for binop in current_order_binops { - if &tokens[i] == binop { - ordered_binops.push(binop.to_owned()); - ordered_binops_indexes.push(i); - } - } - - i += 1; - } - } - - let binop = ordered_binops.pop().unwrap(); - let binop_index = ordered_binops_indexes.pop().unwrap(); - - let mut a: Vec = Vec::new(); - let mut b: Vec = Vec::new(); - - let mut i = 0; - while i < tokens.len() { - if i < binop_index { - a.push(tokens[i].clone()); - } - if i > binop_index { - b.push(tokens[i].clone()); - } - - i += 1; - } - - return match binop { - Token::Plus => ValueNode::Operator(Operator::Add( - Box::new(parse_math(&a)), - Box::new(parse_math(&b)), - )), - Token::Minus => ValueNode::Operator(Operator::Sub( - Box::new(parse_math(&a)), - Box::new(parse_math(&b)), - )), - _ => todo!(), - }; -} - fn parse_basic(tokens: &Vec, i: &mut usize) -> Expression { let literal = match &tokens[*i] { Token::Identifier(identifier) => Expression::Variable(identifier.to_owned()),