# Tokens / Keywords
Let me introduce you to Razen's tokens and keywords - the building blocks of the language! These tokens have been designed to be intuitive and expressive, making your code more readable and maintainable.
## Core Tokens
### Comment Token:
- `#` for declaring a comment and adding notes to your code
```razen
# This is a comment in Razen
```
### Variable Declaration Tokens:
- `num` → for declaring numeric variables and calculations
- Use for **integers**, **floats**, and **mathematical** operations
```razen
num count = 42;
num pi = 3.14159;
```
- `str` → for declaring string variables and text manipulation
- Use for **text data**, **string** operations, and string interpolation
```razen
str name = "Razen";
str greeting = "Hello, " + name + "!";
```
- `bool` → for declaring boolean variables and logical conditions
- Use for **true/false/null** values and control flow
```razen
bool isActive = true;
bool hasErrors = false;
bool isEmpty = null;
```
- `var` → for declaring variables of any type
- Use when type is **unknown or mixed** types are needed
```razen
var data = getUserInput();
var result = processData(data);
```
- `const` → for declaring constants that cannot be changed
- Use for values that should remain fixed throughout execution
```razen
const API_KEY = "abc123xyz";
const MAX_ATTEMPTS = 3;
const PI = 3.14159;
const MAX_USERS = 100;
const APP_NAME = "Razen Demo";
```
### Logical Tokens:
- `if` → for conditional statements
```razen
if (score > 80) {
show "Excellent!";
} else if (score > 60) {
show "Good job!";
} else {
show "Keep practicing!";
}
```
- `else` → for alternative execution path
- `while` → for loop execution while a condition is true
```razen
num i = 0;
while (i < 5) {
show i;
i = i + 1;
}
```
- `for` → for loop execution with initialization, condition, and increment
```razen
for (num i = 0; i < 5; i = i + 1) {
show i;
}
```
- `is` → for equality comparison
```razen
if (status is "ready") {
startProcess();
}
```
- `when` → for pattern matching and case statements
- Use for multiple condition checks
```razen
when (dayOfWeek) {
"Monday": show "Start of week";
"Friday": show "End of week";
_: show "Middle of week";
}
```
- `not` → for logical negation
- Use to invert boolean values
```razen
if (not isEmpty) {
processData();
}
```
### Collection Tokens:
- `list` → for dynamic arrays and lists
- Use for storing multiple values of any type
```razen
list fruits = ["apple", "banana", "orange"];
```
- `arr` → for fixed-size arrays
- Use when array size is known and constant
```razen
arr<num> temperatures = [72, 68, 75, 79, 71];
```
- `append` → for adding elements to lists
- Use for list growth and element addition
```razen
append(fruits, "mango");
```
- `remove` → for removing elements from lists
- Use for list cleanup and element deletion
```razen
remove(fruits, "banana");
```
### Dictionary/Map Tokens:
- `map` → for key-value storage
- Use for storing related data with unique keys
```razen
map userProfile = {
"name": "Alex",
"age": 28,
"isActive": true
};
```
- `key` → for accessing dictionary keys
- Use for key iteration and key-based operations
```razen
for (key in userProfile) {
show key + ": " + userProfile[key];
}
```
- `value` → for accessing dictionary values
- Use for value iteration and value-based operations
```razen
for (value in userProfile) {
processValue(value);
}
```
### Memory Management Tokens:
- `store` → for persistent storage
- Use for saving and loading data
```razen
store userData = loadUserData();
saveToStore(userData);
```
- `box` → for temporary variables with automatic cleanup
```razen
with box tempFile = File["open"]("data.txt") {
# Process file
# File will be automatically closed when exiting this block
}
```
- `ref` → for reference variables
- Use for aliasing and pointer-like behavior
```razen
ref currentUser = users[activeIndex];
currentUser.lastLogin = now();
```
### Input/Output Tokens:
- `show` → for printing output to console
- Use for displaying results and messages
```razen
show "Hello, world!";
show "Result: " + calculateResult();
```
- `read` → for reading input from user
- Use for getting user input and data entry
```razen
show "Enter you name: ";
read name;
show "Enter your age: ";
read age;
```
### Control Flow Tokens:
- `while` → for loop control
- Use for repeated execution based on condition
```razen
num i = 0;
while (i < 10) {
show i;
i = i + 1;
}
```
- `for` → for iterating over collections
- Use for processing elements in a sequence
```razen
for (item in collection) {
processItem(item);
}
```
- `fun` → for function declaration
- Use for code organization and reuse
```razen
fun greet(str name) {
return "Hello, " + name + "!";
}
```
- `async` → for asynchronous functions
- Use for non-blocking operations
```razen
async fun fetchData(str url) {
# Asynchronous operation
return result;
}
```
- `await` → for waiting on asynchronous operations
```razen
async fun processData() {
str data = await fetchData("https://api.example.com/data");
show "Data received: " + data;
}
```
### Object-Oriented Tokens:
- `class` → for class declaration
- Use for object-oriented programming
```razen
class User {
str name;
num age;
fun constructor(str name, num age) {
this[name] = name;
this[age] = age;
}
fun greet() {
show "Hello, my name is " + this[nam];
}
}
```
### Function Control Tokens:
- `return` → for function return values
- Use for sending results back from functions
```razen
fun add(num a, num b) {
return a + b;
}
```
- `continue` → for skipping to the next iteration
- Use in loops to skip the current iteration
```razen
for (num i = 0; i < 10; i = i + 1) {
if (i % 2 is 0) {
continue; # Skip even numbers
}
show i; # Only show odd numbers
}
```
- `break` → for exiting loops early
- Use to terminate a loop before its normal completion
```razen
while (true) {
if (checkCondition()) {
break; # Exit the infinite loop
}
doWork();
}
```
### Module Management Tokens:
- `import` → for importing modules
- Use for importing modules from other files
```razen
import { User, Product } from "./models.rzn";
```
- `export` → for exporting modules
- Use for exporting modules to other files
```razen
export fun calculateTotal(list items) {
# Function implementation
}
```
- `use` → for using imported functionality
- Use for accessing imported functions or classes
```razen
use Math[sqrt] to calculate square roots;
```
- `from` → for specifying import source
- Use with the `import` token to specify path
```razen
import { formatDate } from "./utils/date.rzn";
```
- `to` → for specifying export destination
- Use with the `export` token to specify path
```razen
export { User, Admin } to "./models/index.rzn";
```
### Library Import Token:
- `lib` → for importing standard libraries
- Use for accessing built-in functionality
```razen
lib Math;
lib HTTP;
lib FileSystem;
num squareRoot = Math[sqrt](16); # Using bracket notation for library functions
```
## Special Operators
Razen includes special arrow operators for improved readability:
### Arrow Operators: (Experimental)
- `->` → for indicating transformation or flow direction
```razen
# Pipeline processing
data -> processStep1() -> processStep2() -> result;
```
- `=>` → for lambda functions and mapping operations
```razen
# Lambda function
fun multiply = (num x, num y) => x * y;
# Mapping over a collection
ArrLib[map](numbers, num => num * 2);
```
- `→` → used in documentation to indicate purpose or usage (not in actual code)
## Next Steps
Now that you're familiar with Razen's tokens, you're ready to explore more advanced topics:
- **[Variables and Data Types](/docs/language-basics/variables_datatypes.mdx)** - Learn about different data types and how to use them
- **[Control Structures](/docs/language-basics/control_structures.mdx)** - Dive deeper into if statements, loops, and control flow
- **[Functions](/docs/language-basics/functions.mdx)** - Master function declarations and usage
# Tokens / Keywords
Let me introduce you to Razen's tokens and keywords - the building blocks of the language! These tokens have been designed to be intuitive and expressive, making your code more readable and maintainable.
## Core Tokens
### Comment Token:
- `#` for declaring a comment and adding notes to your code
```razen
# This is a comment in Razen
```
### Variable Declaration Tokens:
- `num` → for declaring numeric variables and calculations
- Use for **integers**, **floats**, and **mathematical** operations
```razen
num count = 42;
num pi = 3.14159;
```
- `str` → for declaring string variables and text manipulation
- Use for **text data**, **string** operations, and string interpolation
```razen
str name = "Razen";
str greeting = "Hello, " + name + "!";
```
- `bool` → for declaring boolean variables and logical conditions
- Use for **true/false/null** values and control flow
```razen
bool isActive = true;
bool hasErrors = false;
bool isEmpty = null;
```
- `var` → for declaring variables of any type
- Use when type is **unknown or mixed** types are needed
```razen
var data = getUserInput();
var result = processData(data);
```
- `const` → for declaring constants that cannot be changed
- Use for values that should remain fixed throughout execution
```razen
const API_KEY = "abc123xyz";
const MAX_ATTEMPTS = 3;
const PI = 3.14159;
const MAX_USERS = 100;
const APP_NAME = "Razen Demo";
```
### Logical Tokens:
- `if` → for conditional statements
```razen
if (score > 80) {
show "Excellent!";
} else if (score > 60) {
show "Good job!";
} else {
show "Keep practicing!";
}
```
- `else` → for alternative execution path
- `while` → for loop execution while a condition is true
```razen
num i = 0;
while (i < 5) {
show i;
i = i + 1;
}
```
- `for` → for loop execution with initialization, condition, and increment
```razen
for (num i = 0; i < 5; i = i + 1) {
show i;
}
```
- `is` → for equality comparison
```razen
if (status is "ready") {
startProcess();
}
```
- `when` → for pattern matching and case statements
- Use for multiple condition checks
```razen
when (dayOfWeek) {
"Monday": show "Start of week";
"Friday": show "End of week";
_: show "Middle of week";
}
```
- `not` → for logical negation
- Use to invert boolean values
```razen
if (not isEmpty) {
processData();
}
```
### Collection Tokens:
- `list` → for dynamic arrays and lists
- Use for storing multiple values of any type
```razen
list fruits = ["apple", "banana", "orange"];
```
- `arr` → for fixed-size arrays
- Use when array size is known and constant
```razen
arr temperatures = [72, 68, 75, 79, 71];
```
- `append` → for adding elements to lists
- Use for list growth and element addition
```razen
append(fruits, "mango");
```
- `remove` → for removing elements from lists
- Use for list cleanup and element deletion
```razen
remove(fruits, "banana");
```
### Dictionary/Map Tokens:
- `map` → for key-value storage
- Use for storing related data with unique keys
```razen
map userProfile = {
"name": "Alex",
"age": 28,
"isActive": true
};
```
- `key` → for accessing dictionary keys
- Use for key iteration and key-based operations
```razen
for (key in userProfile) {
show key + ": " + userProfile[key];
}
```
- `value` → for accessing dictionary values
- Use for value iteration and value-based operations
```razen
for (value in userProfile) {
processValue(value);
}
```
### Memory Management Tokens:
- `store` → for persistent storage
- Use for saving and loading data
```razen
store userData = loadUserData();
saveToStore(userData);
```
- `box` → for temporary variables with automatic cleanup
```razen
with box tempFile = File["open"]("data.txt") {
# Process file
# File will be automatically closed when exiting this block
}
```
- `ref` → for reference variables
- Use for aliasing and pointer-like behavior
```razen
ref currentUser = users[activeIndex];
currentUser.lastLogin = now();
```
### Input/Output Tokens:
- `show` → for printing output to console
- Use for displaying results and messages
```razen
show "Hello, world!";
show "Result: " + calculateResult();
```
- `read` → for reading input from user
- Use for getting user input and data entry
```razen
show "Enter you name: ";
read name;
show "Enter your age: ";
read age;
```
### Control Flow Tokens:
- `while` → for loop control
- Use for repeated execution based on condition
```razen
num i = 0;
while (i < 10) {
show i;
i = i + 1;
}
```
- `for` → for iterating over collections
- Use for processing elements in a sequence
```razen
for (item in collection) {
processItem(item);
}
```
- `fun` → for function declaration
- Use for code organization and reuse
```razen
fun greet(str name) {
return "Hello, " + name + "!";
}
```
- `async` → for asynchronous functions
- Use for non-blocking operations
```razen
async fun fetchData(str url) {
# Asynchronous operation
return result;
}
```
- `await` → for waiting on asynchronous operations
```razen
async fun processData() {
str data = await fetchData("https://api.example.com/data");
show "Data received: " + data;
}
```
### Object-Oriented Tokens:
- `class` → for class declaration
- Use for object-oriented programming
```razen
class User {
str name;
num age;
fun constructor(str name, num age) {
this[name] = name;
this[age] = age;
}
fun greet() {
show "Hello, my name is " + this[nam];
}
}
```
### Function Control Tokens:
- `return` → for function return values
- Use for sending results back from functions
```razen
fun add(num a, num b) {
return a + b;
}
```
- `continue` → for skipping to the next iteration
- Use in loops to skip the current iteration
```razen
for (num i = 0; i < 10; i = i + 1) {
if (i % 2 is 0) {
continue; # Skip even numbers
}
show i; # Only show odd numbers
}
```
- `break` → for exiting loops early
- Use to terminate a loop before its normal completion
```razen
while (true) {
if (checkCondition()) {
break; # Exit the infinite loop
}
doWork();
}
```
### Module Management Tokens:
- `import` → for importing modules
- Use for importing modules from other files
```razen
import { User, Product } from "./models.rzn";
```
- `export` → for exporting modules
- Use for exporting modules to other files
```razen
export fun calculateTotal(list items) {
# Function implementation
}
```
- `use` → for using imported functionality
- Use for accessing imported functions or classes
```razen
use Math[sqrt] to calculate square roots;
```
- `from` → for specifying import source
- Use with the `import` token to specify path
```razen
import { formatDate } from "./utils/date.rzn";
```
- `to` → for specifying export destination
- Use with the `export` token to specify path
```razen
export { User, Admin } to "./models/index.rzn";
```
### Library Import Token:
- `lib` → for importing standard libraries
- Use for accessing built-in functionality
```razen
lib Math;
lib HTTP;
lib FileSystem;
num squareRoot = Math[sqrt](16); # Using bracket notation for library functions
```
## Special Operators
Razen includes special arrow operators for improved readability:
### Arrow Operators: (Experimental)
- `->` → for indicating transformation or flow direction
```razen
# Pipeline processing
data -> processStep1() -> processStep2() -> result;
```
- `=>` → for lambda functions and mapping operations
```razen
# Lambda function
fun multiply = (num x, num y) => x * y;
# Mapping over a collection
ArrLib[map](numbers, num => num * 2);
```
- `→` → used in documentation to indicate purpose or usage (not in actual code)
## Next Steps
Now that you're familiar with Razen's tokens, you're ready to explore more advanced topics:
- **[Variables and Data Types](/docs/language-basics/variables_datatypes.mdx)** - Learn about different data types and how to use them
- **[Control Structures](/docs/language-basics/control_structures.mdx)** - Dive deeper into if statements, loops, and control flow
- **[Functions](/docs/language-basics/functions.mdx)** - Master function declarations and usage