Learn to Code via Tutorials on Repl.it

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

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

Share Page is here

CCL - A language by Geocube101

This tutorial will cover the basic variable types of the language, how to comment, and the different commands.

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


CCL Arrays


 

Creating Arrays

Arrays can be created like any other variable using the "create" command.
An example of creating an array

create array : [1, 2, 3, 4, 5] >> array_1

The above example will create an array containing the integers 1 to 5.
Array elements don't have to be all one variable type, so it is possible to mix an integer and a character or string.

 


 

Adding Elements to Arrays

So how might one add an element to the end of an array?
You could use the "add()" method, or "@next" in combination with the "create" command.

create entry : "value" >> "target" "index/operator"

The value is the value of the element to add, the target is the array to add it to, and the index/operator is the index position to put the element in. Unlike the "add()" method, the index position can be outside of the array.
If you have an array with the value "[1, 2, 3, 4, 5]" and want to add "10" to the 9th index in the array, you can just do:

create entry : 10 >> "array_name" 9

and it will fill the array with "unset" and place 10 at the 9th position.

The new array would then be:

"[1, 2, 3, 4, 5, unset, unset, unset, unset, 10]"

 


 

Relative Operators

These operators can also be used in the "index" spot in the "create entry" command, and tell the array where to add the item.

Operators:

  • @next: Adds the value to the end of the array
  • @previous: Sets the second to last item in the array
  • @last: Sets the last item in the array
  • @first: Sets the first item in the array

So if you have an array called array_1 "[1, 2, 3, 4]" and wanted to add "5" to the end...

create entry : 5 >> array_1 @next

 


 

CCL Hashes


 

Creating Hashes

Hashes can be created like any other variable using the "create" command.
An example of creating a hash

create hash : {1: 2, 3: 4, '5': "six"} >> hash_1

The above example will create a hash.
Hash elements (like arrays) don't have to be all one variable type, so it is possible to mix an integer and a character or string.

 


 

Adding Elements to Hashes

Adding elements to a hash can only be done with the "create" command by creating an entry.

create entry : "value" >> "target" "index/operator"

The value is the value of the element to add, the target is the array to add it to, and the index/operator is the key to put the element in.
If you have a hash with the value "{1:2, 3:4}" and want to add "6" to a key/value pair with the key "5", you can just do:

create entry : 6 >> "hash_name" 5

The new hash would then be:

"{1:2, 3:4, 5:6}"

 


 

CCL Errors


 

Throwing Errors

So this entire file is on nothing but throwing errors and the types of errors.
Even though it's not listed in the normal variables (in main.md), there is a variable type called "Error". This is a reference to the Error class which will contain an error and raise it when thrown. It was mentioned previously (in commands.md during the "getting and printing variables" section) that the compiler has built-in constant variables. The one mentioned there was "console", but there is one other. It's called "tracer" and when given an error with the "get" command, will throw that error.

//Creating an error
create Error : "error string" >> "name"

//Throwing an error
get Error : "name" >> tracer
//OR
get new Error : "error string" >> tracer

These are both ways to throw an error. If you do create an error and send it the console, it will just print the error string.
Note: the tracer only accepts "Error" variables

 


 

Types of Errors

These are a list of errors and reasons they are thrown:

  • NameError: Thrown when the specified variable does not exist
  • TypeError: Thrown when the given variable's type does not match
  • VADError: Short for "Variable Already Defined/Declared Error", it's thrown when a variable name is already taken when attempting to create a new variable
  • ConversionError: Thrown when a variable conversion failes
  • SyntaxError: Thrown when CCL syntax is incorrect
  • ParamError: Thrown when function params are not supplied or incorrect
  • ParseError: Thrown when the compiler failes
  • RestrictedCallError: Thrown when a reserved keyword, variable, function, or class is used
  • TagError: Thrown when NBT parsing failed
  • SpecificationLockError: Thrown when there are duplicate items (i.e. two variables with the same name)
  • ImportError: Thrown when an import has failed
  • EOLError: Short for "End of Line Error", it's thrown when a line ended without closing (i.e. forgeting to end a string or array)
  • EOFError: Short for "End of Function Error", it's thrown when a function failed to terminate (Not currently used)
  • OverrideError: Thrown when the user (or the "sigterm" function forcefully terminates the program
  • ConstVarError: Short for "Constant Variable Error", it's thrown when an attempt is made to modify a static variable
  • NullPointerError: Thrown when a pointer references a "null" value (reference to a variable that no longer exists)
  • StaticPointerError: Thrown when a fixed value is supplied when creating a pointer variable
  • IndexOutOfBoundsError: Thrown when the specified index is not within the array's bounds
  • KeyOutOfBoundsError: Thrown when the specified key is not within the hash's bounds
  • FileError: The "FileError" super class
  • FileOpenError: Thrown when an issue prevents the program from opening the file
  • OSError: The "OSError" super class
  • AccessError: Thrown when access to a file has been denied
  • MemoryOverflowError: Thrown when the program allocated memory has been exceeded
  • CallError: The "CallError" super class
  • RuntimeError: Thrown when the program failes during runtime