-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the Cmple wiki!
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.
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 also made to make typing easier. For example, to comment a code, typing '//' or ''' is so much easier compared to typing /* */
Another one is approach to global variables. In a function, local variables would use = to change its value and use := if the intention is to change the value of the global variable. Variables within a block is more likely local than global. Hence, we use = for it and the coder should consciously use := if the intent is to change the global variable. This behavior only exists in case variables of same names are used inside and outside the block. Otherwise, scoping rules of C applies. More of this later.
Blocks are grouped by indentation, python-style
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
*/
Functions are always declared in C-syle:
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
int x; // <- automatically created by the translator
x = f(5, 3.4);