Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rohittp0/not-python
!Python is a tiny language that I made to learn how compilers do their magic. The compiler of !Python is written in pure python ( no dependencies )
https://github.com/rohittp0/not-python
compiler language programming-language python
Last synced: 7 days ago
JSON representation
!Python is a tiny language that I made to learn how compilers do their magic. The compiler of !Python is written in pure python ( no dependencies )
- Host: GitHub
- URL: https://github.com/rohittp0/not-python
- Owner: rohittp0
- Created: 2022-12-09T22:55:38.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-11-07T16:21:02.000Z (almost 1 year ago)
- Last Synced: 2024-05-01T17:57:17.953Z (6 months ago)
- Topics: compiler, language, programming-language, python
- Language: Python
- Homepage: https://rohittp.com/not-python/
- Size: 48.8 KB
- Stars: 2
- Watchers: 1
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# !Python
**!Python** is a tiny language that I made to learn how compilers do their magic. The compiler of **!Python** is written
in pure python ( no dependencies ). It currently supports limited functionalities only, but in the future I might add more.
Or if you are interested you can add them, power of open source right !?.## Setup
To set up the compiler, you need to have **python** installed on your system. You also need **g++** as the compiler uses it to
compile the generated intermediate code.## How to use
1. Clone the [repository](https://github.com/rohittp0/not-python.git)
2. Run `python3 main.py ` to compile the file
3. Run `.exe` to execute the program## Syntax
**!Python** uses a simple syntax. It is similar to c/c++ but with some differences. The syntax is as follows:
1. Statements should be written one per line
2. `PRINT `: Prints the value of the expression
3. `INPUT `: Takes input from the user and stores it in the variable
4. `IF { }`: Executes the statement if the expression is true
5. `WHILE { }`: Executes the statement while the expression is true
6. `LET = `: Assigns the value of the expression to the variable
7. `RETURN `: Terminates the program with expression as exit code
8. If multiple expressions are given to the print statement, they are printed in the same lineThat's basically it. You can check the [examples](./examples) folder for more examples.
What about comments you ask ? Comments are for those who can't write readable code. Just kidding, I will add comments
later.## Keywords
The following keywords are reserved in **!Python**:
- INPUT
- LET
- IF
- WHILE
- RETURNAll keywords are case-sensitive, why would you want to write `print` instead of `PRINT` ? 🤷.
This means it is perfectly legal to do something like this:
INPUT print
PRINT "You said " printBut it is not legal to do something like this:
INPUT PRINT
PRINT "You said " PRINT## Compiler Flags
Currently, there are only 2 compiler flags:
- `-d`: Enables debug mode. In debug mode, the compiler preserves the intermediate code generated.
It will be saved as `.exe.cpp`
- `-o `: Specifies the name of the output file. By default, the output file is `.exe`## Examples
You can check the [examples](./examples) folder for more examples.