Home

Awesome

Bleach

Intro

What is Bleach?

Who is the target audience of this project?

Why use Bleach?

Examples of simple yet useful programs written in Bleach

  1. Hello, World!
function greet(){
  print "Hello, World!"; // "Hello, World!"
  std::io::print("Hello, World!"); // "Hello, World!"
}

greet();
  1. Factorial
function factorial(n){
  if(n == 0){
    return 1;
  }

  return n * factorial(n - 1);
}

std::io::print(factorial(5)); // 120
  1. Fibonacci
function fibonacci(n) {
  if(n <= 0){
    return 0;
  }elif(n == 1){
    return 1;
  }else{
    return fibonacci(n - 1) + fibonacci(n - 2);
  }
}

let n = 10;
let result = fibonacci(n);
std::io::print("The", n, "th Fibonacci number is:", result);
  1. Basic Arithmetic Operations
let a = 5;
let b = 6;

let sum = a + b;
let difference = a - b;
let product = a * b;
let quotient = a / b;
let remainder = a % b;

std::io::print("Sum:", sum); // 11
std::io::print("Difference:", difference); // -1
std::io::print("Product:", product); // 30
std::io::print("Quotient:", quotient); // 0.833333333333333
std::io::print("Remainder:", remainder); // 5
  1. Logical Control Flow
let number = 42;

if(number > 0){
  std::io::print("Positive Number."); // "Positive Number."
}elif(number < 0){
  std::io::print("Negative Number.");
}else{
  std::io::print("Zero.");
}
  1. Loop Control Flow I
let count = 5;

while(count > 0){
    std::io::print("Countdown:", count);
    count = count - 1;
}
std::io::print("BOOM!"); // "BOOM!"
  1. Loop Control Flow II
let counter = 1;

do{
  std::io::print("Counter is:", counter);
  counter = counter + 1;
}while(count <= 5);
  1. Loop Control Flow III
for(let i = 1; i <= 5; i = i + 1){
    std::io::print("Current Iteration:", i);
}

std::io::print("For loop execution has ended!");
  1. Get User Input
std::io::print("Enter your name:");

let name = std::io::readLine();

let greeting = "Hello, " + name + "!";

std::io::print(greeting);
  1. String Manipulation
let first_name = "John";
let last_name = "Doe";

let full_name = first_name + " " + last_name;
std::io::print("The full name of the person is:", full_name);
  1. Class, Inheritance and Instances Usage
// Base class
class Shape {
  method init(name){
    self.name = name;
  }

  method area(){
    // To be overridden by subclasses
    return 0;
  }

  method describe() {
    return "This is a " + self.name;
  }
}

// Derived class: Circle
class Circle inherits Shape {
  method init(radius){
    // Call the base class constructor
    super.init("Circle");
    self.radius = radius;
  }

  method area(){
    return std::math::pow(self.radius, 2) * 3.14159;
  }
}

// Derived class: Rectangle
class Rectangle inherits Shape {
  method init(width, height){
    // Call the base class constructor
    super.init("Rectangle");
    self.width = width;
    self.height = height;
  }

  method area(){
    return self.width * self.height;
  }
}

// Derived class: Triangle
class Triangle inherits Shape {
  method init(base, height) {
    // Call the base class constructor
    super.init("Triangle");
    self.base = base;
    self.height = height;
  }

  method area(){
    return (self.base * self.height) / 2;
  }
}

// Create instances of each shape
let circle = Circle(5);
let rectangle = Rectangle(4, 6);
let triangle = Triangle(3, 7);

// Print descriptions and areas.
std::io::print(circle.describe(), "with area:", circle.area());
std::io::print(rectangle.describe(), "with area:", rectangle.area());
std::io::print(triangle.describe(), "with area:", triangle.area());

Bleach Language Documentation

Bleach Language Syntax Highlight Visual Studio Code Extension

How to build the Bleach Tree-Walk Interpreter?

  1. Clone this repository in your local machine.
  2. Go to the Bleach root directory. Then, execute the following commands inside it at the console/terminal:
cd scripts
chmod +x bleach_build.sh
  1. Execute the script that builds the Bleach Tree-Walk Interpreter:
./bleach_build.sh

How to run the Bleach Tree-Walk Interpreter?

  1. Execute the script that starts up the Bleach Tree-Walk Interpreter:
./bleach_run.sh # Executes the interpreter in the interactive mode (REPL mode).
./bleach_run.sh absolute_or_relative_path_to_a_bch_file # Executes the interpreter with the code written inside a Bleach file (".bch" extension).

How to clean the built Bleach Tree-Walk Interpreter?

  1. Go to the Bleach root directory. Then, execute the following commands inside it at the console/terminal:
cd scripts
chmod +x bleach_clean.sh
  1. Execute the script that cleans the build of the Bleach Tree-Walk Interpreter (if any is present):
./bleach_clean.sh

How to run the unit tests of the Bleach Tree-Walk Interpreter?

  1. Go to the Bleach root directory. Then, execute the following commands inside it at the console/terminal:
cd scripts
chmod +x bleach_test_pipeline.sh
  1. Execute the script that run all of the unit tests related to the Bleach Tree-Walk Interpreter:
./bleach_test_pipeline.sh

The undergraduate thesis

Current State of the Bleach Language Context-Free Grammar

program → statement* EOF
statement → block | breakStmt | classDeclStmt | continueStmt | doWhileStmt | exprStmt | forStmt | funcDeclStmt | ifStmt | printStmt | returnStmt | varDeclStmt | whileStmt
block → "{" statement* "}"
breakStmt → "break" ";"
classDeclStmt → "class" IDENTIFIER ( "inherits" IDENTIFIER )? "{" methodDeclStmt* "}"
methodDeclStmt → "method" method
method → IDENTIFIER "(" parameters? ")" block
continueStmt → "continue" ";"
doWhileStmt → "do" block "while" "(" expression ")" ";"
exprStmt → expression ";"
forStmt → "for" "(" ( varDecl | exprStmt | ";" ) expression? ";" expression? ")" block
funcDeclStmt → "function" function
function → IDENTIFIER "(" parameters? ")" block
parameters → IDENTIFIER ( "," IDENTIFIER )*
ifStmt → "if" "(" expression ")" statement
         ( "elif" "(" expression ")" statement )*
         ( "else" statement )?
printStmt → "print" expression ";"
returnStmt → "return" expression? ";"
varDeclStmt → "let" IDENTIFIER ( "=" expression )? ";"
whileStmt → "while" "(" expression ")" block
expression → assignment
assignment → ( call "." )? IDENTIFIER "=" assignment | ternary
ternary → logic_or ( "?" expression ":" expression )*
logic_or → logic_and ( "or" logic_and )*
logic_and → equality ( "and" equality )*
equality → comparison ( ( "!=" | "==" ) comparison )*
comparison → term ( ( ">" | ">=" | "<" | "<=" ) term )*
term → factor ( ( "-" | "+" ) factor )*
factor → unary ( ( "/" | "*" | "%" ) unary )*
unary → ( "!" | "-" ) unary | call
call → primary ( "(" arguments? ")" | "." IDENTIFIER )*
arguments → expression ( "," expression )*
primary → "true" | "false" | "nil" | NUMBER | STRING | "(" expression ")" | "[" (expression ( "," expression )*)? "]" | lambdaFunctionExpr | IDENTIFIER | "super" . IDENTIFIER
lambdaFunctionExpr → "lambda" "->" "(" parameters? ")" block

Why was Bleach written in C++?

<!-- ## LLVM Version of the Bleach Language (Not priority right now) ### Initial Setup 1. On the root folder of your machine: ```shell git clone git@github.com:llvm/llvm-project.git ``` 2. Then run the following commands: ```shell cd llvm-project mkdir build cd build ``` 3. Run the following build command: ```shell cmake ../llvm -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=~/llvm-project/build -DBUILD_SHARED_LIBS=on -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release ``` 4. Finally: ```shell make ``` --> <!-- ## Doubts * __What is the diference between using a variable and refering to a variable?__ * __Is it really okay to let a variable be re-declared in the global scope? Not convinced by the author.__ * __Differences between scopes and environments (the author says they are "close cousins"). Also, the author later mentions that scope is a concept/idea and environment is something concrete that implements such concept.__ * __What is necessary to claim that a programming language is Turing-Complete? In other words, what exactly is Turing-Completeness? According to the author, the programming language needs to have the following features implemented:__ * __Arithmetic__ * __A little control-flow (what does "little" even mean in this context?)__ * __The ability to allocate arbitrary amounts of memory__ * __What is the formal and precise definition of scope in the programming language field? The author, Bob Nystrom, says, in chapter 11, that scope is a set of declarations. Therefore, if two sets don't have the same declarations, then they are not the same scope. Is this correct?__ * When dealing with "Get" expression, the author says the following: "Since properties are looked up dynamically, they don’t get resolved". What does this mean? -->