DEV Community

Cover image for Getting Started with sim-C
Aayush Agarwal for CimpleC

Posted on • Updated on

Getting Started with sim-C

We really appreciate the support we received towards sim-C. If you’ve landed here and want to know more about sim-C, do check out our previous post here.

In this post, we will see the various methods of installing sim-C and a handful of examples to get you familiarized about this amazing tool. So let’s simplify programming in C with sim-C.


Installing on Mac/Linux/Windows

  1. Run the following command
$ pip install git+https://github.com/cimplec/sim-c

With sim-C installed on your system, it’s time we get started with it. You can check out the documentation to get familiarized with the high-level syntax of sim-C.

Steps to run

  1. Open any text editor of your choice.
  2. Write code using the sim-C high-level syntax.
  3. Run the file using sim-C compiler.
$ simc test.simc

The C code file is generated with the same name as the simc file, but with extension .c


Here are a few examples of sim-C in action.
The code below is written in the syntax of sim-C.

MAIN
// A single line comment
/*
and this
is a
multi-line comment
*/
for a in 1 to 10 by +1 {
    if (a%2==0){
        print(a)
    }
    else {
        print("Odd")
    }
}
END_MAIN

This sim-C code gets converted to —

#include <stdio.h>
int main() {
// A single line comment
/*
and this
is a
multi-line comment
*/
for(int a=1; i<=10; i++) {
    if (a%2==0){
        printf("%d", a);
    }
    else {
        printf("Odd");
}
return 0;
}

Here’s another example:
sim-C code —

def interest(x, y, z) {
    si = (x*y*z)/100
    return si
}
MAIN
var p= input(“Enter the principal amount: “, “f”)
var r= input(“Enter the rate: “, “f”)
var t= input(“Enter the time period: “, “f”)
var interest_amount = interest(p, r, t)
print(interest_amount)
END_MAIN

Equivalent C code —

#include <stdio.h>
float interest(float x, float y, float z) {
float si = (x*y*z)/100;
return si;
}
int main(){
float p;
printf("Enter the principal amount: ");
scanf("%f", &p);
float r;
printf("Enter the rate: ");
scanf("%f", &r);
float t;
printf("Enter the time period: ");
scanf("%f", &t);
float interest_amount = interest(p,r,t);
printf(interest_amount);
return 0;
}

It is evident that sim-C has the capability to increase productivity and reduce development time by reducing the amount of code that needs to be written.


sim-C is still in continuous development and some amazing changes are on the way!! Do check out the Github repo and star it to be in touch with the updates taking place. Do let us know if you have any suggestions for us. Looking forward to hearing back from you.

Top comments (0)