Skip to content
| Marketplace
Sign in
Visual Studio Code>Language Packs>CLRS KitNew to Visual Studio Code? Get it now.
CLRS Kit

CLRS Kit

j-hernandez-dev

|
1 install
| (0) | Free
Language support and tools for the CRLS pseudolanguage.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

CLRS Kit

clrs-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

Concept Description
File extension .clrs
Run code Executes CLRS code by transpiling it to JavaScript and subsequently running it at runtime.
Build code (JS) Transpiles CLRS code to JavaScript without executing it, generating a file ready for use in Node.js.

⚙️ Current status (version 1.0.1)

  • Full CLRS parser built with Chevrotain.
  • Automatic Abstract Syntax Tree (AST) generation.
  • CLRS-to-JavaScript transpiler.
  • Execution of CLRS programs directly from Visual Studio Code.
  • JavaScript code generation without execution.
  • Syntax highlighting via a TextMate grammar.
  • Language configuration with automatic indentation and code folding.
  • Built-in snippets for CLRS syntax.
  • Standard library for handling files, strings, arrays, and mathematical functions.
  • Syntax and runtime error reporting.
  • Support for functions, arrays, expressions, conditionals, loops, and input/output operations.
  • CodeLens support for run and build buttons.

📖 Language Philosophy

The language is designed based on the following principles:

  • Simple pseudocode syntax close to english.
  • Educational and academic focus.
  • Simplicity for beginners.
  • Similarity to CLRS pseudocode.
  • Use case focused on algorithm design and learning.

🛠️ Requirements

  • Visual Studio Code
  • Node.js (for execution)

🧑‍💻 Author

Project 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

  • There is no support for semantic analysis. Consequently, everything is handled during JavaScript analysis without specifying the error location.
  • Certain code may be generated incorrectly by the transpiler.

🧮 Language Features

Comments

CLRS only supports single-line comments using //.

// Simple comment

Variables

Variables are dynamically and weakly typed. They can store values of different types and change their type during execution through implicit type conversions when necessary.

variable1 <- 10
variable2 <- "text"
variable1 <- variable2

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 <- operator.

variable1 <- 10
variable1 <- 2
variable1 <- 4

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.

variable1 <- 10
variable2 <- "text"
variable3 <- TRUE

Arrays

Arrays are dynamic. Their size and number of dimensions are determined automatically as new positions are accessed.

array[0] <- 10
matrix[2][2] <- 10

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.

variable1 <- array
matrix <- variable2

Input and Output

The print statement writes data to the console. It can print individual values, multiple values separated by commas, concatenated expressions, and entire arrays.

print variable1
print array
print variable1, variable2, variable3
print variable1 + variable2 + variable3

The scan statement reads input from the console. One or more variables can be read in a single statement. The type of the input value is determined automatically.

scan variable1
scan variable1, variable2, variable3

Selection Statements

The only selection structure is if, together with its else if and else variants. Code blocks are defined by indentation, so consistent indentation is required.

if variable3 or TRUE
    print "a"
else if variable1 > 3
    print "b"
else if variable2 = "text"
    print "c"
else
    print "d"

Operators

CLRS provides logical, relational, and arithmetic operators similar to those found in most programming languages. Equality comparison uses the = operator.

if TRUE and TRUE
    print "a"

if FALSE or TRUE
    print "b"

if 10 > 20
    print "c"

if 20 < 10
    print "d"

if 10 = 10
    print "e"

if 20 != 10
    print "f"

for Loop

The for loop supports two variants.

The to variant automatically increments the loop variable until it reaches the specified end expression.

for i <- 0 to 5
    print i

The downto variant automatically decrements the loop variable until it reaches the specified end expression.

for j <- 5 downto 0
    print j

while Loop

The while loop repeatedly executes a block of code as long as the specified condition evaluates to TRUE.

while variable3 and FALSE
    print "This code is never executed"

Functions

Functions are defined by an identifier, a parameter list, and an indented code block.

helloWorld()
    print "Hello, world!"

Function calls use the same syntax as their definitions. Be careful not to indent code immediately after a function call, as it may be interpreted as the body of a new function definition.

helloWorld()

Functions can receive any number of parameters and return a value using the return statement.

sum(a, b)
    return a + b

Functions can also receive arrays as parameters. Only the number of dimensions needs to be specified.

sum2(a, b[])
    return a + b[0]

Function calls can be used as part of any expression. Arrays are passed simply by using their identifier.

variable1 <- sum(1, 2)
print sum(1, 2)

variable1 <- sum2(1, array)
print sum2(1, array)

A function named main can be used as the program entry point. It is invoked automatically, so it does not need to be called explicitly.

main()
    print "Hello, world!"

main() // Not required; this would execute it twice.

Example

Complete Bubble Sort implementation.

array[0] <- 5
array[1] <- 2
array[2] <- 9
array[3] <- 1
array[4] <- 6

n <- LENGTH(array)

print n

i <- 0
j <- 0

for i <- 0 to n - 1
    for j <- 0 to n - i - 2
        if array[j] > array[j + 1]
            temp <- array[j]
            array[j] <- array[j + 1]
            array[j + 1] <- temp

print array

📚 CLRS Standard Library

The CLRS Standard Library provides built-in functions for file handling, mathematical operations, strings, and arrays.


📁 Files

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
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft