Learn to Code via Tutorials on Repl.it!

← Back to all posts
Custom Language Tutorial Part 2 (Leaning CCL - A Custom Language)
Geocube101 (628)

I recently made a program that coverts a text file of custom code into python code to execute (which is the repl currently displaying)
This series of tutorials will be on how to use the language.

To test out some code, enter it into the "program.ccl" file

The idea to post this on the learn board so others can use this program was suggested by rediar

Part 3 is out here

Share Page is here

CCL - A language by Geocube101

This tutorial will cover compiler commands and loops/statements

[Note]: This information can also be found in the tutorial folder of the repl

Compiler Commands


Compiler commands allow additional features like exiting a program and changing the prompt message. All compiler commands start with a tilde "~".


Terminating a Program

For some reason, one may want to end a program early in its execution. This can be done with "~sigterm".

for (integer a << 0 : a < 10 : a++)
	get integer : a >> console
	if (a >= 5)

"~sigterm" will forcefully end the program and throw an OverrideError.

There are two modes to ~sigterm:

  • ~sigterm quiet: Remove error message thrown by "~sigterm"
  • ~sigterm normal: Default setting

By the way, it is possible to delete the "base" variable using the command below. This is another way to terminate the program from within and throws a NullPointerError

destroy object : base



Console Prompt Message

There initially was no way to change the input messgae on the console. As a result, the "~prompt" command was added.
There are three sub-commands that must be specified indicating the action:

  • disable: Hides the prompt
  • enable: Shows and resets the prompt
  • setmessage: Sets the prompt message

The "setmessage" parameter requires a string value to work and will throw an error if the value is not a string.

//Disable the prompt
~prompt disable

//Enable or reset the prompt
~prompt enable

//Change the prompt message
~prompt setmessage <message>



Setting Static Variables

There is a system implemented that prevents the modification of static variables, however there was no way to create static variables.
Two new compiler commands have fixed that.

  • lockvar: Locks a variable
  • unlockvar: Unlocks a variable

These two commands can lock and unlock any user created variable. Keep that in mind as variables like "console", "base", and "tracer" cannot be unlocked with the "~unlockvar" command. Any attempt to unlock them will throw a RestrictedCallError



CCL Statements and Loops


For the most part, all of these loops are the same as in other languages


If, else if, and else

The "if" statement will execute a block of code if the condition supplied is true.
If true then do <code>

if (condition)

The "else if" statement will execute a code block if the preceeding "if" statement's condition is not met and if it's own condition is met. Basically...
...otherwise if true then do <alt_code>

else if (condition)

If you don't have a preceeding "if" statement, the python interpreter will throw a SyntaxError
The "else" statement will execute a code block of the preceeding "if" statement and all following "else if" statements if their condition's are all false. So...
...otherwise do <alt_alt_code>





The "while" loop is a loop that repeatedly executes its code until the condition supplied is false.
while this is true do <code>

while (condition)


This can be dangerous as an incorrect condition can result in an infinite loop




The "unless" loop (An idea taken from Ruby) is the opposite of a "while" loop, repeating its code until the condition is true
unless this is true do <code>

unless (condition)

Like the "while" loop, this can be dangerous as an incorrect condition can result in an infinite loop




The "for" loop is used to either iterate over an iterable object (like an array or hash) or to count
What I'm calling "for loop ranged iteration" is the counting part of the "for" loop. It counts between two numbers, and executes the code for every time it loops.

for ("type" "name" << "initial_value" : "name" "operator" "stop" : "step")

It may seem like a lot, but it's basically like any for loop in Java or C++.

Let's say you want to count from 0 to 9 using a for loop.

for (integer count << 0 : 0 < 10 : 0++)
	get integer : count >> console

This will iterate over the integers 0 to 9 and add one to the variable "count" until count is greater than 10.
The code in the loop simply prints that variable to the console.


The second function of the for loop is to iterate over iterables.

for ("type" "name" : "iterable")

Let's say you wanted to print out every string in an array called "items".
The code to do that is:

for (string element : items)
	get string : element >> console

This will execute the code in the loop for every element in the array.




"Once" is a loop that I made up as part of this language. This is a function that will stop the program until the condition is met. Because of the way it's made, this function will do nothing useful in a single-threaded program.
Use with caution

once (condition)

So why does it not need code? The purpose of this statement is to stop the entire thread until the condition is met (by using some other global variable in another thread). In other words, it purposly locks the program, so I don't advise using it everywhere.



Try and handle

The Try/Handle statement catches and handles errors to prevent the program from crashing.




If any code in the "try" block failes, the "handle" block is executed and the program resumed.
(The error variable is not required)