Skip to content

justlucdewit/cod

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cod

The Cod Compiler

Cod is an opensource concatenative stack-based general purpose programming language that compiles to C

In the future, it is planned for the compiler to be bootstrapped meaning it will be written in Cod itself.


Contribution

To Cod is an opensource project and contributions are welcome. If you would like to contribute, please fork the repository, work using github issues, use the ticket notation style used in the issues, and submit a pull request.

Hacktoberfest pull requests are welcome including spelling mistakes and grammar fixes.


Installation

You can download the latest version from your operating system on The cod website

Once downloaded you can put the executable in your system PATH and then it should work


Usage

cod someScript.cod -o someScript.c for More help, run cod --help

Make sure to download the standard library in your project root


Useful links:

Language

Hello World:

"Hello World!" prints

Fizzbuzz:

-- Fizzbuzz example written in Cod
include "std/math.cod"
include "std/io.cod"
include "std/stack.cod"

alias max_loop_count 40

-- Subroutine to check if number is divisible by another number
subroutine divisible_by {
    % 0 ==
}

-- Counter
1

-- Start the loop
true

while {
    pop
    
    -- Check if divisible by 3
    dup 3 divisible_by if {
        "fizz" prints
    } pop

    -- Check if divisible by 5
    dup 5 divisible_by if {
        "buzz" prints
    } pop
    
    -- Check if divisible by neither
    dup 3 divisible_by ! swap dup cycle3 swap 5 divisible_by ! & if {
        swap printn swap
    } pop

    -- Print newline
    10 printc pop

    -- Increment count
    1 +

    -- Determain if loop again
    dup max_loop_count <=
}