machan-script
v3.0.0
Published
MachanScript is a lightweight programming language written in Javascript.
Downloads
12
Maintainers
Readme
MachanScript
MachanScript is a adipoli 😎 programming language written in Javascript.
✨ Getting Started ✨
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 ]
: Used to declare arrays.ithu obj = { x : 100 , y : 200 , } aanu
: Example of creating objects.obj . x | obj . y
: Accessing object properties.
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:
.ms
: Save the file with.ms
extension.
Native Functions
MachanScript provides the following native functions:
para ( message ) ;
: Prints the message to the console.input_eduku ( varName , prompt ) ;
: Prompts the user to enter a value and assigns it to the variable specified byvarName
.orangu ( milliseconds ) ;
: It will synchronously pause the execution of other operations for the specified number of milliseconds before resuming.veluthu ( arg1 , arg2...., varName ) ;
: Returns the largest. We can either pass sperate values or an array or seperate values and an array. The returned value will be stored in the last passedvarName
.cheruthu ( arg1 , arg2...., varName) ;
: Same as ofveluthu
except it returns the smallest valueinathe_date ( boolVal , varName ) ;
: Returns the date, if true it also returns the time, if we pass thevarName
the returned value will be stored in the new variable created.vayiku ( file , varName ) ;
: Prints the content in the file, if we pass thevarName
the returned content will be stored in the new variable created.ezhuthu ( file , data ) ;
: Stores the data we passed to the file. We can either directly pass a string or a variable containing a string,random ( min , max , varName ) ;
: Returns a random number between the min and max range, if we pass thevarName
the returned value will be stored in the new variable created.fact ( number , varName ) ;
: Returns the factorial of the number, if we pass thevarName
the returned value will be stored in the new variable created.
Control Statements
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 anipo
statement is true.alengi
: Marks the beginning of the block of code to execute if the condition in anipo
statement is false.switch machane
: Used for conditional execution. Different cases are declared byipo
valueanengi
and the default it set byonnum_alengi
.
Loop Statements
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.avane
andvare
: Marks the beginning and end of the block of code to execute in amachane
loop.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 machane
loop.
Examples 😉
Conditional Execution ( ipo
, anengi
, alengi
)
- Usage:
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" ) ;
}
Conditional Execution ( swicth machane
, ipo
, anengi
, onnum_alengi
)
- Usage:
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" ) ;
}
}
While Loop ( machane
, avane
, vare
)
- Usage:
Machane!!
ithu a = 1 aanu
machane ( a <= 5 ) avane vare {
para ( a ) ;
a = a + 1
}
For Loop ( for
, machane
, enit
)
- Usage:
Machane!!
for machane ( ithu i = 0 aanu : i < 5 : i = i + 1 ) enit {
para ( i ) ;
}
Machan Native Functions
input_eduku
Usage :
Machane!!
input_eduku ( w , "Enter a number, a string or an array: ") ;
para ( w ) ;
para ( w [ 2 ] ) ; //arrays
orangu
Usage :
Machane!!
ithu b = 10 aanu
ithu c = 0 aanu
machane ( c <= b ) avane vare {
para ( c ) ;
orangu ( 2000 ) ;
c = c + 1
}
cheruthu
, veluthu
Usage :
Machane!!
ithu arr = [ 3 , 5 , 6 , 9 , 7 , 101 ] aanu
cheruthu ( arr , small ) ;
para ( small ) ;
veluthu ( arr , 12 , 4 , 65 , 1 , 100 , 99 , large ) ;
para ( large ) ;
innathe_date
Usage :
Machane!!
inathe_date ( ) ;
inathe_date ( true ) ;
inathe_date ( true , y ) ;
inathe_date ( false , x ) ;
para ( "date: " , x ) ;
vayiku
Usage :
Machane!!
vayiku ( "./test1.txt" ) ;
ithu filePath = "./test1.txt" aanu
vayiku ( filePath ) ;
ezhuthu
Usage :
Machane!!
ezhuthu ( "./test1.txt", "Hello") ;
ithu y = "./test1.txt" aanu
ithu x = "Hello" aanu
ezhuthu ( y , x ) ;
random
Usage :
Machane!!
random ( 1 , 5 ) ;
random ( 1 , 5 , a ) ;
para ( a ) ;
fact
Usage :
Machane!!
fact ( 4 ) ;
fact ( 4 , a ) ;
para ( a ) ;
Running Code 🚀
You can run MachanScript files from the command line using the following command:
machane filename.ms
VSCode Extension
The MachanScript extension enables syntax highlighting in VSCode.
Version History 📝
v0.1 (June-2024)
- 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
while
Loops withmachane
,avane
,vare
. - Support for
for
loops withfor
,enit
.
Author 😁
MachanScript was created by GeorgeET15
. You can find more about the him on GitHub, LinknedIn.