|
1 | | -# Gen Alpha Programming (GAP) |
| 1 | +# Translatable Python (`.tpy`) |
2 | 2 |
|
3 | | -Gen Alpha Programming (GAP) is a fun, experimental Python-like language that uses Gen Alpha slang for its syntax. It's designed as a demonstration of how a simple interpreter can be built and to provide a humorous take on programming languages. It is *not* intended for serious software development, but rather as an educational and entertaining project. |
| 3 | +Translatable Python (TPY) is a lightweight python compiler that lets you swap Python keywords with your own words. |
| 4 | +Whether you want to code in slang, inside jokes, or another language, you can! |
4 | 5 |
|
5 | | -**Important Note:** This is a simplified interpreter, *not* a full compiler. It translates GAP code into standard Python and then executes it. This means it has limitations compared to a fully compiled language. |
| 6 | +`lang.py` translates specified keywords contained in `lang.csv` into valid Python code and then executes that python |
| 7 | +code. |
6 | 8 |
|
7 | | -## Installation |
8 | | - |
9 | | -You don't need to "install" anything special. Just make sure you have Python 3 (preferably 3.10 or later, for `match`/`case` support) installed on your system. Then, save the interpreter code (provided in the `genalpha_python.py` file) to your computer. |
10 | | - |
11 | | -## Running GAP Code |
| 9 | +This project also has the potential to translate any language supported by UTF-8 into valid python code. |
12 | 10 |
|
13 | | -There are two ways to run GAP code: |
14 | | - |
15 | | -1. **Interactive Mode:** |
| 11 | +## Installation |
16 | 12 |
|
17 | | - Open your terminal or command prompt and run the interpreter script: |
| 13 | +You don't need to "install" anything special. Just make sure you have Python 3 (preferably 3.10 or later, for |
| 14 | +`match`/`case` support) installed on your system. |
18 | 15 |
|
19 | | - ```bash |
20 | | - python gena.py |
21 | | - ``` |
| 16 | +## Running Translatable Python |
22 | 17 |
|
23 | | - You'll see a `gap> ` prompt. Type your GAP code line by line, and it will be executed immediately. Type `exit` to quit the interactive mode. Multi-line statements (like `if`, `for`, `while`, and function definitions) are supported; the interpreter will wait for the complete block (indicated by a colon at the end of the initial line) before executing. |
| 18 | +1. **Specify Keywords In Your Language** |
| 19 | + |
| 20 | + To specify keywords, open `lang.csv` and add each translation in place of the current translation in the format |
| 21 | + `PythonKeyword,TranslatedKeyword`. The first column must be the original Python keyword (e.g. if, else, print), |
| 22 | + and the second column is your custom translation. Do not add multiple keywords or different translatable |
| 23 | + keywords for the same Python keyword, each line should contain strictly a python keyword and a unique |
| 24 | + translatable keyword. Make sure to save the file with UTF-8 encoding if your language uses special characters. |
| 25 | + The program will automatically read these pairs and use them to translate your code. |
24 | 26 |
|
25 | 27 | 2. **File Input:** |
26 | 28 |
|
27 | | - Create a text file containing your GAP code (e.g., `my_program.gap`). Then, run the interpreter with the filename as an argument: |
| 29 | + Create a `.tpy` file containing your translatable code (e.g., `example.tpy`). Then, run the compiler with the |
| 30 | + filename as an argument: |
28 | 31 |
|
29 | 32 | ```bash |
30 | | - python gena.py my_program.gap |
| 33 | + python lang.py example.tpy |
31 | 34 | ``` |
32 | 35 |
|
33 | | - The interpreter will read and execute the code from the file. |
34 | | -
|
35 | | -## Syntax Overview |
36 | | -
|
37 | | -Here's a mapping of Gen Alpha slang to their Python equivalents, along with examples: |
38 | | - |
39 | | -| Gen Alpha Slang | Python Equivalent | Description | Example | |
40 | | -|-----------------|------------------------|---------------------------------------------|-----------------------------------------------| |
41 | | -| `skibidi` | `None` / `def` | No value / Function definition | `skibidi my_var` / `skibidi my_func():` | |
42 | | -| `rizz` | `int` | Integer type hint (not strictly enforced) | `rizz x equals 5` | |
43 | | -| `chad` | `float` | Floating-point type hint (not enforced) | `chad pi equals 3.14159` | |
44 | | -| `gigachad` | `float` |Floating-point number (same as chad) |`gigachad big_num = 12345.67` | |
45 | | -| `yap` | `str` | String type hint | `yap my_string equals "Hello"` | |
46 | | -| `cap` | `bool` | Boolean type hint (not enforced) | `cap is_true equals W` | |
47 | | -| `W` | `True` | Boolean True | `cap flag equals W` | |
48 | | -| `L` | `False` | Boolean False | `cap another_flag equals L` | |
49 | | -| `edgy` | `if` | If statement | `edgy x greater_than y lbrace ...` | |
50 | | -| `amogus` | `else` | Else statement | `edgy x greater_than y lbrace ... amogus lbrace ...` | |
51 | | -| `goon` | `while` | While loop | `goon x less_than 10 lbrace ...` | |
52 | | -| `bruh` | `break` | Break statement (exit loop) | `goon W lbrace edgy condition lbrace bruh` | |
53 | | -| `grind` | `continue` | Continue statement (skip to next iteration) | `flex i in range(10) lbrace edgy i modulo 2 equals_equals 0 lbrace grind ...` | |
54 | | -| `flex` | `for` | For loop | `flex i in range(5) lbrace ...` | |
55 | | -| `bussin` | `return` (limited) | Return statement (very basic implementation) | `skibidi my_func() lbrace bussin 42` | |
56 | | -| `print` | `print` | Print statement | `print("Hello, world!")` | |
57 | | -| `input` |`input` | Read user input |`rant user_name = input("Enter name: ")` | |
58 | | -| `ohio` | `match` | Match statement (Python 3.10+) | `ohio value lbrace ...` | |
59 | | -| `sigma_rule` | `case` | Case within a match statement | `ohio x lbrace sigma_rule 1: ...` | |
60 | | -| `based` | `case _` | Default case in a match statement | `ohio x lbrace ... based: ...` | |
61 | | -| `cringe` | `raise` | Raise an exception | `cringe ValueError("Something went wrong")` | |
62 | | -| `equals` | `=` | Assignment operator | `rizz x equals 10` | |
63 | | -| `plus` | `+` | Addition operator | `x plus y` | |
64 | | -| `minus` | `-` | Subtraction operator | `x minus y` | |
65 | | -| `times` | `*` | Multiplication operator | `x times y` | |
66 | | -| `divide` | `/` | Division operator | `x divide y` | |
67 | | -| `modulo` | `%` | Modulo operator | `x modulo y` | |
68 | | -| `not` | `not` | Logical NOT operator | `not cap` | |
69 | | -| `and` | `and` | Logical AND operator | `x greater_than 0 and x less_than 10` | |
70 | | -| `or` | `or` | Logical OR operator | `x equals_equals 0 or y equals_equals 0` | |
71 | | -| `equals_equals` | `==` | Equality comparison operator | `x equals_equals y` | |
72 | | -| `not_equals` | `!=` | Inequality comparison operator | `x not_equals y` | |
73 | | -| `less_than` | `<` | Less than comparison operator | `x less_than y` | |
74 | | -| `greater_than` | `>` | Greater than comparison operator | `x greater_than y` | |
75 | | -| `less_than_or_equal` | `<=` | Less than or equal to comparison | `x less_than_or_equal y` | |
76 | | -| `greater_than_or_equal` | `>=` | Greater than or equal to comparison | `x greater_than_or_equal y` | |
77 | | -| `semicolon` | *(removed)* | Semicolons are removed | | |
78 | | -| `comma` | `,` | Commas are kept | | |
79 | | -|`lparen` | `(` | Left Parenthesis | `print(x)` | |
80 | | -|`rparen` | `)` | Right Parenthesis | `print(x)` | |
81 | | -|`lbrace` |`:` | Colon (for blocks) | | |
82 | | -|`rant` |`str` | Strings |`rant name = "John"` | |
83 | | -
|
84 | | -**Key Concepts:** |
85 | | -
|
86 | | -* **Indentation:** GAP, like Python, uses indentation (4 spaces recommended) to define code blocks (e.g., inside `if`, `for`, `while`, and function definitions). |
87 | | -* **Functions:** Functions are defined using `skibidi function_name(arguments) lbrace ...`. The `bussin` keyword is used for a very basic form of return (see limitations below). |
88 | | -* **Strings:** Strings are supported using the `rant` keyword. |
89 | | -
|
90 | | -**Limitations:** |
91 | | -
|
92 | | -* **Simplified Interpreter:** This is *not* a full-featured programming language. It's a demonstration project. |
93 | | -* **Limited `return`:** The `bussin` keyword provides only very basic return functionality. It works primarily for simple expressions at the top level (outside of functions) and stores the "returned" value in a special variable. It doesn't handle complex return scenarios within nested functions. |
94 | | -* **No Classes:** Object-oriented programming features (classes, objects, methods) are not supported. |
95 | | -* **No Modules/Imports:** There's no support for importing external modules. |
96 | | -* **Limited Error Handling:** The error messages might not always be very helpful, especially if the error is caused by the underlying Python code generated by the interpreter. |
97 | | -* **Global Scope Only:** All variables are in a single global scope. There's no concept of local variables within functions (beyond function parameters). |
98 | | -* **No Type Enforcement** Type Hints like `rizz` are replaced but python does not enforce them. |
99 | | -
|
100 | | -**Example Program (example.gap):** |
101 | | -```Example.gap |
102 | | -skibidi greet(yap name) lbrace |
103 | | -print("Hello, " plus name plus "!") |
104 | | -
|
105 | | -skibidi factorial(rizz n) lbrace |
106 | | -edgy n equals_equals 0 lbrace |
107 | | -bussin 1 |
108 | | -amogus lbrace |
109 | | -bussin n times factorial(n minus 1) |
110 | | -
|
111 | | -rizz num equals 5 |
112 | | -rizz fact equals factorial(num) |
113 | | -print("Factorial of " plus str(num) plus " is " plus str(fact)) # Convert numbers to strings for printing |
114 | | -
|
115 | | -greet("World") |
116 | | -
|
117 | | -flex i in range(1, 6) lbrace # Loop from 1 to 5 |
118 | | -print("Current number: " plus str(i)) |
119 | | -
|
120 | | -goon W lbrace #Infinite loop |
121 | | -rant user_input = input("Enter a number (or 'quit' to exit): ") |
122 | | -edgy user_input equals_equals "quit" lbrace |
123 | | -bruh |
124 | | -amogus: |
125 | | -rizz number = int(user_input) |
126 | | -print("You entered: " plus str(number)) |
127 | | -rbrace |
| 36 | +## Example |
| 37 | + |
| 38 | +1. `lang.csv` (Example): |
| 39 | + ```csv |
| 40 | + def,myfunc |
| 41 | + return,sendback |
| 42 | + if,whenever |
| 43 | + else,otherwise |
| 44 | + print,say |
| 45 | + ``` |
| 46 | + |
| 47 | +2. Custom Code (hello.tpy): |
| 48 | + ```text |
| 49 | + myfunc greet(name) { |
| 50 | + say("Hello " + name) |
| 51 | + sendback "done" |
| 52 | + } |
| 53 | + |
| 54 | + greet("World") |
| 55 | + ``` |
| 56 | + |
| 57 | +3. Run It: |
| 58 | + ```bash |
| 59 | + python lang.py hello.tpy |
| 60 | + ``` |
| 61 | + |
| 62 | +4. Output: |
| 63 | + ```text |
| 64 | + Hello World |
| 65 | + ``` |
0 commit comments