Rotate Programming Language
Table of Contents
The Syntax is subject to change at any time
Project Link
Basics
Hello World
import "std/io"; // comment fn main() { println("Hello, World"); }
Comments
// SINGLE LINE COMMENTS /* multi line comments */ fn main() {} /* multi line comments do not need to have an ending delimiter because EOF is enough for as a comment delimiter
Syntax Overview
Basic variables
import "std/io"; fn main() { x := 1; // inferred variable y :: 2; // inferred constant z :int = 1; // int variable print_int(x); print_int(y); print_int(z); println(""); }
If Else
import "std/io"; fn main() { x := 1; if x == 1 { println("x is 1"); } else { println("x is not 1"); } }
Loop
fn main() { for i in 0..2 { // do something } x := true; while x { break; } }
Switch
x :: 1; // every case break is the default switch x { 1: {} 2: {} else:{} }
Struct
Token :: struct { x: int, y: [3]int, } d := Token{1, [1, 2, 3]}; d.x = 2; d.y[1] = 1;
Function
import "std/io"; fn add(x: int, y: int) int { return x + y; } fn main() { print_int(add(1, 2)); println(""); }
Enums
// no size specification TknType :: enum { Id, Number, Float, String, Char, Invalid, }
Memory managment
similar to C, with some modern features (new/delete and defer)
io :: import("std/io"); os :: import("std/os"); str := new [3]char; defer delete str; x := new [100]int; tkn := new Token; // assuming Token is a struct defer delete tkn; defer delete x; // how to check for failed allocation if x == nil { io.println("Fail alloc"); os.exit(1); }
TODO
Compiler
- Parser 30% done
- TypeChecker 10% done
- Analysis
- Optimization
- CodeGen
DOCS
- Add a copy button in HTML docs export
- Add automation to docs generation
- Custom syntax highlighting for rotate