CLRS Kitclrs-kit is a Visual Studio Code extension designed to support a pseudocode language heavily inspired by the syntax used in the book Introduction to Algorithms (CLRS). 💻 Getting started in VS Code
⚙️ Current status (version 1.0.1)
📖 Language PhilosophyThe language is designed based on the following principles:
🛠️ Requirements
🧑💻 AuthorProject developed by j-hernandez-dev as an open educational tool. 📜 License (GPLv2)This project is open source. It may be freely modified and extended, provided that attribution to the original author is maintained. ⚠️ Known issues
🧮 Language FeaturesCommentsCLRS only supports single-line comments using
VariablesVariables are dynamically and weakly typed. They can store values of different types and change their type during execution through implicit type conversions when necessary.
Variables are always mutable; the language does not support constants. Their scope is local to the function in which they are defined, and assignment is performed using the
Variables must be initialized when they are created. Standalone declarations without an initial value are not allowed. Supported value types are numeric, string, and boolean.
ArraysArrays are dynamic. Their size and number of dimensions are determined automatically as new positions are accessed.
A complete array can be assigned to a variable, and a variable can also be assigned to an array. In both cases, the corresponding values are copied.
Input and OutputThe
The
Selection StatementsThe only selection structure is
OperatorsCLRS provides logical, relational, and arithmetic operators similar to those found in most programming languages. Equality comparison uses the
|
| CLRS Function | Description | Returns |
|---|---|---|
READ_FILE(path) |
Reads the contents of a text file. | String |
FILE_EXISTS(path) |
Checks whether a file exists. | Boolean |
FILE_SIZE(path) |
Returns the size of a file in bytes. | Number |
CREATE_FILE(path) |
Creates an empty file. | - |
WRITE_FILE(path, content) |
Appends content to a file. | - |
DELETE_FILE(path) |
Deletes a file if it exists. | - |
🔢 Mathematics
| CLRS Function | Description | Returns |
|---|---|---|
ABS(x) |
Returns the absolute value of a number. | Number |
MIN(a, b) |
Returns the smaller of two values. | Number |
MAX(a, b) |
Returns the larger of two values. | Number |
ROUND(x) |
Rounds to the nearest integer. | Number |
FLOOR(x) |
Rounds down to the nearest integer. | Number |
SQRT(x) |
Returns the square root. | Number |
CBRT(x) |
Returns the cube root. | Number |
EXP(x) |
Returns e raised to the power of x. | Number |
LOG(x) |
Returns the natural logarithm. | Number |
LOG10(x) |
Returns the base-10 logarithm. | Number |
LOG2(x) |
Returns the base-2 logarithm. | Number |
SIN(x) |
Returns the sine of an angle. | Number |
COS(x) |
Returns the cosine of an angle. | Number |
TAN(x) |
Returns the tangent of an angle. | Number |
ASIN(x) |
Returns the arcsine. | Number |
ACOS(x) |
Returns the arccosine. | Number |
TO_RADIANS(x) |
Converts degrees to radians. | Number |
TO_DEGREES(x) |
Converts radians to degrees. | Number |
PI() |
Returns the constant π. | Number |
E() |
Returns the constant e. | Number |
RANDOM(min, max) |
Returns a random number within the specified range. | Number |
AVERAGE(array) |
Returns the average of an array. | Number |
SUM(array) |
Returns the sum of all elements in an array. | Number |
MEDIAN(array) |
Returns the median of a data set. | Number |
VARIANCE(array) |
Returns the variance of a data set. | Number |
🔤 Strings
| CLRS Function | Description | Returns |
|---|---|---|
LENGTH(x) |
Returns the length of a string or data structure. | Number |
CHAR_AT(string, index) |
Returns the character at the specified position. | String |
SUBSTRING(string, start, end) |
Extracts a substring. | String |
INDEX_OF(string, text) |
Returns the position of a substring. | Number |
CONTAINS(string, text) |
Checks whether a string contains another string. | Boolean |
UPPER(string) |
Converts text to uppercase. | String |
LOWER(string) |
Converts text to lowercase. | String |
TRIM(string) |
Removes leading and trailing whitespace. | String |
REPLACE(string, old, new) |
Replaces occurrences of a substring. | String |
SPLIT(string, separator) |
Splits a string into an array. | Array |
IS_NUMBER(string) |
Checks whether a string represents a number. | Boolean |
IS_EMPTY(string) |
Checks whether a string is empty. | Boolean |
STARTS_WITH(string, text) |
Checks whether a string starts with the specified text. | Boolean |
ENDS_WITH(string, text) |
Checks whether a string ends with the specified text. | Boolean |
📦 Arrays
| CLRS Function | Description | Returns |
|---|---|---|
PUSH(array, value) |
Appends an element to the end of an array. | Number |
REMOVE(array, index) |
Removes an element at the specified index. | - |
INSERT(array, index, value) |
Inserts an element at the specified index. | - |
FIND_INDEX(array, value) |
Returns the index of a value. | Number |
HAS_VALUE(array, value) |
Checks whether an array contains a value. | Boolean |
SORT(array) |
Sorts the array in ascending order. | - |
REVERSE(array) |
Reverses the array. | Array |
COPY(array) |
Returns a copy of the array. | Array |
JOIN(array, separator) |
Joins the array elements into a string. | String |