Skip to content

Transpilator for C code to be converted into Bash script.

Notifications You must be signed in to change notification settings

YarikRevich/c-to-bash

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

c-to-bash-converter

Linux StandWithUkraine

General Information

Converts simple programs written in C to Bash script.

Use case

Having the following C code:

#include <stdio.h>

int d = 5 + 1;

// Describes foo function.
int foo() {
    return d;
}

int main() {
    int g = foo();

    for(int i = g; i < 10; i++) {
        printf("Hello world");
    }

    if (12 == 12) {
        printf("It works");
    }

    int i = 10; 

    while (i < 20) {
        printf("Slava Ukraini!");

        i++;
    }

    return 1;
}

It will be converted into the following script:

#!/bin/bash
    
d=$(( 5 + 1 ))
    
# Describes foo function.
function foo() {
    echo $((d))
}
    
function main() {
    local g=$(foo)
    
    for (( i=g; i < 10; i++ )); do
        echo "Hello world"
    done
    
    if [[ $(( 12 )) == $(( 12 )) ]]; then
        echo "It works"
    fi
    
    local i=$(( 10 ))
    
    while (( i < 20 )); do
        echo "Slava Ukraini!"
        (( i++ ))
    
    done
    
    echo $((1))
}
    
main

Supported functionality

Supported statements:

  • if conditions
  • for cycles
  • while cycles
  • simple function declarations without arguments
  • return statement
  • local variables
  • global variables
  • increaments
  • decreaments
  • comment declarations(separate line)

About

Transpilator for C code to be converted into Bash script.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages