Skip to content

Create a new transpiler from astx to c #263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xmnlab opened this issue Apr 14, 2025 · 1 comment
Open

Create a new transpiler from astx to c #263

xmnlab opened this issue Apr 14, 2025 · 1 comment

Comments

@xmnlab
Copy link
Contributor

xmnlab commented Apr 14, 2025

No description provided.

@nagajaideep
Copy link
Contributor

ASTx C Transpiler Implementation Summary

I Will create C language transpiler for ASTx that follows the same architecture as the Python transpiler but adapted for C language specifics. Here's an overview of the implementation:


Core Components

ASTxCTranspiler Class

  • Main class that handles conversion of ASTx nodes to C code.
  • Similar structure to ASTxPythonTranspiler with C-specific adaptations.

Key Methods

  • _generate_block() - Handles indentation and produces C-style blocks with braces.
  • visit() methods for each ASTx node type (using plum dispatch).
  • generate_program() - Assembles complete C program with includes and declarations.
  • _get_c_type() - Maps ASTx types to C types.
  • _translate_operator() - Converts ASTx operators to C operators.

C-Specific Features

  • Type management (handling C's static typing).
  • Header file inclusion tracking.
  • Semicolon management for statements.
  • Function prototypes generation.
  • Struct definitions handling.

Implemented Functionality

  • Variable declarations with appropriate C types.
  • Control structures (if-else, while, for, do-while).
  • Function definitions and calls.
  • Operators (arithmetic, logical, comparison).
  • Basic data structures (using arrays for lists).
  • Type casting.
  • Standard library function integration.

C-Specific Adaptations

  • Added semicolons to statement endings.
  • Implements proper C-style blocks with braces.
  • Tracks required includes (#include directives).
  • Handles function prototypes.
  • Manages C's type system requirements.
  • Converts Python-style loops to C-style loops.
  • Implements proper memory management considerations.

The implementation follows the same visitor pattern as the Python transpiler, ensuring a consistent approach while addressing C's unique language requirements.

if the approach given above looks good Ivan ,Let me fully implement the transpiler and test file along with documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants