MachanScript is a adipoli π programming language written in Javascript.
To start using MachanScript, follow these simple steps:
-
Installation: Install MachanScript globally using npm:
npm i -g machan-script
Note :- Assuming that you have Node.js installed, if not please install before continuing
-
Syntax Overview:
Machane!!: Every MachanScript file should start by calling Machan, or else the code will not run.ithu varName = value aanu: Used to declare variables.ithu const varName = value aanu: Used to declare constant variables.ithu b = "Hello World" aanu: Used to declare strings.ithu arr = [ 1 , 4 , 6 , 8 , 3 ] aanu: Used to declare arrays.ithu obj = { x : 100 , y : 200 , } aanu: Example of creating objects.obj . x | obj . y: Accessing object properties.// comment: Single-line comment./* comment */: Multi-line comment (New in V3.0).nirth;: Break out of loops.aavane;: Continue to next iteration.return value;: Return from your functions.
-
Examples:
-
Variable Declaration:
ithu variableName = value aanu ithu const constantName = value aanu -
Object Creation:
ithu obj1 = { x : 100 , y : 200 , } aanu ithu const obj2 = { z : 300 , v : 400 , } aanu -
Printing:
para ( "Hello World!!" ) ; para ( "Sum: " , obj1 . x + obj2 . z ) ;
-
-
Saving the file:
- Save the file with
.mcextension.
- Save the file with
MachanScript provides a variety of built-in functions to handle I/O, math, data structures, and more.
-
para ( ...args ) ;: Prints messages to the console.para("Hello", "Machan!"); -
input_eduku ( varName , prompt ) ;: Gets user input.input_eduku(name, "What is your name? "); -
orangu ( ms ) ;: Pause execution (non-blocking).orangu(1000); // 1 second sleep -
inathe_date ( includeTime? , varName? ) ;: Get current date.inathe_date(); // Prints date inathe_date(true, d); // Saves date & time to 'd'
-
vayiku ( path , varName? ) ;: Read file content.vayiku("./src.ms", data); -
ezhuthu ( path , data ) ;: Write to a file.ezhuthu("./log.txt", "Action completed");
array_push ( arr , val ) ;,array_pop ( arr ) ;array_length ( arr ) ;,array_join ( arr , sep ) ;,array_slice ( arr , start , end ) ;ithu myArr = [1, 2] aanu array_push(myArr, 3); // [1, 2, 3] ithu last = array_pop(myArr) aanu // 3 para(array_join(myArr, "-")); // "1-2"
string_length ( str ) ;,string_substring ( str , start , end ) ;string_upper ( str ) ;,string_lower ( str ) ;,string_split ( str , sep ) ;ithu msg = "Hello World" aanu para(string_upper(msg)); // "HELLO WORLD" para(string_length(msg)); // 11
sqrt(n),power(b, e),abs(n),round(n),floor(n),ceil(n)random ( min , max , varName? ) ;: Random integer.fact ( n , varName? ) ;: Factorial.para(sqrt(16)); // 4 para(random(1, 10)); // Random 1-10
object_keys(obj),object_values(obj),object_has(obj, key)ithu user = {id: 1, name: "Ali"} aanu para(object_keys(user)); // ["id", "name"]
number_ano(v),string_ano(v),array_ano(v),object_ano(v)ipo (number_ano(10)) anengi { para("It is a number"); }
MachanScript supports the following control statements:
ipo: Used for conditional execution. Followed by a condition and a block of code to execute if the condition is true.anengi: Marks the beginning of the block of code to execute if the condition in anipostatement is true.alengi: Marks the beginning of the block of code to execute if the condition in anipostatement is false.switch machane: Used for conditional execution. Different cases are declared byipovalueanengiand the default it set byonnum_alengi.machane try cheyu { ... } pidiku ( err ) { ... }: Handle errors gracefully (New in V3.0).
MachanScript supports the following loop statements:
machane: Used to create while loops. Followed by a condition and a block of code to execute repeatedly as long as the condition is true.aavaneandvare: Marks the beginning and end of the block of code to execute in amachaneloop.for machane: Used to create for loops. Followed by a condition and a block of code to execute repeatedly as long as the condition is true.enit: Marks the beginning block of code to execute in afor machaneloop.machane pani name ( args ) { ... }: Define your own functions (New in V3.0).
Machane!!
ithu x = 5 aanu
ipo ( x < 10 ) anengi {
para ( " x is less than 10 " ) ;
} alengi {
para ( "x is greater than or equal to 10" ) ;
}
Machane!!
input_eduku ( x , "Enter a number: ") ;
switch machane ( x ) {
ipo 1 anengi {
para ( " You selected 1 " ) ;
}
ipo 2 anengi {
para ( " You selected 2 " ) ;
}
onnum_alengi {
para ( "MachanScript" ) ;
}
}
Machane!!
ithu a = 1 aanu
machane ( a <= 5 ) aavane vare {
para ( a ) ;
a = a + 1
}
Machane!!
for machane ( ithu i = 0 aanu : i < 5 : i = i + 1 ) enit {
para ( i ) ;
}
Machane!!
machane pani add(a, b) {
return a + b;
}
ithu sum = add(10, 20) aanu
para(sum) ;
Machane!!
machane pani fib(n) {
ipo (n <= 1) anengi {
return n;
}
return fib(n - 1) + fib(n - 2);
}
for machane (ithu i = 0 aanu : i < 10 : i = i + 1) enit {
para("Fib(", i, ") = ", fib(i));
}
Machane!!
ithu students = [
{ name: "Rahul", marks: [80, 90, 75] },
{ name: "Anu", marks: [95, 85, 100] }
] aanu
machane pani average(marks) {
ithu sum = 0 aanu
ithu len = array_length(marks) aanu
for machane (ithu i = 0 aanu : i < len : i = i + 1) enit {
sum += marks[i]
}
return sum / len;
}
para("--- Student Report ---");
for machane (ithu s = 0 aanu : s < array_length(students) : s = s + 1) enit {
ithu student = students[s] aanu
para(student.name, " scored an average of: ", average(student.marks));
}
Machane!!
machane pani safeLoad(path) {
machane try cheyu {
para("Loading file: ", path);
vayiku(path, content) ;
return content;
} pidiku (err) {
para("β οΈ Machane pani kitti: ", err);
return null;
}
}
ithu data = safeLoad("./config.ms") aanu
ipo (data != null) anengi {
para("File content: ", data);
}
Machane!!
para("Finding the first number divisible by 7 and 3...");
ithu n = 1 aanu
machane (true) aavane vare {
ipo (n % 7 == 0 && n % 3 == 0) anengi {
para("Found it: ", n);
nirth; // Stop the infinite loop
}
n = n + 1;
aavane; // Continue to next iteration (redundant but works!)
}
Machane!!
ithu input = 16 aanu
ipo (number_ano(input)) anengi {
para("Square root of ", input, " is ", sqrt(input));
} alengi {
para("Input is not a number!");
}
para("2 raised to 10 is: ", power(2, 10));
You can run MachanScript files from the command line using the following command:
machane filename.mcThe MachanScript extension enables syntax highlighting in VSCode.
- User-defined functions with
machane panisyntax andreturnkeyword - Try-Catch error handling (
machane try cheyu ... pidiku) - Logical operators (
&&,||,!) - Comprehensive test suite covering all language features
- Huge standard library upgrade:
- Array operations:
array_push,array_pop,array_length,array_join,array_slice - String operations:
string_length,string_substring,string_upper,string_lower,string_split - Object functions:
object_keys,object_values,object_has - Type checking:
number_ano,string_ano,array_ano,object_ano - Math functions:
sqrt,power,abs,round,floor,ceil
- Array operations:
- Enhanced native function support in expressions
- Improved else-if (
alengi ipo) syntax support - Updated Malayalam keywords (
aavanefor continue) - Multi-line comments support (
/* */)
- New and improved CLI with interactive REPL
- Fully localized Malayalam error messages
- Smart Bundler/Packager for deployment
- Initial release of MachanScript.
- Basic functionality for variable declaration, object creation, and control statements.
- Machan Native Functions like
para,input_eduku,cheruthu,veluthu,inathe_date,vayiku,ezhuthu,random,fact,orangu. - Support for conditional execution with
ipo,anengi,alengi,switch machane,oonum-alengi. - Support for
whileLoops withmachane,avane,vare. - Support for
forloops withfor,enit.
MachanScript was created by GeorgeET15. You can find more about the him on GitHub, LinknedIn.
This project is licensed under the MIT License. Please provide appropriate credit to the author when using this software. Contributions are welcome!
If you use MachanScript in your project, please acknowledge the author, George Emmanuel Thomas, in your documentation or credits section.