https://github.com/gabriel-dp/c2python
Convert your C code to Python. Practical work in the Compilers subject at UFSJ.
https://github.com/gabriel-dp/c2python
c compiler python ufsj
Last synced: 2 months ago
JSON representation
Convert your C code to Python. Practical work in the Compilers subject at UFSJ.
- Host: GitHub
- URL: https://github.com/gabriel-dp/c2python
- Owner: gabriel-dp
- Created: 2025-04-03T11:53:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-07T19:34:19.000Z (over 1 year ago)
- Last Synced: 2025-04-07T20:34:21.598Z (over 1 year ago)
- Topics: c, compiler, python, ufsj
- Language: C++
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# c2python
> Convert your C code to Python using a C++ program
```cpp
#define STUDENT "Gabriel de Paula"
#define SUBJECT "Compiladores"
#define PROFESSOR "Flávio Schiavoni"
#define SEMESTER "2025/1"
```
## How to use
Generate the executable:
```bash
make
```
Run the executable
```bash
./bin/compiler
```
## 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.
- [x] Lexical Analyzer
- [x] Syntax Analyzer
- [x] Semantic Analyzer
- [x] Code Generation (poor)
- [ ] Optimization