https://github.com/neuodev/mybash
A very minimalistic programming language built with Rust
https://github.com/neuodev/mybash
Last synced: 5 months ago
JSON representation
A very minimalistic programming language built with Rust
- Host: GitHub
- URL: https://github.com/neuodev/mybash
- Owner: neuodev
- Created: 2022-09-09T07:41:19.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-27T18:08:29.000Z (almost 4 years ago)
- Last Synced: 2025-03-20T02:48:49.252Z (over 1 year ago)
- Language: Rust
- Size: 97.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MyBash
A very minimalistic programming language built with Rust
## Example
```bash
# mybash ./foo.mb bar baz
# This is a comment
# If statments and exper evaluation
if $1 = "bar"
do echo "I got bar"
else
do echo "I got baz"
endif
# Variables
name: str = "Jone"
age: int = 31
is_awesome: bool = true
math_expr = 12 / 2 + 1 # 7
echo math_expr
```
## Examples
Variable declaration with basic if statment
```bash
# mybash script.mb
age: int = 30
echo age
if age > 40
do echo "I am old"
else
do echo "I am still young"
endif
```
#### Output
```bash
30
I am still young
```
Access positional arguments and echo it to the stdout
```bash
# mybash script_5.mb me
echo $1
if $1 == 'me'
do echo "Hello, Ahmed"
else
do echo "Hi, :) ${1} ✋"
endif
```
#### Output
```bash
Ahmed
Hi, :) Ahmed ✋
```
Access evn variables (with comments)
```bash
# Echo env variables to the stdout
# example: mybash ./sript_6.mb foo bar baz
echo $PATH
echo $PWD # Current working directory
echo $0 # Should display the script name (script_6.mb)
echo $1 # Should display the first arg (foo)
echo $2 # Should display the second arg (bar)
```
Evaluate math expressions and echo it to the stdout
```bash
res: int = (12 + 12) / 4
echo "(12 + 12) / 4 ⏬"
echo res
```
#### Output
```bash
(12 + 12) / 4 ⏬
6
```
Variable expansion with echo statments
```bash
name: str = "Jone"
echo "Hello, $name 🙌"
echo "PATH = ${PATH}"
echo "HOME = $HOME"
echo "PWD = $PWD"
echo "HOSTNAME = $HOSTNAME"
echo "HOSTTYPE = $HOSTTYPE"
```
Variable concatenation
```bash
f_name: str = "Jone"
l_name: str = "doe"
full_name: str = "${f_name} ${l_name}"
echo "My full name is $full_name"
```
#### Output
```bash
My full name is Jone doe
```
Read stdin
```bash
name: string = input("What is your name? ")
age: string = input("What is your age? ")
addr: string = input("What is your address? ")
echo "My name is $name"
echo "My age is $age"
echo "I live in $addr"
```