Get up and running with Veyra in minutes!
Make sure you have:
- Rust 1.70+ - Install here
- Git - For cloning the repository
# Clone the repository
git clone https://github.com/k6w/veyra.git
cd veyra
# Build the compiler
cd compiler
cargo build --release
# Build the toolchain
cd ../tools
cargo build --release
# Verify installation
cd ..
./compiler/target/release/veyra --versionCreate hello.vey:
println("Hello, World!")
Run it:
./compiler/target/release/veyra hello.veyLaunch the REPL for quick experiments:
./tools/target/release/veyra-replTry these commands:
>>> let name = "Veyra"
>>> println("Hello, " + name + "!")
Hello, Veyra!
>>> let square = fn(x) { return x * x }
>>> square(5)
25
>>> let numbers = [1, 2, 3, 4, 5]
>>> for n in numbers { println(n * 2) }
2
4
6
8
10
let name = "Alice" # String
let age = 25 # Integer
let height = 5.8 # Float
let is_student = true # Boolean
let items = [1, 2, 3] # Array
let person = {"name": "Bob", "age": 30} # Dictionary
# Simple function
fn greet(name) {
println("Hello, " + name + "!")
}
greet("World")
# Function with return value
fn add(a, b) {
return a + b
}
let result = add(5, 3)
println(result) # 8
# Recursive function
fn factorial(n) {
if n <= 1 {
return 1
}
return n * factorial(n - 1)
}
println(factorial(5)) # 120
# If-elif-else
let score = 85
if score >= 90 {
println("Grade: A")
} elif score >= 80 {
println("Grade: B")
} elif score >= 70 {
println("Grade: C")
} else {
println("Grade: F")
}
# While loop
let count = 0
while count < 5 {
println(count)
count = count + 1
}
# For loop
let fruits = ["apple", "banana", "orange"]
for fruit in fruits {
println("I like " + fruit)
}
# Arrays
let numbers = [1, 2, 3, 4, 5]
println(numbers[0]) # 1
println(len(numbers)) # 5
# Add elements
numbers = numbers + [6]
println(numbers) # [1, 2, 3, 4, 5, 6]
# Dictionaries
let person = {
"name": "Alice",
"age": 30,
"city": "NYC"
}
println(person["name"]) # Alice
person["age"] = 31 # Update value
fn safe_divide(a, b) {
try {
if b == 0 {
throw("Division by zero!")
}
return a / b
} catch error {
println("Error: " + error)
return null
} finally {
println("Division operation completed")
}
}
let result = safe_divide(10, 2)
println(result) # 5
Check your code for issues:
./tools/target/release/veyra-lint myprogram.veyDebug your program:
./tools/target/release/veyra-dbg myprogram.veyDebugger commands:
break <line>- Set breakpointcontinue- Continue executionstep- Step to next lineprint <var>- Print variable valuequit- Exit debugger
- Open VS Code
- Go to Extensions
- Install from
tools/vscode_extension - Enjoy syntax highlighting and IntelliSense!
- Language Specification - Complete language reference
- Examples - More code examples
- Design Philosophy - Language design principles
Check out these examples:
# Hello World
./compiler/target/release/veyra examples/hello_world.vey
# Functions
./compiler/target/release/veyra examples/functions.vey
# Loops
./compiler/target/release/veyra examples/loops.vey
# Math Demo
./compiler/target/release/veyra examples/math_demo.veyVeyra includes a rich standard library:
# Math operations
import math
println(math.sqrt(16)) # 4
println(math.pow(2, 8)) # 256
println(math.sin(math.pi)) # ~0
# String operations
import string
let text = "Hello, World!"
println(string.upper(text)) # HELLO, WORLD!
println(string.split(text, ",")) # ["Hello", " World!"]
# Collections
import collections
let items = [3, 1, 4, 1, 5, 9]
println(collections.sort(items)) # [1, 1, 3, 4, 5, 9]
println(collections.max(items)) # 9
Problem: cargo: command not found
- Solution: Install Rust from https://rustup.rs/
Problem: Build fails with linking errors
- Solution: Make sure you have the Visual Studio Build Tools installed (Windows) or build-essential (Linux)
Problem: REPL doesn't show output
- Solution: Make sure you're using
println()to display values
Let's build a simple calculator to learn Veyra:
# calculator.vey
fn add(a, b) { return a + b }
fn subtract(a, b) { return a - b }
fn multiply(a, b) { return a * b }
fn divide(a, b) {
if b == 0 {
println("Error: Division by zero")
return null
}
return a / b
}
fn calculate(op, a, b) {
if op == "+" {
return add(a, b)
} elif op == "-" {
return subtract(a, b)
} elif op == "*" {
return multiply(a, b)
} elif op == "/" {
return divide(a, b)
} else {
println("Unknown operation: " + op)
return null
}
}
# Test the calculator
println("5 + 3 = " + str(calculate("+", 5, 3)))
println("10 - 4 = " + str(calculate("-", 10, 4)))
println("6 * 7 = " + str(calculate("*", 6, 7)))
println("20 / 4 = " + str(calculate("/", 20, 4)))
Run it:
./compiler/target/release/veyra calculator.veyOutput:
5 + 3 = 8
10 - 4 = 6
6 * 7 = 42
20 / 4 = 5
You're now ready to start coding in Veyra! Here are some ideas:
- Calculator - Build a more advanced calculator
- To-Do List - Create a task manager
- Data Analysis - Process and analyze data
- Web Scraper - Extract data from websites
- Game - Build a text-based game
Happy coding! 🎉