"Why programmers like cooking: you peel the carrot, you chop the carrot, and you put the carrot in the stew. You don’t suddenly find out that your peeler is several versions behind and they dropped support for carrots in 4.3." —Randall Koutnik

Screenshot-2024-04-25-at-1-25-01-PM-removebg-preview-1-6

🎉 Welcome to COOK v1.0:

⚡ A statically-typed & selectively-interpreted esoteric DSL...

💪 ...with a forgiving English syntax and built-in standard library!

⭐ Drop me a star if you find this cool, it's like caffeine for my motivation.

 

Overview

Novice coders are often told that coding is like cooking, and programs themselves are often compared to recipes. Inspired by this analogy, COOK (Compiler for Object-Oriented Keys) is an esoteric programming language that blends the art of cooking with the precision of code. Built on top of Java, the language balances pointed functionality with a plain-English syntax, making it intuitive to both beginners and seasoned programmers (pun intended). And, through the selective tokenization of compiler-defined keys, programs written in COOK are even crafted to resemble the recipes in a cookbook.

Grab your favorite spatula, and let's get started!

 

Setup and I/O

If you have git installed, you can just clone the repository to your Desktop:

git clone https://github.com/ishaan-awasthi/COOK

Create a new Java project in your preferred IDE. I'm partial to IntelliJ IDEA for Java, which automatically creates all the directories for the JDK. Whichever IDE you prefer, copy the Java class files from your clone to the /src/ subdirectory in your created project.

COOK programs are written line-by-line in .txt files. After cloning the repository, you'll need to edit the following line in the Main.java class to reference your COOK program:

Scanner scanner = new Scanner(new File(new File("").getAbsolutePath()+"/src/sample.txt"));

The standard stream for both output and error handling (as well as runtime user input; see the section on COOK's Standard Library) is the process terminal of your IDE. After writing your code, you'll execute it via Main.java in your IDE itself.

 

Syntax Rules (or the lack thereof)

Keys

COOK utilizes a variety of keys in the lexer, such as top-level process keys that signal the general intention behind a line of code, second-level argument keys to modify the behavior of the top-level process, and reference keys that point to important tokens such as variable names and their values. These keys (and any parameters pointed to by a reference key) are the only parts of the code that are tokenized.

As such, COOK is an example of a forgiving language. You have complete freedom when it comes to adding filler text, punctuation, capitalization, putting the top-level process keys anywhere in the line, or even putting integer values in the middle of a word (see Declaration for an example). Furthermore, any line of code that does not contain one of the top-level keys will by default be considered a comment in its entireity and will be ignored by the compiler.

Reference Keys

Reference keys are the most important and the most simple part of coding in COOK. Since you have the ability to determine the majority of the syntax, COOK uses reference keys to filter out important tokens such as target variable names and assigned values. Before accessing a variable by its name, or using a plain integer for certain operations, you will need to precede it by the appropriate reference. Most of the time you'll use the article the, with a few exceptions. Similar to a reference key, when using a plain string (like printing hello world), you will need to encase it in quotation marks like a lot of other languages.

You still have complete freedom over how you want to write your code — just make sure all the required parameters/tokens are included and referenced in the correct order (since x-y != y-x).

 

Variable Declaration

COOK supports two variable types: integers and strings. As with all processes in COOK, you will need to signal to the compiler that you intend to declare a variable using a key: measure for integers and prepare for strings. if you choose not to initialize an integer variable with a value, it will default to 0 in order to avoid any null exceptions. Variable declarations are one of the few exceptions to the reference rule, using the reference key of.

The stripped-down syntax for both declarations is as follows:

Measure 5 cups of int-name
Prepare a bowl of "string-value" brand string-name

As mentioned earlier, COOK's forgiving syntax allows you to write code whichever way you'd like, as long as variables are accessed in order. For example, all of the following lines of code are valid and equivalent:

of int-name 5 pinches measure
Thou shalt take 5, goblets of int-name. And measure it.
It's beginning to look a lot like Ch5istmas, so pour a glass of int-name!!! and deck the halls with boughs of holly (and don't forget to measure!)

Not really cooking-themed that time, but hopefully you get the idea. (Psst... check out the included sample.txt code for an example of COOK's intended style!)

Also note that while (almost) any syntax works, for the rest of this documentation I'll only be including simplified/contexual versions to ensure that the required parameters for each aspect of the functionality are clear.

 

Computation

COOK has built-in functionality for basic arithmetic. You can perform on operations on two variables together, or one variable and then one integer. The keys and references for each operation differs slightly; the semi-stripped syntax is as listed below:

Addition

The key for addition is mix, and the reference key is in the for the variable you will be populating and the for the other two.

In the bowl, mix the chicken and the rice.
In the bowl, mix the var1 and the 123.

The first line will perform the computation bowl = chicken + rice. Again, note how you can either add two variables, or add one variable and then one integer. This applies to all of the operations listed in this section.

Subtraction

The key for subtraction is reduce, and the reference key is in the for the variable you will be populating and the for the other two.

In the pot, reduce the chicken-stock from the soup.

For subtraction/division/modulo, make sure to reference the variables in the correct order to perform the intended computation.

Multiplication

The key for multiplication is fold, and the reference key is in the for the variable you will be populating and the for the other two.

In the plate, fold the dough into the 4 number of layers.

Here we are multiplying by an integer. This always needs to come second and still needs a reference!

Division

The key for divison is divide, and the reference key is in the for the variable you will be populating and the for the other two.

In the tray, divide the cheese into the people number of portions.

Modulo

With modulo, excess serves both as the operation key and the reference key for the first variable. Use in the for the variable to be populated and the for the second variable/integer.

In the tray, save the excess cheese after dividing into the people number of portions.

Note the similarity in syntax to divison.

 

Conditionals

Intuitively, the if keyword signals a conditional in COOK. These operate over two lines of code, with the first being the condition and the second being the considered action. You will need to use the the reference key here. COOK has built-in functionality to compare the sizes of integers, as well as the equality of strings:

If the chicken is more than the rice,
in the bowl, mix the chicken and the rice.

If the string1 is the same brand as the string2,
in the bowl, mix the chicken and the rice.

For integers, you can use is more than, is less than, is equal to, and more (check the section on COOK's Standard Library).

 

Loops

COOK has functionality for reverse while loops, signaled by the until key. These also operate over two lines of code, with the first being the loop operator and the second being the considered action. You will again use the the reference key here. Loops have the same built-in checks for integers as conditionals:

Until the bowl is equal to the rice,
in the bowl, mix the rice and the 1.

Once again, check the section on COOK's Standard Library for additional loop argument options!

 

(Very Limited) Standard Library

Finally, COOK has a built-in Standard Library with a limited implementation of useful functions, arguments, and capabilities.

"Serve" Key: Output

Likely to be your most used of the built-in functions, serve is the key serving as COOK's equivalent to Python's print or Java's System.out (which COOK by nature utilizes). You can use it to display variables and standalone strings to the standard output stream (your IDE's process terminal). Usage is as follows:

Serve the "potatoes".
Serve the potatoes.

Note the distinction between the two lines: the former simply outputs the string "potatoes" to the terminal, while the latter accesses some previously declared variable potatoes, either an integer or string, and returns the associated value to print. Both usages still require a reference key!

"Find" Key: Runtime User Input

While the program is compiling, you can prompt for user input through the terminal using the find key. There are separate implementations for integers and for strings:

Find how much of the intvariable you have.
Find what brand of the stringvariable you have.

In both cases, the compiler will pause execution until the user inputs a valid input.

"Is Gone" Argument: Conditionals/Loops

In addition to the variable-variable comparisons utilized by COOK's conditionals and loops, an additional argument is gone is defined. This built-in condition checks whether the referenced integer variable is equal to zero, allowing for a more elegant syntax in specific cases. See the included sample.txt COOK program for an example of this operator in action.

Alternative Filetypes

While the standard input for COOK is .txt files, certain other filetypes may also work. Alternative filetypes range from .md, to .csv, all the way to even .py; if it can be accessed and read as plain text, it should theoretically be compatible with COOK. However, depending on your JDK version, .java files themselves may fail as the util.Scanner module processes them differently and will expect some kind of class declaration in the header.

 

Closing Thoughts

I've always believed that cooking and coding, though seemingly distinct, share a remarkable overlap in terms of originality, precision, and the beauty of creation. By creating this esoteric fusion of those two worlds, I hope to offer a unique playground for programmers of all levels. Whether you're just learning the basics or have been coding for years, I invite you to to explore this world where scripts and recipes are synonymous, and where the syntax you choose to use is just as flexible as your inner chef's palate.

As you delve into COOK, remember that its purpose isn't just functionality; it's about the journey of discovery, the joy of experimentation, and the satisfaction of crafting something uniquely your own. So, grab that favorite spatula, fire up your IDE, and let's embark on a culinary adventure through code!

Bon appétit, and happy coding!

— Ishaan Awasthi

COOK example