From 6f3e00a79204bc5eb99752a7a6033fa0eca76be8 Mon Sep 17 00:00:00 2001 From: RonaldsonBellande Date: Wed, 2 Oct 2024 15:24:39 -0400 Subject: [PATCH] latest pushes --- bellos_scripts/basic_math.bellos | 18 ++++---- src/bellos.rs | 3 +- src/executor/executor.rs | 0 src/executor/mod.rs | 1 + src/interpreter/interpreter.rs | 2 +- src/lexer/lexer.rs | 2 +- src/parser/parser.rs | 2 +- src/utilities/mod.rs | 1 + src/utilities/utilities.rs | 75 ++++++++++++++++++++++++++++++++ 9 files changed, 90 insertions(+), 14 deletions(-) create mode 100644 src/executor/executor.rs create mode 100644 src/executor/mod.rs create mode 100644 src/utilities/mod.rs create mode 100644 src/utilities/utilities.rs diff --git a/bellos_scripts/basic_math.bellos b/bellos_scripts/basic_math.bellos index 02c1db2..74adac5 100644 --- a/bellos_scripts/basic_math.bellos +++ b/bellos_scripts/basic_math.bellos @@ -1,22 +1,22 @@ #!/usr/bin/env bellos -# File: file_operations.bellos +# File: file_operations.bellos # Demonstrating file operations # Writing to a file -echo "This is a test file" > test.txt -echo "Adding another line" > test.txt +write test.txt "This is a test file" +append test.txt "Adding another line" # Reading from a file echo "Contents of test.txt:" -cat test.txt +read test.txt -# Using a while loop to read file line by line +# Using a loop to read file line by line echo "Reading file line by line:" -while read -r line +for line in $(read_lines test.txt) do - echo "Line: $line" -done < test.txt + echo "Line: ${line}" +done # Cleaning up -rm test.txt +delete test.txt diff --git a/src/bellos.rs b/src/bellos.rs index c5b945d..5d1af5f 100644 --- a/src/bellos.rs +++ b/src/bellos.rs @@ -6,9 +6,8 @@ mod utilities; use crate::interpreter::interpreter::Interpreter; use crate::lexer::lexer::Lexer; use crate::parser::parser::Parser; -use crate::utilities::Token; +use crate::utilities::utilities::Token; -use glob::glob; use std::env; use std::fs::File; use std::io::{self, BufRead, Write}; diff --git a/src/executor/executor.rs b/src/executor/executor.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/executor/mod.rs b/src/executor/mod.rs new file mode 100644 index 0000000..0c95fda --- /dev/null +++ b/src/executor/mod.rs @@ -0,0 +1 @@ +pub mod executor; diff --git a/src/interpreter/interpreter.rs b/src/interpreter/interpreter.rs index 70036e4..bb26122 100644 --- a/src/interpreter/interpreter.rs +++ b/src/interpreter/interpreter.rs @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::utilities::ASTNode; +use crate::utilities::utilities::ASTNode; use glob::glob; use std::collections::HashMap; diff --git a/src/lexer/lexer.rs b/src/lexer/lexer.rs index 03456d8..9988811 100644 --- a/src/lexer/lexer.rs +++ b/src/lexer/lexer.rs @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::utilities::Token; +use crate::utilities::utilities::Token; pub struct Lexer { input: Vec, diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 101d4be..a639a3e 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -13,7 +13,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::utilities::{ASTNode, Token}; +use crate::utilities::utilities::{ASTNode, Token}; pub struct Parser { tokens: Vec, diff --git a/src/utilities/mod.rs b/src/utilities/mod.rs new file mode 100644 index 0000000..89db166 --- /dev/null +++ b/src/utilities/mod.rs @@ -0,0 +1 @@ +pub mod utilities; diff --git a/src/utilities/utilities.rs b/src/utilities/utilities.rs new file mode 100644 index 0000000..b30f283 --- /dev/null +++ b/src/utilities/utilities.rs @@ -0,0 +1,75 @@ +// 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 . + +#[derive(Debug, Clone, PartialEq)] +pub enum Token { + Word(String), + Assignment, + Pipe, + Redirect(String), + LeftParen, + RightParen, + Semicolon, + NewLine, + If, + Then, + Else, + Fi, + While, + Do, + Done, + For, + In, + Function, + Ampersand, +} + +#[derive(Debug, Clone)] +pub enum ASTNode { + Command { + name: String, + args: Vec, + }, + Assignment { + name: String, + value: String, + }, + Pipeline(Vec), + Redirect { + node: Box, + direction: String, + target: String, + }, + Block(Vec), + If { + condition: Box, + then_block: Box, + else_block: Option>, + }, + While { + condition: Box, + block: Box, + }, + For { + var: String, + list: Vec, + block: Box, + }, + Function { + name: String, + body: Box, + }, + Background(Box), +}