Skip to content
 
 

Repository files navigation

Coal

About

Coal is a programming language designed for simplicity and ease of use. It is a compiled language, meaning that it runs faster than python. Coal also has the low-level accessibility like C.

Features

  • Simple syntax
  • Fast execution
  • Low-level accessibility
  • Easy to learn

Syntax

Variables

Variables are declared by using the var keyword like in kotlin:

var x = 5 // int
var y: string = "Hello, World!"

When creating a variable, you have the option to declare a type. You must always assign a type if you leave the variable undeclared, otherwise the compilier will figure out the type for you.

See the Data Types section for more information.

Data Types

Coal supports the following data types:

  • int
  • float
  • string
  • bool
  • char

We hope to have more in the future!

Functions

Functions are declared using the fn keyword:

fn main() {
    // code here
}

At the moment, you cannot make any other functions other than the main function. (We plan to add this soon.)

Important: All coal files always start with a main function, which is the entry point of the program.

If statements

fn main() {
    var x = 5
    if(x == 5) {
        println("x = 5")
    } elif(x != 5 && x >= 10) {
        println("x isnt 5 and is greater than 10")
    } else {
        println("x isnt 5 and is less than 10")
    }
}

While loops

fn main() {
    var x = 0
    while(x < 100_000) {
        x += 1
        println(x)
    }

    println("We're done!")
}

System Out and In

To print to the console, use the println function:

println("Hello, World!")

To take input from the user, use the input function:

var name = input("What's your name? ")

Coming soon!

Math

Coal supports the following mathematical operations:

  • Addition: +
  • Subtraction: -
  • Multiplication: *
  • Division: /
  • Modulus: %

More coming soon!

How to Compile and Run

To compile and run a coal program, use the following command:

    ./gradlew run --args="--input path/to/your/file.coal"
    

This will compile a coal program that will appear in the same directory. It is important to note that when building if there is an error in your code, the compiler will not tell you what is wrong. (We hope to add this feature however we don't know.)

More to come!

About

Compiled language, the ease of use as python, and the low-level accessibility as C

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages