Bash++: Bash with classes
Find a file
2024-10-22 21:24:41 +08:00
scripts Improving the tokenizer 2024-10-22 20:15:20 +08:00
LICENSE Licensed under GPLv3 2024-10-22 03:43:10 +00:00
main.cpp Removed comment that belongs in readme 2024-10-22 21:24:27 +08:00
makefile Bash++ is a much better name than Object Bash 2024-10-22 11:35:18 +08:00
README.md Updated readme 2024-10-22 21:24:41 +08:00
token.cpp Improving the tokenizer 2024-10-22 20:15:20 +08:00
token.h Improving the tokenizer 2024-10-22 20:15:20 +08:00
tokenizer.cpp Improving the tokenizer 2024-10-22 20:15:20 +08:00
tokenizer.h Improving the tokenizer 2024-10-22 20:15:20 +08:00

Bash++

Bash with classes

The Basic Idea

A Bash++ script will be read first by the Bash++ interpreter.

The interpreter parses the script, identifies the objects and their methods

At the end, the interpreter will generate an ordinary Bash script, and the generated script will be passed to Bash proper for execution

This is intended to be a source-to-source compiler.

Syntax

  • The Bash++ syntax will be a superset of the Bash syntax

  • The syntax will be designed to be easily converted to ordinary Bash script

Here is the basic syntax for class definition:

@class ClassName {

	@property [public|private|protected] propertyName

	@constructor [parameters] {
		constructor body
	}

	@method [public|private|protected] methodName {
		method body
	}
}

Here is the basic syntax for object creation:

@object objectName = new ClassName

Here is the basic syntax for method invocation:

@objectName.methodName

Here is the basic syntax for property access:

@objectName.propertyName

Here is the basic syntax for method invocation with parameters:

@objectName.methodName parameter1 parameter2 parameter3

Here is the basic syntax for property assignment:

@objectName.propertyName = value

Here is the basic syntax for property access with assignment:

value = @objectName.propertyName

Here is the basic syntax for method invocation with parameters and assignment:

value = @objectName.methodName parameter1 parameter2 parameter3

With all of this, we can write Bash scripts like the following:

if [[ @objectName.methodName parameter1 parameter2 parameter3 -eq 0 ]]; then
	echo "The method returned 0"
elif [[ @objectName.propertyName == "value" ]]; then
	echo "The property value is: @objectName.propertyName"
fi