Introduction

What is simC?

Often people have trouble programming in C (especially beginners) due to its low level syntax and unavailability of stable third party libraries. We present sim-C a high-level front end for C which creates a dynamically typed syntax for C. User can write code in this high level syntax and then compile it to optimized C code. sim-C does not process the code and simply translates it to C thus, there is no possibility of the code running slowly. So, with sim-C users can write code faster using the high level syntax and at the same time be able to harness the power and speed of a C program. Let us make C cool again.

Pipeline

Not found

Steps to run

  • Open any text editor of choice

  • Write code using simC high-level syntax

  • Run the file using simC compiler:

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

Some debugging commands

These commands are to be used in terminal while executing the file written in simC. These commands displays the tokens and opcodes that are created during the compilation of the simc code.

  • To print all the tokens during compilation

                      
                        $ simc <filename>.simc token
                      
                    
  • To print all the opcodes during compilation

                      
                        $ simc <filename>.simc opcode
                      
                    
  • To print symbol table after lexical analysis

                      
                        $ simc <filename>.simc table_after_lexing
                      
                    
  • To print symbol table after parsing

                      
                        $ simc <filename>.simc table_after_parsing
                      
                    

Main Function

Note:All the simC code is written in between the MAIN and END_MAIN keywords.

simC code:

C code:

Input Statement

Input without message prompt and type specification

When the type is not specified, the default type selected is "string".

simC code:

C code:

Integer input

simC code:

C code:

Float input

simC code:

C code:

Double input

simC code:

C code:

Character input

simC code:

C code:

String input

simC code:

C code:

Variables

Declaration

simC code:

C code:

Note: simC is a dynamically typed syntax for C so variable declarations do not require explicit mention of types.

Note: Identifiers cannot be named after a C keyword.

Initialization

simC code:

C code:

Assignment

simC code:

C code:

Strings

simC code:

C code:

Print statement

Print a string

simC code:

C code:

Print a numeric constant

simC code:

C code:

Print a variable

simC code:

C code:

Print with variables embedded in strings

simC code:

C code:

sizeof Operator

Syntax:

simC code:

C code:

type Operator

Syntax:

simC code:

C code:

Arithmetic Operators

Operator simC C
+ (Addition) 1 + 2 1 + 2
- (Subtraction) 1 - 2 1 - 2
* (Multiplication) 1 * 2 1 * 2
/ (Division) 1 / 2 1 / 2
% (Modulus) 1 % 2 1 % 2
** (Power, includes math.h during compilation) 1 ** 2 pow(1, 2)

Relational Operators

Operator simC C
< (Lesser than) 1 < 2 1 < 2
> (Greater than) 1 > 2 1 > 2
== (Equal to) 1 == 2 1 == 2
<= (Lesser than or equal to) 1 <= 2 1 <= 2
>= (Greater than or equal to) 1 >= 2 1 >= 2
!= (Not equal to) 1 != 2 1 != 2

Logical Operators

Operator simC C
&& (and) 1 && 2 1 && 2
|| (or) 1 || 2 1 || 2

Bitwise Operators

Operator simC C
& (bitwise and) 1 & 2 1 & 2
| (bitwise or) 1 | 2 1 | 2
^ (bitwise xor) 1 ^ 2 1 ^ 2

Escape Sequences

Escape Sequence simC C
\\ (Backslash) \\ \\
\0 (Null) \0 \0
\n (New Line) \n \n
\a (Alarm or Beep) \a \a
\b (Backspace) \b \b
\f (Form Feed) \f \f
\r (Carriage Return) \r \r
\t (Horizontal Tab) \t \t
\v (Vertical Tab) \v \v
\? (Question Mark) \? \?
\' (Single Quote) \' \'
\" (Double Quote) \" \"

Math Constants

Name of Constant simC format C format
Euler's Number (e) E M_E
Pi PI M_PI
Not a number (NaN) NaN NAN
Infinity inf INFINITY

Comments

Single line comments

simC code:

C code:

Multi line comments

simC code:

C code:

Typecasting

Explicit Typecasting

Syntax:

simC code:

C code:

Code Blocks

simC code:

C code:

Loops

For loop

simC code:

C code:

While loop

simC code:

C code:

Do while loop

simC code:

C code:

Conditional Statements

if statement

simC code:

C code:

if-else statement

simC code:

C code:

Nested if-else (if-else ladder)

simC code:

C code:

Switch Case

simC code:

C code:

break statement

simC code:

C code:

continue statement

simC code:

C code:

exit statement

simC code:

C code:

return statement

return expression

simC code:

C code:

return void

simC code:

C code:

Functions

Function Definition

C code:

Function Calling

C code:

Function Definition (with default arguments)

C code (The compiled C code contains a normal function with default argument values bound to the actual parameters during calling):

Function Calling (with default arguments)

C code:

Pointers

Pointer Declaration

simC code:

C code:

Pointer Declaration and Assignment

simC code:

C code:

Arrays

Array Declaration

simC code:

C code:

Array Declaration and Assignment

simC code:

C code:

simC code:

C code:

Array Indexing

simC code:

C code:

simC code:

C code:

Import Statements

To import a third-party module into your simC code.

simC code:

C code:

Example code: If package name if geometry then:

simC code:

C code:

Install Third-Party Packages

Functions maybe written by other developers that you can use in your code without having to write them again yourself.

simC syntax:

            
              $ simpack --name <name_of_package>
            
          

Example code: If package name if geometry then:

            
              $ simpack --name geometry
            
          

Raw C code

Sometimes the user might feel to write the actual C code while coding in simC as he/she might feel that the original C syntax is better or he/she finds it more comfortable to use it instead of the simC syntax. Apart from this, another reason for including the direct C code in simC file would be that the simC syntax of that particular feature of C language might not yet be developed or still being developed. The user can't wait for its syntax as the requirement is urgent. in such cases, the user can write the actual C code in the simC file and still get the desired results. The raw C code can be written in between the BEGIN_C and END_C keywords.
Note: The BEGIN_C and END_C are written inside the MAIN and END_MAIN keywords.

simC code:

C code:

Structures

Structure Declaration

simC code:

C code:

Structure Instantiation

simC code:

simC code:

simC code:

simC code: