Skip to content

Convert your C code to Python. Practical work in the Compilers subject at UFSJ.

License

Notifications You must be signed in to change notification settings

gabriel-dp/c2python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

c2python

Convert your C code to Python using a C++ program

#define STUDENT "Gabriel de Paula"
#define SUBJECT "Compiladores"
#define PROFESSOR "Flávio Schiavoni"
#define SEMESTER "2025/1"

 

How to use

Generate the executable:

make

Run the executable

./bin/compiler <source_file.c> <output_file.py>

 

Simplified C Syntax

1. Identifiers

  • Must start with an alphabetic character or an underscore (_).
  • Can contain any combination of letters, digits, and underscores after the first character.

2. Numbers

  • Must start with a digit.
  • Can contain one dot . to separate the integer and decimal parts.
  • May end with the letter f to represent a float.

3. String Literals

  • Must start and end with a double quote ".
  • The sequence \" is used to escape a double quote within the string.

4. Operators

  • Supported operators include:
    *, /, %, +, -, ==, !=, &&, ||, =, +=, -=, *=, /=, %=, &, |, ., >, <, >=, <=, !
  • If an operator consists of multiple characters, each individual character must also be a valid operator on its own.

5. Separators

  • Token-generating separators:
    (, ), {, }, [, ], ;, ,
  • Ignored separators (do not generate tokens):
    whitespace, newline \n, tab \t

6. Comments

  • Line comments start with //

  • Block comments start with /* and end with */

 

Discussion

This project was built only for educational purposes, probably will never be finished, but was a great way to learn more about compilers.

  • Lexical Analyzer
  • Syntax Analyzer
  • Semantic Analyzer
  • Code Generation (poor)
  • Optimization

About

Convert your C code to Python. Practical work in the Compilers subject at UFSJ.

Topics

Resources

License

Stars

Watchers

Forks