AssembleProgramming / AssembleScript

AssembleScript is a programming language designed for avengers to write powerful scripts and fight against evil forces. This repository contains it's source code and documentation.
https://assemblescript.vercel.app/
MIT License
12 stars 5 forks source link
interpreter parser programming-language typescript

AssembleScript

AssembleScript is a programming language designed for avengers to write powerful scripts and fight against evil forces. This repository contains the source code and documentation for AssembleScript.

Supported File-Extensions

The .avenger file extension is commonly used for code written in AssembleScript.

Here is the demo file for the code written in AssembleScript. download

Setup

Download Node.js. Run this followed commands:

# Clone the Repository
git clone https://github.com/AssembleProgramming/AssembleScript.git

# Install Deno using npm: In the terminal, execute the following command to install Deno globally using npm:
sudo npm install -g deno (MAC)
sudo snap install deno (LINUX)
npm install -g deno (WINDOWS)

# Verify the installation: After the installation is complete, you can verify that Deno has been installed correctly by running the following command:
deno --version

# Run the project
deno run -A main.ts

# Format your entire code with this command
deno fmt

# Add your test code to test.txt



📚 Documentation and Usage Guide

KeyWords

The following keywords in AssembleScript have significant references to the Marvel Cinematic Universe:

Embrace the spirit of superheroes as you code in AssembleScript, harnessing the power of these keywords to build marvelous programs!

To write scripts in AssembleScript, follow the syntax described blelow. The language supports variables, operators, if-else statements, switch statements, and loops.Here are some important points to keep in mind:

🛡 Variables

Declare variables using the newAvenger keyword followed by the variable name and initial value.

Declare const using the newEternal keyword followed by the variable name and value.

Variable name must not contain any number or any other special character otherthan UNDERSCORE

---INVALID: $thanos, gor69, iamgoblintheno1, @dormamu, %hella

+++VALID: _ironman, captain_america, __moon_knight, spiderman
newAvenger a = "Strange";
newAvenger b = 3000;
newEternal PI = 3.142;
newEternal AI = "Jarvis";

🛡 Print

To Print in console use vision()

vision("Love You 3000");

🛡 Switch Statements

Use the multiverse keyword for switch statements. Check the value of a variable and execute the corresponding madness or the default block.

@@ Instead of break keyword use `endgame`@@
newAvenger name = "iron";
multiverse(name){
    madness "captain":
        endgame;
    madness "iron":
        endgame;
    default:
        endgame;
}

🛡 If-Else Statements

Use the ifWorthy keyword for conditional statements. If the condition is true, execute the code within the curly braces; otherwise, execute the code in the otherwise block.

@@ Instead of True keyword use `SHIELD`@@
@@ Instead of False keyword use `HYDRA`@@
newAvenger isTrue = SHIELD;
newAvenger isFalse = HYDRA;

ifWorthy(isTrue){
    vision("Hello World!");
}
otherwise{
    vision("Hello Thanos!");
}

🛡 Loops

AssembleScript supports for and while loops.

@@ use blank `vision()` for a newline@@
wakandaForEach(i in 10 to 20){
    vision(i);
}
vision();
wakandaForEach(i in 10 to 0 step 2){
    vision(i);
}
@@ use blank `vision()` for a newline@@
newAvenger i;
wakandaFor(i = 0; i < 20; i = i + 1){
    vision(i);
}
newAvenger i = 0;
fightUntil(i < 10){
    vision(i);
    i = i + 1;
}

🛡 Arrays

team avengers[4] = {'Captain America', 'Iron Man', 'Thor', 'Hulk'};
team avengers[4] = {"Captain America", "Iron Man", "Thor", "Hulk"};

newAvenger firstAvenger = avengers[0];
newAvenger secondAvenger = avengers[1];

vision(firstAvenger);     $ Output: 'Captain America' $
vision(secondAvenger);    $ Output: 'Iron Man' $
team male[10] = {"Captain America", "Iron Man" ,"Dr. Strange", "Hulk", "Hawkeye", "Spiderman", "Thor", "T`Challa", "Ant Man", "Moon Knight"};
team female[7] = {"Black Widow","Captain Marvel","Wanda Maximoff","She Hulk","Ms Marvel","Gamora","Nebula"};
team avenger[2] = {male, female};

vision(avengers[0][4]);  $ Output: 'Hawkeye' $
vision(avengers[1][6]);  $ Output: 'Gamora' $

🛡 Comments

In AssembleScript, you can add comments to your code to provide explanations, document your intentions, or leave notes for yourself or other developers. Marvel Cinematic Universe-inspired comments in AssembleScript add a touch of superhero flair to your code.

$ Single Line Comments $

$
Multi-line
Comments
$
$ This variable stores the hero's strength $
newAvenger power = 100;

🛡 User Defined Functions

You can create your own user-defined functions in Assemblescript with keyword assemble and snap resembling def and return keywords in other scripting languages

Example:

assemble binary_search(arr, n, key){
    newAvenger lo = 0;
    newAvenger hi = n-1;

    fightUntil(lo <= hi){
        newAvenger mid = floor(lo + (hi - lo)/2);
        ifWorthy(arr[mid] ==  key){
            snap SHIELD;
        }
        otherwise ifWorthy(arr[mid] >  key){
            hi = mid - 1;
        }
        otherwise{
            lo = mid + 1;
        }
    }
    snap HYDRA;
}
team arr_one[7] = {1,2,3,4,5,6,7};
newAvenger size_one = 7;
vision(binary_search(arr_one, size_one, 4)) #Output: true

🛡 General Information

@@ {number} {string} {null} {boolean} @@

🛡 Built-In Methods

typeOf(varName);
vision(args);
assertWEqual(val1, val2);
time();               #To get the current time in AssembleScript
random();             #return random number between 0-1 exclusive
abs(number);          #return absolute value
floor(number);        #rounds a number down to the nearest integer.
ceil(number);         #rounds a number up to the nearest integer.
sin(angle);           #calculates the sine of an angle.
cos(angle);           #calculates the cosine of an angle.
tan(angle);           #calculates the tangent of an angle.
iSin(number);         #calculates the inverse sine of a number.
iCos(number);         #calculates the inverse sine of a number.
iTan(number);         #calculates the inverse sine of a number.
sqrt(number);         #calculates the square root of a number.
pow(a, b);            #calculates the power of a number a raised to b.
min(num1, num2);      #returns the smallest of two numbers num1 and num2.
max(num1, num2);      #returns the largest of two numbers num1 and num2.
len(string);                        #returns the length of string
charAt(string, index);              #returns the character at given index
concat(string1, string2);           #returns the string with the concatenation of given two strings
toLowerCase(string);                #returns the string in lower case
toUpperCase(string);                #returns the string in uppercase
indexOf(string, char):              #returns the index of character from string
subStr(string, startIdx, endIdx);   #returns the substring from start index to end index
trim(string);                       #removes leading

🤝 Contributing

Contributions are welcome! If you find a bug or have suggestions for improvement, please open an issue or submit a pull request.

🙏 Acknowledgements

Thanks to the creators and maintainers of TypeScript and Deno for their invaluable tools and documentation.

That's it! Start writing powerful scripts using AssembleScript and unleash your superhero potential!