diff --git a/bellos_scripts/basic_math.bellos b/bellos_scripts/basic_math.bellos
index bdeea06..bf2e354 100644
--- a/bellos_scripts/basic_math.bellos
+++ b/bellos_scripts/basic_math.bellos
@@ -3,38 +3,43 @@
# Demonstrating arithmetic operations
-echo Basic Math Operations
+# Addition
+result=$((5 + 3))
+echo Addition: 5 + 3 = $result
-# Simple echo statements for arithmetic
-echo Addition:
-echo 5 + 3 = 8
+# Subtraction
+result=$((10 - 4))
+echo Subtraction: 10 - 4 = $result
-echo Subtraction:
-echo 10 - 4 = 6
+# Multiplication
+result=$((6 * 7))
+echo Multiplication: 6 * 7 = $result
-echo Multiplication:
-echo 6 * 7 = 42
+# Division
+result=$((20 / 4))
+echo Division: 20 / 4 = $result
-echo Division:
-echo 20 / 4 = 5
+# Modulus
+result=$((17 % 5))
+echo Modulus: 17 % 5 = $result
-echo Modulus:
-echo 17 % 5 = 2
+# Compound operation
+result=$(( (10 + 5) * 2 ))
+echo Compound: (10 + 5) * 2 = $result
-echo Compound operation:
-echo (10 + 5) * 2 = 30
-
-# Using variables (without arithmetic)
-echo Using variables:
+# Using variables
a=7
b=3
-echo a = $a
-echo b = $b
+result=$((a + b))
+echo Variables: $a + $b = $result
-# Simple increments and decrements
-echo Increment and Decrement:
-echo count = 0
-echo count after increment: 1
-echo count after decrement: 0
+# Increment
+count=0
+count=$((count + 1))
+echo Increment: count after increment = $count
+
+# Decrement
+count=$((count - 1))
+echo Decrement: count after decrement = $count
echo Basic math operations completed.
diff --git a/dependencies.txt b/dependencies.txt
index a25ed55..4e72c59 100644
--- a/dependencies.txt
+++ b/dependencies.txt
@@ -1,3 +1,4 @@
glob = "0.3.0"
tempfile = "3.2"
shellexpand = "3.1.0"
+meval = "0.2"
diff --git a/executable/bellos b/executable/bellos
index 59a3bc1..fbca1db 100755
Binary files a/executable/bellos and b/executable/bellos differ
diff --git a/src/bellos.rs b/src/bellos.rs
index 7e915bc..e34b188 100644
--- a/src/bellos.rs
+++ b/src/bellos.rs
@@ -13,22 +13,19 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
-mod executor;
+mod executor_processes;
mod interpreter;
mod lexer;
mod parser;
mod utilities;
-use crate::executor::executor::Executor;
-use std::env;
-use std::process;
+use crate::executor_processes::executor::Executor;
fn main() {
- let args: Vec = env::args().collect();
+ let args: Vec = std::env::args().collect();
let mut executor = Executor::new();
-
if let Err(e) = executor.run(args) {
eprintln!("Application error: {}", e);
- process::exit(1);
+ std::process::exit(1);
}
}
diff --git a/src/executor_processes/executor.rs b/src/executor_processes/executor.rs
new file mode 100644
index 0000000..dab6f21
--- /dev/null
+++ b/src/executor_processes/executor.rs
@@ -0,0 +1,115 @@
+// Copyright (C) 2024 Bellande Architecture Mechanism Research Innovation Center, Ronaldson Bellande
+
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see .
+
+use crate::executor_processes::processes::Processes;
+use crate::interpreter::interpreter::Interpreter;
+use crate::lexer::lexer::Lexer;
+use crate::parser::parser::Parser;
+use crate::utilities::utilities::ASTNode;
+use std::fs::File;
+use std::io::{self, BufRead, BufReader, Write};
+use std::sync::Arc;
+
+pub struct Executor {
+ interpreter: Interpreter,
+ processes: Arc,
+}
+
+impl Executor {
+ pub fn new() -> Self {
+ Executor {
+ interpreter: Interpreter::new(),
+ processes: Arc::new(Processes::new()),
+ }
+ }
+
+ pub fn run(&mut self, args: Vec) -> Result<(), String> {
+ if args.len() > 1 {
+ // Execute script file
+ self.execute_script(&args[1])
+ } else {
+ // Interactive mode
+ self.run_interactive_mode()
+ }
+ }
+
+ fn execute_script(&mut self, filename: &str) -> Result<(), String> {
+ let file =
+ File::open(filename).map_err(|e| format!("Error opening file {}: {}", filename, e))?;
+ let reader = BufReader::new(file);
+ for line in reader.lines() {
+ let line = line.map_err(|e| format!("Error reading line: {}", e))?;
+ self.process_content(&line)?;
+ }
+ Ok(())
+ }
+
+ fn run_interactive_mode(&mut self) -> Result<(), String> {
+ loop {
+ print!("bellos> ");
+ io::stdout().flush().unwrap();
+ let mut input = String::new();
+ io::stdin().read_line(&mut input).unwrap();
+
+ if input.trim().is_empty() {
+ continue;
+ }
+
+ if let Err(e) = self.process_content(&input) {
+ eprintln!("Error: {}", e);
+ }
+ }
+ }
+
+ fn process_content(&mut self, content: &str) -> Result<(), String> {
+ let ast_nodes = self.parse_content(content)?;
+ self.execute(ast_nodes)
+ }
+
+ fn parse_content(&self, content: &str) -> Result, String> {
+ let mut lexer = Lexer::new(content.to_string());
+ let tokens = lexer.tokenize();
+ let mut parser = Parser::new(tokens);
+ parser.parse()
+ }
+
+ pub fn execute(&mut self, nodes: Vec) -> Result<(), String> {
+ for node in nodes {
+ self.execute_node(node)?;
+ }
+ Ok(())
+ }
+
+ fn execute_node(&mut self, node: ASTNode) -> Result