Skip to content
Noel Quintos edited this page Jul 31, 2015 · 32 revisions

Welcome to the Cmple wiki!

The Idea

A language that is as easy to use as python but the speed of C. This language will be called Cmple (pronounced 'simple') whose syntax is a mix between C (in terms of variable declaration) and python (everything else). A translator to C, called cmple2c, would translate the Cmple code to C and then, compiled using C compiler.

Functionality is borrowed from various programming languages (Nim, Julia, Python, C) to allow better abstraction and ease of use.

Why Another Language?

Nim is the nearest to my liking but I still find it too complicated. Nim is like Pascal and my preference is C in terms of simplicity.

Attempts are made to make coding and typing easier. For example, to comment a code, typing '//' or ''' is so much easier compared to typing /* */. Also, python-like expressiveness is attempted and cymple2c will do the hard work of translating them to equivalent C code.

Delimiters

Blocks are grouped by indentation, python-style. The following Cmple statement

if 2 < x < 111
     z = 5
     y = 0
else
     z = -22
     y = 22

will be translated to this equivalent C statement

if (2 < x && x < 111) {
    z = 5;
    y = 0;
}
else {
    z = -22;
    y = 22;
}  

Notice that unlike python, no need for ':' at the if line.

Comments

Use '//' to designate comments as follows:

// this is a comment  
x = 4 // another comment  

cmple2c will translate this to:

 /* This is a comment */   
 x = 4; /* another comment*/    

Use ''' for longer comments as follows:

'''  
   This is a longer comment  
   spanning several lines  
'''  

cmple2c will translate this to:

/*   
   This is a longer comment  
   spanning several lines  
*/  

Variable and Function Declaration

Functions are always declared in C-syle and will not be modified by cmple2c

int f(int x, float y)  

Variables need not be declared if it could be derived somewhere else.

x = f(5, 3.4) // no need to declare x

Since we know that f() returns an int, the cmple2c would automatically create the declaration for you as follows:

int x; // <- automatically created by the translator  
x = f(5, 3.4);  

The first assignment will be used as the basis for making declaration

Functions pointers are also automatically declared for each defined functions when needed so that functions may be passed as parameter. The following cmple code:

int f(int x, float y)
    return x/y

g = f
print g(10, 5.0) // will print 2.0

will be translated into:

int f(int x, float y) {
    return x/y;
}

typedef int (*_cmple_f)(int, float);
_cmple_f g = &f;
print g(10, 5.0);

cmple2c keeps a dictionary of typedef signatures for all defined function and make appropriate declarations.

Clone this wiki locally