Skip to content

SaturdaySans/Saturn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Saturn

Saturn is a lightweight cpp interpreter :D
It supports variables, math, printing, conditionals, loops, and strings!!!


Running the Lagrange:

  1. Compile the interpreter (once!):
g++ saturn.cpp -o saturn
  1. Run a .sat script:
./saturn hello.sat
  • The saturn executable is the interpreter that runs .sat files
  • You can run scripts from anywhere once the interpreter is compiled.

Syntax

Variables Declaration

let x = 67
let name = "sixseven"
  • No explicit types: numbers and strings are inferred
  • Stored internally in a key-value map

Printing

print "Hello world"
print x
  • Strings must be in quotes ("...")
  • Variables print their stored value

Basic Operators

Supported operators: + - * /

let a = 10
let b = 5

let sum = a + b
let diff = a - b
let prod = a * b
let div = a / b

print sum
print diff
print prod
print div

If Statements

if x > 5
    print "x is MASSIVE"
end
  • Comparisons: > < >= <= == !=
  • Blocks have to end with end

For Loops

for i = 1 to 5
    print i
end
  • Loop variable increments automatically
  • Loop ends when the variable exceeds the end value

Using Comments

# Cement
let score = 100
  • Lines starting with # are ignored by the interpreter

Strings

let greeting = "Hello Saturn"
print greeting
  • Strings always use double quotes "...".

Formatted Strings

let grade = "A"
print "Grade: {grade}"
  • Similar to python's fstring

Input

input namme "Enter name: "
input age
  • Input Variable "prompt text"
  • Prompt text is optional

Random

random number 5
random number 1 10
  • Random (variable) (max)
  • Random (variable) (min) (max)

Sampel Code

random hp 10 15
random dmg 1 3
input rounds "Rounds:"

let remaining = hp - dmg
print remaining

#if remaining < 50
#    print "low hp"
#end

print "Health: {hp}"
print "Damage: {dmg}"

for i = 1 to rounds
    if remaining > 0
        print "Round {i}"
        let remaining = remaining - dmg
        print "Remaining hp: {remaining}, Damage dealt: {dmg}"
    end
end

Extra

  • Scripts should have the .sat extension
  • Blocks always end with end

Tysm! <3

About

cpp

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages