CatType programming language documentation

CatType — User Guide

Version: 1.0 - Last updated 19/7/25 (dd/mm/yy)

Contents

  1. Introduction
  2. What’s New in Version 1.0
  3. Quick Start Example
  4. Language Features
  5. Commands Reference
  6. Additional Notes

  1. Introduction

CatType is a beginner-friendly scripting language specially designed for my Roblox game Programming playground .CatType supports variables, expressions, input/output, control flow, and basic data types including numbers, strings, and booleans.

Key features include:

  • Declaring variables of types: number, string, and bool
  • Assigning and re-assigning values to variables
  • Input and output commands for interaction
  • Arithmetic and string operations
  • Logical operators with short-circuit evaluation
  • Conditional statements (if, else if, else)
  • Block scopes with variable lifetime management
  • Automatic cleanup (garbage collection) of unused variables
  • Support for negative numbers and unary minus, including flipping booleans

Internally, CatType uses three main components:

  • Lexer: breaks your code into tokens
  • Parser: builds a structured syntax tree from tokens
  • Interpreter: runs the code, manages variables, and cleans up

  1. What’s New in Version 1.0

Version 1.0 introduces:

  • Release of CatType with features such as:
  • Garbage collection
  • Conditions and basic logic
  • Input and output.
  • And more.

  1. Quick Start Example

Try this example to get started with CatType:

bool flag = true
output(flag)
flag = input("Enter true or false:")
if (flag) {
    output("Flag is true")
} else {
    output("Flag is false")
}
number n = -5
output(-n + 10)  // Outputs 15
output(-true)    // Outputs false
output(-false)   // Outputs true

  1. Language Features

Comments

  • Use // for single-line comments.
    Example: // This is a comment

Variable Declaration

  • Declare variables with: =
  • Supported types: number, string, bool
  • Variable names must be unique within the same block scope — no reusing names inside the same scope.
    Example:
number age = 25
string name = "cat"
bool isReady = true

Assignment

  • Assign new values to existing variables with: =
  • The new value must match the variable’s type.
  • You cannot assign to undeclared variables.
    Example:
age = 30
name = "dog"
isReady = false

Output Statement

  • Use output(...) to print values to the console. Multiple comma-separated expressions can be outputted in one call.
    Example:
output(name)
output("Hello, ", name)
output(age + 5, " years old")

Mathematical Operations

  • Supported operators: +, -, *, /, % (modulo)
  • Use parentheses () to control order of operations.
  • Negative numbers and unary minus supported (e.g., -5, -x)
  • Unary minus on booleans flips their state (-truefalse, -falsetrue)
    Examples:
output(x + 2 * 3)
output((x + 2) * 3)
output(10 % 3)  // Outputs 1
output(-true)   // Outputs false

Logical Operators

  • Use and, or, not for boolean logic.
  • and and or perform short-circuit evaluation.
    Example:
if (x > 0 and not (x == 10 or x == 20)) {
    output("x is positive and not 10 or 20")
}

Boolean Literals

  • Use true and false as boolean values.
    Example:
bool flag = true

String Literals and Concatenation

  • Strings can be enclosed in double quotes "text", single quotes 'text', or backticks `text`.
  • Use + to join strings or concatenate with numbers (automatic conversion).
    Example:
output("cat" + 2)  // Outputs "cat2"

Identifiers (Variable Names)

  • Start with a letter or underscore _.
  • Follow with letters, digits, or underscores.

Input Statement and Expressions

  • Prompt input using input("Prompt") or just input().
  • Can be used as a statement or within variable declarations/assignments.
  • Input is converted into the variable’s type (number, string, bool).
  • If conversion fails, an error with line info is shown.
    Example:
number age = input("Enter your age:")
bool confirmed = input("true or false?")

Conditional Statements

  • Syntax supports if, elseif, and else blocks.
  • Each block introduces a new variable scope.
  • Conditions support comparison (==, !=, >,<, >=,<=) and logical operators.
    Example:
if (flag) {
    output("Flag is true")
} elseif (age > 18) {
    output("Adult user")
} else {
    output("Minor user")
}

Variable Scope and Garbage Collection

  • Each block (e.g., if, else) forms a new scope.
  • Variables are only visible inside their scope and its child scopes.
  • Variables no longer referenced in remaining code are automatically deleted after each statement.
  • Variables declared inside a block are deleted when the block ends or become unreferenced.
  • All variables and scopes are cleaned up when the program ends.

  1. Commands Reference

  • number =
    Declare a numeric variable.
    Example: number score = 100
    Example with input: number age = input("Enter age:")

  • string =
    Declare a string variable.
    Example: string pet = "cat"
    Example with input: string pet = input("Enter pet:")

  • bool =
    Declare a boolean variable.
    Example: bool flag = true
    Example with input: bool flag = input("Enter true or false:")

  • =
    Assign a new value to an existing variable.
    Example:

    score = 200
    pet = "dog"
    flag = false
    score = input("Enter new score:")
    
  • output(, , ...)
    Print one or more values to the console.
    Example:

    output(score, pet)
    output(x + 2, "cat" + 2)
    output(flag)
    
  • input("")
    Prompt the user and return input as a value.
    Example:

    input("Enter anything:")
    number n = input("Enter a number:")
    bool flag = input("Enter true or false:")
    
  • if () {...}
    Conditional execution with new variable scope.
    Example: if (flag) { output("Flag is true") }

  • elseif () {...}
    Additional conditional branch with new scope.

  • else {...}
    Final conditional branch with new scope.

  • //
    Add single-line comments to your code.


  1. Additional Notes

  • Variable names cannot be redeclared in the same scope.
  • Variables are resolved starting from the innermost scope outward.
  • The + operator works for both numbers (addition) and strings (concatenation).
  • Modulo % gives the remainder of division.
  • Input conversion respects the variable type; errors show the specific line number.
  • Logical operators are supported in all expressions and conditions.
  • Boolean variables accept only true or false values.
  • Unused variables are cleaned up automatically after each statement.
  • The entire environment is cleaned when the script finishes.
  • Unary minus works on numbers and booleans, flipping boolean values when applied.
1 Like