Manthan

Introducing CricLang 🏏

· Manthan Gupta

logo

CricLang is a fun programming language created for cricket enthusiasts. If you look at the initial commit on the repository, it will show it as June 9, 2023, but the idea of building my programming language has been lingering at the back of my head since my college days. Finally, after procrastinating on building CricLang, I started working on it on Feb 17, 2024, and it is now ready for public beta release.

Why the name CricLang?

CricLang is an amalgamation of ‘Cricket’ and ‘GoLang’ as it is built on top of Go. It represents my love for cricket, software engineering, and the idea that code should be as simple and readable as the game. It is an evolving programming language and isn’t perfect by any means.

Documentation

CricLang is a dynamically typed language written in Go

Data Types

CricLang currently supports 4 types of data types int, string, boolean, and array as of now. Boolean values are denoted by notout and out.

>>> 1                   # int
>>> -10                 # int
>>> "Hello World!"      # string
>>> notout              # boolean true
>>> out                 # boolean false
>>> [1, "Hello World!"] # array

Declaring Variables

Variables are declared using the reserved keyword player.


>>> player x = 5;                       # integer variable
>>> player y = "Hello World!";          # string variable
>>> player z = notout;                  # boolean variable
>>> player a = [-5, "Hello World!", z];  # array of variables

Conditionals

CricLang supports if-else statements. If condition is declared using the appeal reserved keyword and else is declared using the appealrejected reserved keyword.


>>> appeal(5 < 10) { "if condition" } appealrejected { "else condition" };
>>> appeal(notout) { "true" };
>>> appeal(!notout) { "if condition" } appealrejected { "else condition" };

Return Statements

Return statements are declared using the keyword signaldecision.


>>> signaldecision 10;
>>> appeal(5 < 10) { signaldecision "if condition"; } appealrejected { signaldecision "else condition"; };

Functions

Functions can be declared using the reserved keyword field. Functions are also binded to variables in CricLang.


>>> player x = -5;
>>> player y = 25;
>>> player z = field(x, y){ appeal(x * x == y){ signaldecision "yes"; } appealrejected {signaldecision "no";}; };
>>> z(x, y);            # output: yes

Operators

CricLang supports arithmetic operators (+, -, *, /), logical operator (!), and comparison operators (==, <, >, !=) out of the box.


>>> 1 + 1                       # output: 2
>>> "Hello" + " " + "World!"    # output: "Hello World!"
>>> 1 - 1                       # output: 0
>>> 5 * -5                      # output: 25
>>> 5 / 5                       # output : 1
>>> notout == out               # output: false
>>> !out                        # output: true

Built-in Functions

CricLang is incomplete without its built-in functions which are meme references. Only the OG cricket fans can spot the references to the error messages. Here is a list of all the built-in functions

Thala

Thala is inspired by the meme “Thala for a reason”. It takes a string or an array as input and returns the length of the string or array but with a twist.

>>> thala()                             # 0 params
MISFIELD: girlfriend se raat mei baat kar lena, pehle 0 ki jagah 1 argument daal de

>>> thala(1)                            # wrong type of param
MISFIELD: girlfriend se raat mei baat kar lena, pehle sahi type ka argument toh daal de

>>> thala("Hello World")                # string as a parameter
Captain Cool: 11

>> thala("Is this sixteen?")            # string a parameter
Thala for a reason: 16

Gambhir

Gambhir is inspired by the famous meme where he says some 3rd option when given two options. It takes two parameters and returns something random.


>>> gambhir()                   # no arguments passed
MISFIELD: *Gautam Gambhir Stares Angrily* got=0 arguments, want=2 arguments

>> gambhir("virat", "sachin")   # 2 arguments passed
Interviewer: virat or sachin
Gautam Gambhir: baingan

Kohli

Kohli is inspired by one of his famous stump mic recordings. It takes [0, n] arguments and returns a fatal error with an error message.


>>> kohli()                     # no arguments passed
shaam tak khelenge, inki G phatt jaayegi lekin abhi tera code phatt gaya
exit status 1

>> kohli("wrong data type")     # with an error message
shaam tak khelenge, inki G phatt jaayegi lekin abhi tera code phatt gaya wrong data type
exit status 1

Rohit

Rohit is inspired by one of his after-match interviews in 2019. It takes one string argument and returns the output.


>>> rohit()             # no arguments passed
MISFIELD: mera gale ka vaat lag gaya chilla chilla ke ki 1 argument chahiye! tunne 0 de diye

>>> rohit(42)           # argument with wrong data type
MISFIELD: mera gale ka vaat lag gaya chilla chilla ke ki sahi type ka argument daal de

>>> rohit("Manthan")    # 1 string argument
Reporter: Manthan ke birthday ke baare mei kuch boliye.
Rohit: Abhi birthday mei kya bola jata hai? Happy Birthday? Yahi bola jata hai.

I will keep adding more fun built-in functions to CricLang and improve it overall. If you think you have some great ideas for adding a built-in function or improving CricLang, don’t shy away from sending a PR.

Parting Words

CricLang is my attempt at building a programming language, and it’s by no means a complete language. It has its share of flaws, and they will be improved upon over the period of time. If you love CricLang, then don’t forget to share it on Twitter, LinkedIn, and Peerlist. Drop a star to CricLang on GitHub.

Note for Folks who are Hiring

If you are hiring for software engineers, then I am actively looking out. I am looking for companies that are working either in the field of distributed systems, databases, cloud computing, audio/ video infrastructure, OTT platforms, fintech, or AI. If your team is pushing boundaries and working on something truly unique, I’d love to hear from you too. Reach out to me on guptaamanthan01@gmail.com or Twitter or LinkedIn.

                        Made with love for 🏏 in 🇮🇳