Skip to content

⚙️ CS Assignment: Compiler for my own programming language.

Notifications You must be signed in to change notification settings

madyanalj/cs-comp-cons

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cs-comp-cons

Compiler Construction: This OCaml program is a compiler tool for my special language.

Usage

Building Compiler

$ make build

This will install core and menhir using opam first if they are not already installed, then build the compiler.

Running Tests

$ make test

This will run all test files existing in the tests directory. If the filename contains a string in the format .e_VALUE., it will output the test actual value and expect it to be the same as VALUE.

Syntax

My language uses c-style syntax, inspired by Javascript.

Function Definition

main (params) {
    0;
}

To return a value from a function, just add it as the last expression in the function.

Comments

/*
    This is a multiline ..
    .. comment!
*/
some_code(); /* inline comment */

Local Variables

let x = 5;

Operations

let x = 5;
let y = (x + 5) / 2;

Available Operators: + - * / <= < >= > == != && || !. You can use brackets to prioritize expressions.

Assignment

let x = 5;
x = 10;

Constants

const ENVIRONMENT = 1;

Calling Functions

sum(x, y);

Outputting Values

print x;

Debugging

dump(x);
dump(x + 3);
dump(x, y);

Reading User Input (Int Only - for now)

let x = read_int();

While Loops

while (i < max) {
    do_something();
    i = i + 1;
}

If Statements

if (i > 0) {
    do_something();
} else {
    do_something_else();
}

Complex Expression Assignment

(let z = x + y; if (z = 0) { x } else { y }) = 7;

Put parentheses around expressions to ensure they are parsed into a sequence.

About

⚙️ CS Assignment: Compiler for my own programming language.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published