Skip to content

tereus-project/tereus-transpiler-c-go

Repository files navigation

Tereus C to Go transpiler

Tereus transpilers mostly works like a compiler but instead of generating machine code, it generates text.

We use ANLTR to parse the source code into a AST (Abstract Syntax Tree).

ANTLR (ANother Tool for Language Recognition) is a powerful parser generator for reading, processing, executing, or translating structured text or binary files.

https://github.com/antlr/antlr4

Architecture

Command-line usage

You can use the following command to convert a C file to Go:

go run cmd/cli/main.go <input.c>

Worker usage

The transpiler is designed to listen on a queue for C files to convert.

First, you need to copy the .env.example file to .env and fill in the values.

The Kafka endpoint and S3 bucket should be shared with the Tereus API.

You can then start the worker with:

➜  go run .
INFO[0000] Connecting to Kafka...
INFO[0000] Connecting to MinIO...
INFO[0000] Starting transpiler job listener...
DEBU[0006] Job '48549e3e-a181-49f5-b204-0fc56df3e319' started
DEBU[0006] Downloading job files...
DEBU[0006] Downloading file 'main.c'
DEBU[0006] Remixing file 'main.c'
DEBU[0006] Uploading file 'main.go'
DEBU[0007] Job '48549e3e-a181-49f5-b204-0fc56df3e319' completed

The worker will get transpilation submissions from a queue and update the status and result in another one.

Supported features

  • Variables
    • Declaration
      • Global variables
    • Initialization
    • Assignment
    • Automatic type conversion
    • Variable list
    • Array variables declaration
      • Sized
      • Unsized
    • Multiple inline variables declaration
      • With pointers
  • Functions
    • Declaration with no definition
    • Declaration with definition
    • Arguments
    • Recursion
  • Types
    • Pointers
    • Arrays
      • Multi-dimensional arrays
    • Structures
      • Declaration with no definition
      • Declaration with definition
      • Initialization
    • Unions
    • Enums
    • Typedefs
  • Statements
    • if
    • for
      • With empty body
      • With multiple increments
    • do
    • while
    • switch
    • case
    • default
    • break
    • continue
    • return
    • goto
  • Expressions
    • Array indexing
    • List initialization
    • Structure property access
    • Pointer property access
    • Function call
    • Type casting
  • Arithmetic
    • Addition (+)
    • Subtraction (-)
    • Multiplication (*)
    • Division (/)
    • Modulo (%)
    • Prefix increment (++)
    • Prefix decrement (--)
    • Postfix increment (++)
    • Postfix decrement (--)
  • Bitwise operations
    • Bitwise AND (&)
    • Bitwise OR (|)
    • Bitwise XOR (^)
    • Bitwise NOT (~)
    • Bitwise Left Shift (<<)
    • Bitwise Right Shift (>>)
  • Logical operations
    • Logical AND (&&)
    • Logical OR (||)
    • Logical NOT (!)
  • Conditional operations
    • Equality (==)
    • Inequality (!=)
    • Less than (<)
    • Less than or equal to (<=)
    • Greater than (>)
    • Greater than or equal to (>=)
  • Assignment operations
    • Basic assignment (=)
    • Addition assignment (+=)
    • Subtraction assignment (-=)
    • Multiplication assignment (*=)
    • Division assignment (/=)
    • Modulo assignment (%=)
    • Bitwise AND assignment (&=)
    • Bitwise OR assignment (|=)
    • Bitwise XOR assignment (^=)
    • Bitwise Left Shift assignment (<<=)
    • Bitwise Right Shift assignment (>>=)
    • Ternary operator (?:)
  • Pointers operations
    • Pointer dereference (*)
    • Pointer addition (+)
    • Pointer subtraction (-)
    • Prefix pointer increment (++)
    • Prefix pointer decrement (--)
    • Postfix pointer increment (++)
    • Postfix pointer decrement (--)
    • Value address (&)
  • Misc
    • Comments
      • Single-line comments
      • Multi-line comments
    • sizeof
  • Preprocessor directives
    • #define A B
    • #define F(x) x
    • #define F(x) x ## 1
    • #undef A
    • #if A
    • #ifdef A
    • #ifndef A
    • #else
    • #elif A
    • #endif
    • #include <stdlib.h>
    • #include "./locallib.h"
  • Standard Library
    • stdlib.h
      • atof
      • atoi
      • atol
      • strtod
      • strtol
      • strtoul
      • calloc
      • free
      • malloc
      • realloc
      • abort
      • atexit
      • exit
      • getenv
      • system
      • bsearch
      • qsort
      • abs
      • div
      • labs
      • ldiv
      • rand
      • srand
      • mblen
      • mbstowcs
      • mbtowc
      • wcstombs
      • wctomb
    • assert.h
      • assert
    • string.h
      • memset
      • memchr
      • memcmp
      • memcpy
      • memmove
      • strcat
      • strncat
      • strchr
      • strcmp
      • strncmp
      • strcoll
      • strncpy
      • strcspn
      • strerror
      • strlen
      • strpbrk
      • strrchr
      • strspn
      • strtok
      • strxfrm