├── .idea ├── .gitignore ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── vcs.xml └── whython.iml ├── LICENSE ├── README.md ├── images ├── builtins_1.png ├── builtins_2.png ├── eval_1.png ├── keywords_dict_1.png ├── keywords_dict_2.png ├── syntax_1.png └── syntax_2.png ├── whython ├── __pycache__ │ ├── constants.cpython-310.pyc │ ├── constants.cpython-39.pyc │ ├── context.cpython-310.pyc │ ├── context.cpython-39.pyc │ ├── errors.cpython-310.pyc │ ├── errors.cpython-39.pyc │ ├── interpreter.cpython-310.pyc │ ├── interpreter.cpython-39.pyc │ ├── lexer.cpython-310.pyc │ ├── lexer.cpython-39.pyc │ ├── parser_.cpython-310.pyc │ ├── parser_.cpython-39.pyc │ ├── position.cpython-310.pyc │ ├── position.cpython-39.pyc │ ├── run.cpython-310.pyc │ ├── run.cpython-39.pyc │ ├── runtime_results.cpython-310.pyc │ ├── runtime_results.cpython-39.pyc │ ├── strings_with_arrows.cpython-310.pyc │ ├── strings_with_arrows.cpython-39.pyc │ ├── symbol_table.cpython-310.pyc │ ├── symbol_table.cpython-39.pyc │ ├── tokens.cpython-310.pyc │ └── tokens.cpython-39.pyc ├── constants.py ├── context.py ├── docs │ ├── docs.md │ ├── grammar.txt │ └── todo.txt ├── editable_ │ ├── __pycache__ │ │ ├── editable.cpython-310.pyc │ │ └── editable.cpython-39.pyc │ ├── editable.py │ └── editable_emoji.py ├── errors.py ├── examples │ ├── eval.whython │ ├── guesser.whython │ └── hello_world.whython ├── execute │ ├── __pycache__ │ │ ├── execute_append.cpython-310.pyc │ │ ├── execute_append.cpython-39.pyc │ │ ├── execute_clear.cpython-310.pyc │ │ ├── execute_clear.cpython-39.pyc │ │ ├── execute_exit.cpython-310.pyc │ │ ├── execute_exit.cpython-39.pyc │ │ ├── execute_extend.cpython-310.pyc │ │ ├── execute_extend.cpython-39.pyc │ │ ├── execute_input.cpython-310.pyc │ │ ├── execute_input.cpython-39.pyc │ │ ├── execute_input_int.cpython-310.pyc │ │ ├── execute_input_int.cpython-39.pyc │ │ ├── execute_is_func.cpython-310.pyc │ │ ├── execute_is_func.cpython-39.pyc │ │ ├── execute_is_list.cpython-310.pyc │ │ ├── execute_is_list.cpython-39.pyc │ │ ├── execute_is_num.cpython-310.pyc │ │ ├── execute_is_num.cpython-39.pyc │ │ ├── execute_is_str.cpython-310.pyc │ │ ├── execute_is_str.cpython-39.pyc │ │ ├── execute_len.cpython-310.pyc │ │ ├── execute_len.cpython-39.pyc │ │ ├── execute_pop.cpython-310.pyc │ │ ├── execute_pop.cpython-39.pyc │ │ ├── execute_print.cpython-310.pyc │ │ ├── execute_print.cpython-39.pyc │ │ ├── execute_pyeval.cpython-310.pyc │ │ ├── execute_pyeval.cpython-39.pyc │ │ ├── execute_randint.cpython-310.pyc │ │ ├── execute_randint.cpython-39.pyc │ │ ├── execute_run.cpython-310.pyc │ │ ├── execute_run.cpython-39.pyc │ │ ├── execute_to_int.cpython-310.pyc │ │ ├── execute_to_int.cpython-39.pyc │ │ ├── execute_to_str.cpython-310.pyc │ │ ├── execute_to_str.cpython-39.pyc │ │ ├── execute_update_value.cpython-310.pyc │ │ └── execute_update_value.cpython-39.pyc │ ├── execute_append.py │ ├── execute_clear.py │ ├── execute_exit.py │ ├── execute_extend.py │ ├── execute_input.py │ ├── execute_input_int.py │ ├── execute_is_func.py │ ├── execute_is_list.py │ ├── execute_is_num.py │ ├── execute_is_str.py │ ├── execute_len.py │ ├── execute_pop.py │ ├── execute_print.py │ ├── execute_pyeval.py │ ├── execute_randint.py │ ├── execute_run.py │ ├── execute_to_int.py │ ├── execute_to_str.py │ └── execute_update_value.py ├── interpreter.py ├── lexer.py ├── nodes_ │ ├── __pycache__ │ │ ├── node_binop.cpython-310.pyc │ │ ├── node_binop.cpython-39.pyc │ │ ├── node_break.cpython-310.pyc │ │ ├── node_break.cpython-39.pyc │ │ ├── node_call.cpython-310.pyc │ │ ├── node_call.cpython-39.pyc │ │ ├── node_continue.cpython-310.pyc │ │ ├── node_continue.cpython-39.pyc │ │ ├── node_for.cpython-310.pyc │ │ ├── node_for.cpython-39.pyc │ │ ├── node_funcdef.cpython-310.pyc │ │ ├── node_funcdef.cpython-39.pyc │ │ ├── node_if.cpython-310.pyc │ │ ├── node_if.cpython-39.pyc │ │ ├── node_list.cpython-310.pyc │ │ ├── node_list.cpython-39.pyc │ │ ├── node_number.cpython-310.pyc │ │ ├── node_number.cpython-39.pyc │ │ ├── node_return.cpython-310.pyc │ │ ├── node_return.cpython-39.pyc │ │ ├── node_string.cpython-310.pyc │ │ ├── node_string.cpython-39.pyc │ │ ├── node_unaryop.cpython-310.pyc │ │ ├── node_unaryop.cpython-39.pyc │ │ ├── node_varaccess.cpython-310.pyc │ │ ├── node_varaccess.cpython-39.pyc │ │ ├── node_varassign.cpython-310.pyc │ │ ├── node_varassign.cpython-39.pyc │ │ ├── node_while.cpython-310.pyc │ │ ├── node_while.cpython-39.pyc │ │ ├── nodes.cpython-310.pyc │ │ └── nodes.cpython-39.pyc │ ├── node_binop.py │ ├── node_break.py │ ├── node_call.py │ ├── node_continue.py │ ├── node_for.py │ ├── node_funcdef.py │ ├── node_if.py │ ├── node_list.py │ ├── node_number.py │ ├── node_return.py │ ├── node_string.py │ ├── node_unaryop.py │ ├── node_varaccess.py │ ├── node_varassign.py │ ├── node_while.py │ └── nodes.py ├── parser_.py ├── position.py ├── run.py ├── runtime_results.py ├── shell.py ├── strings_with_arrows.py ├── symbol_table.py ├── tokens.py └── values │ ├── __pycache__ │ ├── value_basefunction.cpython-310.pyc │ ├── value_basefunction.cpython-39.pyc │ ├── value_builtinfunc.cpython-310.pyc │ ├── value_builtinfunc.cpython-39.pyc │ ├── value_function.cpython-310.pyc │ ├── value_function.cpython-39.pyc │ ├── value_list.cpython-310.pyc │ ├── value_list.cpython-39.pyc │ ├── value_number.cpython-310.pyc │ ├── value_number.cpython-39.pyc │ ├── value_string.cpython-310.pyc │ ├── value_string.cpython-39.pyc │ ├── value_values.cpython-310.pyc │ └── value_values.cpython-39.pyc │ ├── value_basefunction.py │ ├── value_builtinfunc.py │ ├── value_function.py │ ├── value_list.py │ ├── value_number.py │ ├── value_string.py │ └── value_values.py └── whython_emoji ├── __pycache__ ├── constants.cpython-310.pyc ├── constants.cpython-39.pyc ├── context.cpython-310.pyc ├── context.cpython-39.pyc ├── errors.cpython-310.pyc ├── errors.cpython-39.pyc ├── interpreter.cpython-310.pyc ├── interpreter.cpython-39.pyc ├── lexer.cpython-310.pyc ├── lexer.cpython-39.pyc ├── parser_.cpython-310.pyc ├── parser_.cpython-39.pyc ├── position.cpython-310.pyc ├── position.cpython-39.pyc ├── run.cpython-310.pyc ├── run.cpython-39.pyc ├── runtime_results.cpython-310.pyc ├── runtime_results.cpython-39.pyc ├── strings_with_arrows.cpython-310.pyc ├── strings_with_arrows.cpython-39.pyc ├── symbol_table.cpython-310.pyc ├── symbol_table.cpython-39.pyc ├── tokens.cpython-310.pyc └── tokens.cpython-39.pyc ├── constants.py ├── context.py ├── docs ├── docs.md ├── grammar.txt └── todo.txt ├── editable_ ├── __pycache__ │ ├── editable.cpython-310.pyc │ └── editable.cpython-39.pyc └── editable.py ├── errors.py ├── examples ├── emoji.whython ├── eval.whython ├── guesser.whython └── hello_world.whython ├── execute ├── __pycache__ │ ├── execute_append.cpython-310.pyc │ ├── execute_append.cpython-39.pyc │ ├── execute_clear.cpython-310.pyc │ ├── execute_clear.cpython-39.pyc │ ├── execute_exit.cpython-310.pyc │ ├── execute_exit.cpython-39.pyc │ ├── execute_extend.cpython-310.pyc │ ├── execute_extend.cpython-39.pyc │ ├── execute_input.cpython-310.pyc │ ├── execute_input.cpython-39.pyc │ ├── execute_input_int.cpython-310.pyc │ ├── execute_input_int.cpython-39.pyc │ ├── execute_is_func.cpython-310.pyc │ ├── execute_is_func.cpython-39.pyc │ ├── execute_is_list.cpython-310.pyc │ ├── execute_is_list.cpython-39.pyc │ ├── execute_is_num.cpython-310.pyc │ ├── execute_is_num.cpython-39.pyc │ ├── execute_is_str.cpython-310.pyc │ ├── execute_is_str.cpython-39.pyc │ ├── execute_len.cpython-310.pyc │ ├── execute_len.cpython-39.pyc │ ├── execute_pop.cpython-310.pyc │ ├── execute_pop.cpython-39.pyc │ ├── execute_print.cpython-310.pyc │ ├── execute_print.cpython-39.pyc │ ├── execute_pyeval.cpython-310.pyc │ ├── execute_pyeval.cpython-39.pyc │ ├── execute_randint.cpython-310.pyc │ ├── execute_randint.cpython-39.pyc │ ├── execute_run.cpython-310.pyc │ ├── execute_run.cpython-39.pyc │ ├── execute_to_int.cpython-310.pyc │ ├── execute_to_int.cpython-39.pyc │ ├── execute_to_str.cpython-310.pyc │ ├── execute_to_str.cpython-39.pyc │ ├── execute_update_value.cpython-310.pyc │ └── execute_update_value.cpython-39.pyc ├── execute_append.py ├── execute_clear.py ├── execute_exit.py ├── execute_extend.py ├── execute_input.py ├── execute_input_int.py ├── execute_is_func.py ├── execute_is_list.py ├── execute_is_num.py ├── execute_is_str.py ├── execute_len.py ├── execute_pop.py ├── execute_print.py ├── execute_pyeval.py ├── execute_randint.py ├── execute_run.py ├── execute_to_int.py ├── execute_to_str.py └── execute_update_value.py ├── interpreter.py ├── lexer.py ├── nodes_ ├── __pycache__ │ ├── node_binop.cpython-310.pyc │ ├── node_binop.cpython-39.pyc │ ├── node_break.cpython-310.pyc │ ├── node_break.cpython-39.pyc │ ├── node_call.cpython-310.pyc │ ├── node_call.cpython-39.pyc │ ├── node_continue.cpython-310.pyc │ ├── node_continue.cpython-39.pyc │ ├── node_for.cpython-310.pyc │ ├── node_for.cpython-39.pyc │ ├── node_funcdef.cpython-310.pyc │ ├── node_funcdef.cpython-39.pyc │ ├── node_if.cpython-310.pyc │ ├── node_if.cpython-39.pyc │ ├── node_list.cpython-310.pyc │ ├── node_list.cpython-39.pyc │ ├── node_number.cpython-310.pyc │ ├── node_number.cpython-39.pyc │ ├── node_return.cpython-310.pyc │ ├── node_return.cpython-39.pyc │ ├── node_string.cpython-310.pyc │ ├── node_string.cpython-39.pyc │ ├── node_unaryop.cpython-310.pyc │ ├── node_unaryop.cpython-39.pyc │ ├── node_varaccess.cpython-310.pyc │ ├── node_varaccess.cpython-39.pyc │ ├── node_varassign.cpython-310.pyc │ ├── node_varassign.cpython-39.pyc │ ├── node_while.cpython-310.pyc │ ├── node_while.cpython-39.pyc │ ├── nodes.cpython-310.pyc │ └── nodes.cpython-39.pyc ├── node_binop.py ├── node_break.py ├── node_call.py ├── node_continue.py ├── node_for.py ├── node_funcdef.py ├── node_if.py ├── node_list.py ├── node_number.py ├── node_return.py ├── node_string.py ├── node_unaryop.py ├── node_varaccess.py ├── node_varassign.py ├── node_while.py └── nodes.py ├── parser_.py ├── position.py ├── run.py ├── runtime_results.py ├── shell.py ├── strings_with_arrows.py ├── symbol_table.py ├── tokens.py └── values ├── __pycache__ ├── value_basefunction.cpython-310.pyc ├── value_basefunction.cpython-39.pyc ├── value_builtinfunc.cpython-310.pyc ├── value_builtinfunc.cpython-39.pyc ├── value_function.cpython-310.pyc ├── value_function.cpython-39.pyc ├── value_list.cpython-310.pyc ├── value_list.cpython-39.pyc ├── value_number.cpython-310.pyc ├── value_number.cpython-39.pyc ├── value_string.cpython-310.pyc ├── value_string.cpython-39.pyc ├── value_values.cpython-310.pyc └── value_values.cpython-39.pyc ├── value_basefunction.py ├── value_builtinfunc.py ├── value_function.py ├── value_list.py ├── value_number.py ├── value_string.py └── value_values.py /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 50 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/whython.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Julian 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What is whython? 2 | > An almost fully customizable language made in python! 3 | 4 | Whython is a project language, the idea of it is that anyone can download 5 | and edit the language to make it suitable to what they want. This could be 6 | a change that makes it more like a language they know; a change that makes 7 | it easier for new people to learn the language; or even a change that makes 8 | it into a shitpost, it doesn't matter. You have the control! 9 | 10 | # How to run 11 | #### Download [whython](whython) 12 | 1. type `git clone https://github.com/NexInfinite/whython` in terminal (or download by other means) 13 | 2. cd whython/whython (or go into directory via other prefered method) 14 | 3. download emoji via pip using `pip3 install emoji` 15 | 16 | #### Create a script 17 | 1. make a file with the ending extesion ".whython" 18 | 2. write some code in it (use examples for help) 19 | 20 | #### Run the script 21 | 1. type `python3 shell.py` (or run script by other perfered method) 22 | 2. In the shell type `run('path/to/file')` 23 | 24 | # What can whython do? 25 | At the point of writing this (the first main push) you can change anything in the 26 | file [editable.py](whython/editable_/editable.py). This means you can change all the 27 | keywords (except = - / * ^) and all the builtin function names. 28 | ### Keywords 29 | For example, you may not like creating a variable like this: 30 | ``` 31 | var x = 10 32 | ``` 33 | and so you can change `KEYWORDS_DICT["var"]` to "let" and create a variable like this: 34 | ``` 35 | let x = 10 36 | ``` 37 | ![img.png](images/keywords_dict_1.png) 38 |
to
39 | ![img_1.png](images/keywords_dict_2.png) 40 | 41 | If you want to be super quirky you can even use emojis in the `KEYWORDS_DICT` and make 42 | some horrible emoji language! 43 | ### Builtin functions 44 | You may hate calling print like this: 45 | ``` 46 | print("Hello, World!") 47 | ``` 48 | and so you can change the global_symbol_table to be "shout" and print like this: 49 | ``` 50 | shout("Hello, World!") 51 | ``` 52 | ![img.png](images/builtins_1.png) 53 |
to
54 | ![img_1.png](images/builtins_2.png) 55 | 56 | ### Syntax 57 | Sometimes it can be annoying typing out: 58 | ``` 59 | var x = 10 60 | ``` 61 | so you may want this: 62 | ``` 63 | x = 10 64 | ``` 65 | To do this change:
66 | ![img.png](images/syntax_1.png) 67 |
to
68 | ![img_1.png](images/syntax_2.png) 69 | 70 | ### Eval 71 | There are things in this language that you can only do in python. If you need 72 | to run python eval then you can do: 73 | ``` 74 | var test = `print("This is from python")` 75 | eval(test) 76 | ``` 77 | Which will output
78 | ![img.png](images/eval_1.png) 79 |
80 | This is all editable in the editable.py file. 81 | 82 | 83 | # Todo 84 | There are a couple of builtin function that have not been created yet, this will be 85 | done in the future. 86 | - [x] to_str 87 | - [x] to_int 88 | - [x] eval 89 | - [ ] make builtins easier to add 90 | 91 | # What are the plans? 92 | I am planning to allow more control, for example a way to change all grammar rules 93 | and also easily add builtins (right now its kind of tedious). 94 | 95 | # How can I contribute? 96 | Either create a request on GitHub or message me on discord `Nexin#0001` to ask for 97 | new features. 98 | 99 | # Background 100 | This project was meant to be something small to learn about how languages run, but 101 | now it's a little more than that. I was originally following `codepulse`'s 102 | tutorial on YouTube but have since change a lot of the grammar rules and made 103 | it easier to debug. 104 | -------------------------------------------------------------------------------- /images/builtins_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/images/builtins_1.png -------------------------------------------------------------------------------- /images/builtins_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/images/builtins_2.png -------------------------------------------------------------------------------- /images/eval_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/images/eval_1.png -------------------------------------------------------------------------------- /images/keywords_dict_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/images/keywords_dict_1.png -------------------------------------------------------------------------------- /images/keywords_dict_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/images/keywords_dict_2.png -------------------------------------------------------------------------------- /images/syntax_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/images/syntax_1.png -------------------------------------------------------------------------------- /images/syntax_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/images/syntax_2.png -------------------------------------------------------------------------------- /whython/__pycache__/constants.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/constants.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/constants.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/constants.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/context.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/context.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/context.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/context.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/errors.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/errors.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/errors.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/errors.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/interpreter.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/interpreter.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/interpreter.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/interpreter.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/lexer.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/lexer.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/lexer.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/lexer.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/parser_.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/parser_.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/parser_.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/parser_.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/position.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/position.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/position.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/position.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/run.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/run.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/run.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/run.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/runtime_results.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/runtime_results.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/runtime_results.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/runtime_results.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/strings_with_arrows.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/strings_with_arrows.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/strings_with_arrows.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/strings_with_arrows.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/symbol_table.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/symbol_table.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/symbol_table.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/symbol_table.cpython-39.pyc -------------------------------------------------------------------------------- /whython/__pycache__/tokens.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/tokens.cpython-310.pyc -------------------------------------------------------------------------------- /whython/__pycache__/tokens.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/__pycache__/tokens.cpython-39.pyc -------------------------------------------------------------------------------- /whython/constants.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | import string 6 | import emoji 7 | 8 | # *################### 9 | # * CONSTANTS 10 | # *################### 11 | 12 | emojis = [] 13 | for emoji_ in emoji.EMOJI_UNICODE["en"]: 14 | emojis.append(emoji.EMOJI_UNICODE["en"][emoji_]) 15 | 16 | DIGITS = '0123456789' 17 | LETTERS = string.ascii_letters 18 | EMOJIS = "".join(emojis) 19 | LETTERS_DIGITS = LETTERS + DIGITS + EMOJIS 20 | QUOTES = "'\"" -------------------------------------------------------------------------------- /whython/context.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * CONTEXT 3 | # *################### 4 | 5 | class Context: 6 | def __init__(self, display_name, parent=None, parent_entry_pos=None): 7 | self.display_name = display_name 8 | self.parent = parent 9 | self.parent_entry_pos = parent_entry_pos 10 | self.symbol_table = None -------------------------------------------------------------------------------- /whython/docs/docs.md: -------------------------------------------------------------------------------- 1 | # If statements 2 | ``` 3 | if value == value do 4 | # do something 5 | elif value == other_value do 6 | # do something 7 | else 8 | # do something 9 | end 10 | ``` 11 | 12 | # While loop 13 | ``` 14 | while value == value do 15 | # do something 16 | break/return/continue 17 | end 18 | ``` 19 | 20 | # For loop 21 | ``` 22 | for var i = 0 to 5 step 1 do 23 | print(i) 24 | break/return/continue 25 | end 26 | ``` -------------------------------------------------------------------------------- /whython/docs/grammar.txt: -------------------------------------------------------------------------------- 1 | (LESS) 2 | 3 | statements : NEWLINE* statement (NEWLINE+ statement)* NEWLINE* 4 | 5 | statement : KEYWORD:return expr? 6 | : KEYWORD:continue 7 | : KEYWORD:break 8 | : expr 9 | 10 | expr : KEYWORD:var IDENTIFIER EQ expr 11 | : comp_expr ((KEYWORD:and | KEYWORD:or | KEYWORD:not) comp_expr)* 12 | 13 | comp_expr : NOT comp_expr 14 | : arith_expr ((EE | LT | LTE | GT | GTE) arith_expr)* 15 | 16 | arith_expr : term ((PLUS | MINUS) term)* 17 | 18 | term : factor ((MUL | DIV) factor)* 19 | 20 | factor : (PLUS | MINUS) factor 21 | : power 22 | 23 | exponent : call (EXPONENT factor)* 24 | 25 | call : atom (LPAREN (expr (COMMA expr)*)? RPAREN)? 26 | 27 | atom : INT | FLOAT | STRING | IDENTIFIER 28 | : LPAREN expr RPAREN 29 | : list_expr 30 | : if_expr 31 | : for_expr 32 | : while_expr 33 | : func_def 34 | 35 | list_expr : LSQUARE (expr (COMMA expr)*)? RSQUARE 36 | 37 | if_expr : KEYWORD:if expr KEYWORD:then 38 | (statement if_expr_b | if_expr_c?) 39 | | (NEWLINE statements KEYWORD:end if_expr_b | if_expr_c) 40 | 41 | if_expr_b : KEYWORD:elif expr KEYWORD:then 42 | (statement if_expr_b | if_expr_c?) 43 | | (NEWLINE statements KEYWORD:end if_expr_b | if_expr_c) 44 | 45 | if_expr_c : KEYWORD:else 46 | statement 47 | | (NEWLINE statements KEYWORD:end) 48 | 49 | for_expr : KEYWORD:for KEYWORD:var IDENTIFIER EQ expr KEYWORD:to expr 50 | (KEYWORD:STEP expr)? KEYWORD:then 51 | statement 52 | | (NEWLINE statements KEYWORD:end) 53 | 54 | while_expr : KEYWORD:while expr KEYWORD:then 55 | statement 56 | | (NEWLINE statements KEYWORD:end) 57 | 58 | func_def : KEYWORD:func IDENTIFIER? 59 | LPAREN (IDENTIFIER (COMMA IDENTIFIER)*)? RPAREN 60 | (ARROW expr) 61 | | (NEWLINE statements KEYWORD:end) 62 | 63 | (MORE) 64 | -------------------------------------------------------------------------------- /whython/docs/todo.txt: -------------------------------------------------------------------------------- 1 | DONE: 2 | print 3 | input 4 | input_int 5 | clear 6 | exit 7 | update_value 8 | is_num 9 | is_string 10 | is_list 11 | is_function 12 | append 13 | pop 14 | extend 15 | run 16 | length 17 | randint 18 | to_str 19 | to_int 20 | use python code 21 | TODO: 22 | make builtins easier 23 | -------------------------------------------------------------------------------- /whython/editable_/__pycache__/editable.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/editable_/__pycache__/editable.cpython-310.pyc -------------------------------------------------------------------------------- /whython/editable_/__pycache__/editable.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/editable_/__pycache__/editable.cpython-39.pyc -------------------------------------------------------------------------------- /whython/editable_/editable.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from symbol_table import SymbolTable 6 | 7 | from values.value_builtinfunc import BuiltInFunction 8 | from values.value_number import Number 9 | 10 | # *################### 11 | # * KEYWORDS 12 | # * YOU CAN EDIT THIS! 13 | # *################### 14 | 15 | """ 16 | How to use: 17 | 18 | Change the value in the dict (right hand side) to the new value you want it to be. 19 | For example changing 20 | 21 | "var": "var", to "var": "let", 22 | will change 23 | var x = 10 to let x = 10 24 | 25 | You cannot change the value to be a value with spaces, for example 26 | 27 | "let this be" will not work but "let_this_be" will work! 28 | """ 29 | 30 | KEYWORDS_DICT = { 31 | "var": "var", 32 | "and": "and", 33 | "or": "or", 34 | "elif": "elif", 35 | "else": "else", 36 | "if": "if", 37 | "not": "not", 38 | "do": "do", 39 | "for": "for", 40 | "to": "to", 41 | "step": "step", 42 | "while": "while", 43 | "func": "func", 44 | "end": "end", 45 | "return": "return", 46 | "continue": "continue", 47 | "break": "break", 48 | } 49 | 50 | # *################### 51 | # * SYMBOL TABLE 52 | # * YOU CAN EDIT THIS! 53 | # *################### 54 | 55 | """ 56 | How to use: 57 | 58 | Change the value in the first argument of .set() 59 | For example: 60 | global_symbol_table.set("null", Number.null) 61 | -> 62 | global_symbol_table.set("nill", Number.null) 63 | 64 | This will change the value `null` to `nill` in the command line. 65 | """ 66 | 67 | global_symbol_table = SymbolTable() 68 | # changing the below to 69 | # global_symbol_table.set("nill", Number.null) 70 | # will make `nill` work instead of `null` in command line 71 | global_symbol_table.set("null", Number.null) 72 | global_symbol_table.set("true", Number.true) 73 | global_symbol_table.set("false", Number.false) 74 | global_symbol_table.set("pi", Number.pi) 75 | 76 | # changing the below to 77 | # global_symbol_table.set("shout", BuiltInFunction("print")) 78 | # will make shout("value") work instead of print("value") 79 | # If you want an example of what each of this functions do go to values/value_builtinfunc.py and find the correct function. 80 | global_symbol_table.set("print", BuiltInFunction("print")) 81 | global_symbol_table.set("input", BuiltInFunction("input")) 82 | global_symbol_table.set("input_int", BuiltInFunction("input_int")) 83 | global_symbol_table.set("clear", BuiltInFunction("clear")) 84 | global_symbol_table.set("exit", BuiltInFunction("exit")) 85 | global_symbol_table.set("update_value", BuiltInFunction("update_value")) 86 | global_symbol_table.set("is_num", BuiltInFunction("is_num")) 87 | global_symbol_table.set("is_str", BuiltInFunction("is_str")) 88 | global_symbol_table.set("is_list", BuiltInFunction("is_list")) 89 | global_symbol_table.set("is_func", BuiltInFunction("is_func")) 90 | global_symbol_table.set("append", BuiltInFunction("append")) 91 | global_symbol_table.set("pop", BuiltInFunction("pop")) 92 | global_symbol_table.set("extend", BuiltInFunction("extend")) 93 | global_symbol_table.set("run", BuiltInFunction("run")) 94 | global_symbol_table.set("len", BuiltInFunction("len")) 95 | global_symbol_table.set("randint", BuiltInFunction("randint")) 96 | global_symbol_table.set("to_str", BuiltInFunction("to_str")) 97 | global_symbol_table.set("to_int", BuiltInFunction("to_int")) 98 | global_symbol_table.set("eval", BuiltInFunction("pyeval")) 99 | 100 | # *################### 101 | # * GRAMMAR RULES 102 | # * YOU CAN EDIT THIS! 103 | # *################### 104 | 105 | # With this True you will need "var". 106 | # With it False you can either use "var" or not. 107 | GRAMMAR_USE_IDENTIFIER_FOR_ASSIGNMENT = True 108 | # More coming soon.... -------------------------------------------------------------------------------- /whython/editable_/editable_emoji.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from symbol_table import SymbolTable 6 | 7 | from values.value_builtinfunc import BuiltInFunction 8 | from values.value_number import Number 9 | 10 | # *################### 11 | # * KEYWORDS 12 | # * YOU CAN EDIT THIS! 13 | # *################### 14 | 15 | """ 16 | How to use: 17 | 18 | Change the value in the dict (right hand side) to the new value you want it to be. 19 | For example changing 20 | 21 | "var": "var", to "var": "let", 22 | will change 23 | var x = 10 to let x = 10 24 | 25 | You cannot change the value to be a value with spaces, for example 26 | 27 | "let this be" will not work but "let_this_be" will work! 28 | """ 29 | 30 | KEYWORDS_DICT = { 31 | "var": "😀", 32 | "and": "👌", 33 | "or": "🤏", 34 | "elif": "😑", 35 | "else": "🤬", 36 | "if": "❓", 37 | "not": "❌", 38 | "do": "⏩", 39 | "for": "🔁", 40 | "to": "👉", 41 | "step": "🦶", 42 | "while": "🤨", 43 | "func": "🥶", 44 | "end": "💀", 45 | "return": "👹", 46 | "continue": "😈", 47 | "break": "😱" 48 | } 49 | 50 | # *################### 51 | # * SYMBOL TABLE 52 | # * YOU CAN EDIT THIS! 53 | # *################### 54 | 55 | """ 56 | How to use: 57 | 58 | Change the value in the first argument of .set() 59 | For example: 60 | global_symbol_table.set("null", Number.null) 61 | -> 62 | global_symbol_table.set("nill", Number.null) 63 | 64 | This will change the value `null` to `nill` in the command line. 65 | """ 66 | 67 | global_symbol_table = SymbolTable() 68 | # changing the below to 69 | # global_symbol_table.set("nill", Number.null) 70 | # will make `nill` work instead of `null` in command line 71 | global_symbol_table.set("null", Number.null) 72 | global_symbol_table.set("true", Number.true) 73 | global_symbol_table.set("false", Number.false) 74 | global_symbol_table.set("pi", Number.pi) 75 | 76 | # changing the below to 77 | # global_symbol_table.set("shout", BuiltInFunction("print")) 78 | # will make shout("value") work instead of print("value") 79 | # If you want an example of what each of this functions do go to values/value_builtinfunc.py and find the correct function. 80 | global_symbol_table.set("📣", BuiltInFunction("print")) 81 | global_symbol_table.set("💬", BuiltInFunction("input")) 82 | global_symbol_table.set("🤓", BuiltInFunction("input_int")) 83 | global_symbol_table.set("🔄", BuiltInFunction("clear")) 84 | global_symbol_table.set("🤡", BuiltInFunction("exit")) 85 | global_symbol_table.set("📲", BuiltInFunction("update_value")) 86 | global_symbol_table.set("🔢", BuiltInFunction("is_num")) 87 | global_symbol_table.set("🔠", BuiltInFunction("is_str")) 88 | global_symbol_table.set("🔣", BuiltInFunction("is_list")) 89 | global_symbol_table.set("🚚", BuiltInFunction("is_func")) 90 | global_symbol_table.set("🔚", BuiltInFunction("append")) 91 | global_symbol_table.set("🔝", BuiltInFunction("pop")) 92 | global_symbol_table.set("🔛", BuiltInFunction("extend")) 93 | global_symbol_table.set("😳", BuiltInFunction("run")) 94 | global_symbol_table.set("📏", BuiltInFunction("len")) 95 | global_symbol_table.set("🤑", BuiltInFunction("randint")) 96 | global_symbol_table.set("👄", BuiltInFunction("to_str")) 97 | global_symbol_table.set("👅", BuiltInFunction("to_int")) 98 | global_symbol_table.set("🧠", BuiltInFunction("pyeval")) 99 | 100 | # *################### 101 | # * GRAMMAR RULES 102 | # * YOU CAN EDIT THIS! 103 | # *################### 104 | 105 | # With this True you will need "var". 106 | # With it False you can either use "var" or not. 107 | GRAMMAR_USE_IDENTIFIER_FOR_ASSIGNMENT = True 108 | # More coming soon.... -------------------------------------------------------------------------------- /whython/errors.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from strings_with_arrows import * 6 | 7 | # *################### 8 | # * ERRORS 9 | # *################### 10 | 11 | class Error: 12 | def __init__(self, pos_start, pos_end, error_name, details): 13 | self.error_name = error_name 14 | self.details = details 15 | self.pos_start = pos_start 16 | self.pos_end = pos_end 17 | 18 | def as_string(self): 19 | result = f"{self.error_name}: {self.details}" 20 | result += f"\nFile {self.pos_start.fn}, line {self.pos_start.ln + 1}" 21 | result += '\n\n' + string_with_arrows(self.pos_start.ftxt, self.pos_start, self.pos_end) 22 | return result 23 | 24 | class IllegalCharError(Error): 25 | def __init__(self, pos_start, pos_end, details): 26 | super().__init__(pos_start, pos_end, 'Illegal Character', details) 27 | 28 | 29 | class ExpectedCharError(Error): 30 | def __init__(self, pos_start, pos_end, details=''): 31 | super().__init__(pos_start, pos_end, 'Expected Character', details) 32 | 33 | 34 | class InvalidSyntaxError(Error): 35 | def __init__(self, pos_start, pos_end, details=''): 36 | super().__init__(pos_start, pos_end, 'Invalid Syntax', details) 37 | 38 | class CastingError(Error): 39 | def __init__(self, pos_start, pos_end, details=''): 40 | super().__init__(pos_start, pos_end, 'Casting Error', details) 41 | 42 | class RTError(Error): 43 | def __init__(self, pos_start, pos_end, details, context): 44 | super().__init__(pos_start, pos_end, 'Runtime Error', details) 45 | self.context = context 46 | 47 | def as_string(self): 48 | result = self.generate_traceback() 49 | result += f"{self.error_name}: {self.details}" 50 | result += '\n\n' + string_with_arrows(self.pos_start.ftxt, self.pos_start, self.pos_end) 51 | return result 52 | 53 | def generate_traceback(self): 54 | result = "" 55 | pos = self.pos_start 56 | ctx = self.context 57 | 58 | while ctx: 59 | result = f" >> File {pos.fn}, line {str(pos.ln + 1)}, in {ctx.display_name}\n" 60 | pos = ctx.parent_entry_pos 61 | ctx = ctx.parent 62 | 63 | return f"Traceback (most recent call last):\n {result}" -------------------------------------------------------------------------------- /whython/examples/eval.whython: -------------------------------------------------------------------------------- 1 | # run("examples/eval") 2 | 3 | var test_1 = `input("What's your name? ")` 4 | var name = eval(test_1) 5 | print(name) 6 | 7 | var test_2 = ` 8 | print("test_2") 9 | ` 10 | print("\n") 11 | eval(test_2) 12 | 13 | var test_3 = ` 14 | for i in range(10): 15 | print(f"hello, test_3! {i}") 16 | ` 17 | print("\n") 18 | eval(test_3) 19 | 20 | var test_4 = ` 21 | def test_4(): 22 | print("Test 4 is wrapped in a function!") 23 | test_4() 24 | ` 25 | print("\n") 26 | eval(test_4) -------------------------------------------------------------------------------- /whython/examples/guesser.whython: -------------------------------------------------------------------------------- 1 | number = randint(1, 100) 2 | 3 | func winner() 4 | print("This is the winner message!!!") 5 | end 6 | 7 | while true do 8 | print("Guess a number between 1 and 100") 9 | var x = input_int() 10 | if x <= 100 and x >= 1 do 11 | if x == number do 12 | print("You got it!") 13 | winner() 14 | break 15 | elif x < number do 16 | print("Too low!") 17 | elif x > number do 18 | print("Too high!") 19 | end 20 | else 21 | print("Number not within range of 1 and 100") 22 | end 23 | end -------------------------------------------------------------------------------- /whython/examples/hello_world.whython: -------------------------------------------------------------------------------- 1 | print("Hello, World!") -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_append.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_append.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_append.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_append.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_clear.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_clear.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_clear.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_clear.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_exit.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_exit.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_exit.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_exit.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_extend.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_extend.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_extend.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_extend.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_input.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_input.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_input.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_input.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_input_int.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_input_int.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_input_int.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_input_int.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_is_func.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_is_func.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_is_func.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_is_func.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_is_list.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_is_list.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_is_list.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_is_list.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_is_num.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_is_num.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_is_num.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_is_num.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_is_str.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_is_str.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_is_str.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_is_str.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_len.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_len.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_len.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_len.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_pop.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_pop.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_pop.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_pop.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_print.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_print.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_print.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_print.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_pyeval.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_pyeval.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_pyeval.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_pyeval.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_randint.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_randint.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_randint.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_randint.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_run.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_run.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_run.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_run.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_to_int.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_to_int.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_to_int.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_to_int.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_to_str.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_to_str.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_to_str.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_to_str.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_update_value.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_update_value.cpython-310.pyc -------------------------------------------------------------------------------- /whython/execute/__pycache__/execute_update_value.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/execute/__pycache__/execute_update_value.cpython-39.pyc -------------------------------------------------------------------------------- /whython/execute/execute_append.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_list import List 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | from errors import RTError 10 | 11 | # *################### 12 | # * APPEND 13 | # *################### 14 | 15 | def execute_append_func(self, exec_ctx): 16 | list_ = exec_ctx.symbol_table.get("list") 17 | value = exec_ctx.symbol_table.get("value") 18 | 19 | if not isinstance(list_, List): 20 | return RTResult().failure(RTError( 21 | self.pos_start, self.pos_end, 22 | "First argument must be a list", 23 | exec_ctx 24 | )) 25 | 26 | list_.elements.append(value) 27 | return RTResult().success(Number.null) -------------------------------------------------------------------------------- /whython/execute/execute_clear.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | import os 6 | 7 | from values.value_number import Number 8 | from runtime_results import RTResult 9 | 10 | # *################### 11 | # * PRINT 12 | # *################### 13 | 14 | def execute_clear_func(self, exec_ctx): 15 | os.system("cls" if os.name == "nt" else "clear") 16 | return RTResult().success(Number.ignore) 17 | -------------------------------------------------------------------------------- /whython/execute/execute_exit.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | import sys 6 | 7 | # *################### 8 | # * RANDINT 9 | # *################### 10 | 11 | def execute_exit_func(self, exec_ctx): 12 | print("Exiting...") 13 | sys.exit() 14 | -------------------------------------------------------------------------------- /whython/execute/execute_extend.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_list import List 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | from errors import RTError 10 | 11 | # *################### 12 | # * EXTEND 13 | # *################### 14 | 15 | def execute_extend_func(self, exec_ctx): 16 | list_a = exec_ctx.symbol_table.get("list_a") 17 | list_b = exec_ctx.symbol_table.get("list_b") 18 | 19 | if not isinstance(list_a, List): 20 | return RTResult().failure(RTError( 21 | self.pos_start, self.pos_end, 22 | "First argument must be a list", 23 | exec_ctx 24 | )) 25 | 26 | if not isinstance(list_b, List): 27 | return RTResult().failure(RTError( 28 | self.pos_start, self.pos_end, 29 | "Second argument must be a list", 30 | exec_ctx 31 | )) 32 | 33 | list_a.elements.extend(list_b.elements) 34 | return RTResult().success(Number.null) -------------------------------------------------------------------------------- /whython/execute/execute_input.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | 7 | from runtime_results import RTResult 8 | 9 | # *################### 10 | # * PRINT 11 | # *################### 12 | 13 | def execute_input_func(self, exec_ctx): 14 | prompt = exec_ctx.symbol_table.get("prompt=0") 15 | if isinstance(prompt, String): 16 | text_input = input(prompt) 17 | else: 18 | text_input = input() 19 | return RTResult().success(String(text_input)) -------------------------------------------------------------------------------- /whython/execute/execute_input_int.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_number import Number 6 | from values.value_string import String 7 | 8 | from runtime_results import RTResult 9 | 10 | # *################### 11 | # * PRINT 12 | # *################### 13 | 14 | def execute_input_int_func(self, exec_ctx): 15 | prompt = exec_ctx.symbol_table.get("prompt=0") 16 | while True: 17 | if isinstance(prompt, String): 18 | text_input = input(prompt) 19 | else: 20 | text_input = input() 21 | try: 22 | text_int = int(text_input) 23 | break 24 | except ValueError: 25 | print(f"'{text_input}' is not an integer. Try again!") 26 | return RTResult().success(Number(text_int)) -------------------------------------------------------------------------------- /whython/execute/execute_is_func.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_function import Function 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | 10 | # *################### 11 | # * IS FUNCTION 12 | # *################### 13 | 14 | def execute_is_func_func(self, exec_ctx): 15 | is_function = isinstance(exec_ctx.symbol_table.get("value"), Function) 16 | return RTResult().success(Number.true if is_function else Number.false) -------------------------------------------------------------------------------- /whython/execute/execute_is_list.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_list import List 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | 10 | # *################### 11 | # * IS LIST 12 | # *################### 13 | 14 | def execute_is_list_func(self, exec_ctx): 15 | is_list = isinstance(exec_ctx.symbol_table.get("value"), List) 16 | return RTResult().success(Number.true if is_list else Number.false) -------------------------------------------------------------------------------- /whython/execute/execute_is_num.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_number import Number 6 | from runtime_results import RTResult 7 | 8 | 9 | # *################### 10 | # * IS NUMBER 11 | # *################### 12 | 13 | def execute_is_num_func(self, exec_ctx): 14 | is_num = isinstance(exec_ctx.symbol_table.get("value"), Number) 15 | return RTResult().success(Number.true if is_num else Number.false) -------------------------------------------------------------------------------- /whython/execute/execute_is_str.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | 10 | # *################### 11 | # * IS STRING 12 | # *################### 13 | 14 | def execute_is_str_func(self, exec_ctx): 15 | is_str = isinstance(exec_ctx.symbol_table.get("value"), String) 16 | return RTResult().success(Number.true if is_str else Number.false) -------------------------------------------------------------------------------- /whython/execute/execute_len.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_list import List 6 | from values.value_string import String 7 | from values.value_number import Number 8 | from runtime_results import RTResult 9 | 10 | from errors import RTError 11 | 12 | # *################### 13 | # * LENGTH 14 | # *################### 15 | 16 | def execute_len_func(self, exec_ctx): 17 | item_ = exec_ctx.symbol_table.get("item") 18 | 19 | if isinstance(item_, List): 20 | return RTResult().success(Number(len(item_.elements))) 21 | elif isinstance(item_, String): 22 | return RTResult().success(Number(len(str(item_.value)))) 23 | else: 24 | return RTResult().failure(RTError( 25 | self.pos_start, self.pos_end, 26 | f"Them item was not a list of a string", 27 | exec_ctx 28 | )) 29 | -------------------------------------------------------------------------------- /whython/execute/execute_pop.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_list import List 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | from errors import RTError 10 | 11 | # *################### 12 | # * POP 13 | # *################### 14 | 15 | def execute_pop_func(self, exec_ctx): 16 | list_ = exec_ctx.symbol_table.get("list") 17 | index = exec_ctx.symbol_table.get("index") 18 | 19 | if not isinstance(list_, List): 20 | return RTResult().failure(RTError( 21 | self.pos_start, self.pos_end, 22 | "First argument must be a list", 23 | exec_ctx 24 | )) 25 | 26 | if not isinstance(index, Number): 27 | return RTResult().failure(RTError( 28 | self.pos_start, self.pos_end, 29 | "Second argument must be an integer", 30 | exec_ctx 31 | )) 32 | 33 | try: 34 | element = list_.elements.pop(index.value) 35 | except IndexError: 36 | return RTResult().failure(RTError( 37 | self.pos_start, self.pos_end, 38 | f"Element at index '{index.value}' could not be removed as it is out of range of the list.", 39 | exec_ctx 40 | )) 41 | return RTResult().success(element) -------------------------------------------------------------------------------- /whython/execute/execute_print.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_number import Number 6 | 7 | from runtime_results import RTResult 8 | 9 | # *################### 10 | # * PRINT 11 | # *################### 12 | 13 | def execute_print_func(self, exec_ctx): 14 | print(str(exec_ctx.symbol_table.get("value"))) 15 | return RTResult().success(Number.ignore) -------------------------------------------------------------------------------- /whython/execute/execute_pyeval.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | from runtime_results import RTResult 7 | from errors import RTError 8 | 9 | 10 | # *################### 11 | # * PYTHON EVAL 12 | # *################### 13 | 14 | def execute_pyeval_func(self, exec_ctx): 15 | code = exec_ctx.symbol_table.get("code") 16 | try: 17 | # code = compile(code.value, "script", "exec") 18 | try: 19 | response = eval(code.value) 20 | except: 21 | response = exec(code.value) 22 | return RTResult().success(String(response)) 23 | except Exception as e: 24 | return RTResult().failure(RTError( 25 | self.pos_start, self.pos_end, 26 | f"The code could not be evaluated. \n\n{e}", 27 | exec_ctx 28 | )) 29 | -------------------------------------------------------------------------------- /whython/execute/execute_randint.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_number import Number 6 | 7 | from runtime_results import RTResult 8 | from errors import RTError 9 | 10 | 11 | # *################### 12 | # * RANDINT 13 | # *################### 14 | 15 | def execute_randint_func(self, exec_ctx): 16 | import random 17 | from_ = exec_ctx.symbol_table.get("from") 18 | to_ = exec_ctx.symbol_table.get("to") 19 | 20 | if not isinstance(from_, Number): 21 | return RTResult().failure(RTError( 22 | self.pos_start, self.pos_end, 23 | "First argument must be a number", 24 | exec_ctx 25 | )) 26 | 27 | if not isinstance(to_, Number): 28 | return RTResult().failure(RTError( 29 | self.pos_start, self.pos_end, 30 | "Second argument must be a number", 31 | exec_ctx 32 | )) 33 | 34 | try: 35 | random_num = random.randint(from_.value, to_.value) 36 | return RTResult().success(Number(random_num)) 37 | except Exception as e: 38 | return RTResult().failure(RTError( 39 | self.pos_start, self.pos_end, 40 | f"Error generating number\n{e}", 41 | exec_ctx 42 | )) -------------------------------------------------------------------------------- /whython/execute/execute_run.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | from errors import RTError 10 | 11 | # *################### 12 | # * RUN 13 | # *################### 14 | 15 | def execute_run_func(self, exec_ctx): 16 | from run import run 17 | fn = exec_ctx.symbol_table.get("filename") 18 | 19 | if not isinstance(fn, String): 20 | return RTResult().failure(RTError( 21 | self.pos_start, self.pos_end, 22 | "Argument must be a string", 23 | exec_ctx 24 | )) 25 | 26 | fn = fn.value 27 | 28 | try: 29 | if not fn.endswith(".whython"): 30 | fn += ".whython" 31 | with open(fn, "r") as f: 32 | script = f.read() 33 | except Exception as e: 34 | return RTResult().failure(RTError( 35 | self.pos_start, self.pos_end, 36 | f"Failed to load script '{fn}'\n{e}", 37 | exec_ctx 38 | )) 39 | 40 | _, error = run(fn, script) 41 | if error: 42 | return RTResult().failure(RTError( 43 | self.pos_start, self.pos_end, 44 | f"Failed to load script '{fn}'\n{error.as_string()}", 45 | exec_ctx 46 | )) 47 | 48 | return RTResult().success(Number.ignore) -------------------------------------------------------------------------------- /whython/execute/execute_to_int.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | from errors import RTError 9 | 10 | 11 | # *################### 12 | # * TO INTEGER 13 | # *################### 14 | 15 | def execute_to_int_func(self, exec_ctx): 16 | value = exec_ctx.symbol_table.get("value") 17 | 18 | if not isinstance(value, String): 19 | return RTResult().failure(RTError( 20 | self.pos_start, self.pos_end, 21 | f"The first argument must be a string.", 22 | exec_ctx 23 | )) 24 | 25 | return RTResult().success(Number(int(value.value))) -------------------------------------------------------------------------------- /whython/execute/execute_to_str.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | from runtime_results import RTResult 7 | 8 | 9 | # *################### 10 | # * TO STRING 11 | # *################### 12 | 13 | def execute_to_str_func(self, exec_ctx): 14 | value = exec_ctx.symbol_table.get("value") 15 | return RTResult().success(String(str(value))) -------------------------------------------------------------------------------- /whython/execute/execute_update_value.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_number import Number 6 | from values.value_list import List 7 | from values.value_string import String 8 | 9 | from runtime_results import RTResult 10 | from errors import RTError 11 | 12 | 13 | # *################### 14 | # * UPDATE VALUE 15 | # *################### 16 | 17 | def execute_update_value_func(self, exec_ctx): 18 | list_ = exec_ctx.symbol_table.get("list") 19 | index_ = exec_ctx.symbol_table.get("index") 20 | value_ = exec_ctx.symbol_table.get("new_value") 21 | 22 | if not isinstance(list_, List): 23 | return RTResult().failure(RTError( 24 | self.pos_start, self.pos_end, 25 | "First argument must be a list", 26 | exec_ctx 27 | )) 28 | 29 | if not isinstance(index_, Number): 30 | return RTResult().failure(RTError( 31 | self.pos_start, self.pos_end, 32 | "Second argument must be a number", 33 | exec_ctx 34 | )) 35 | 36 | if not isinstance(value_, Number) or isinstance(value_, String): 37 | return RTResult().failure(RTError( 38 | self.pos_start, self.pos_end, 39 | "Third argument must be a number or a string", 40 | exec_ctx 41 | )) 42 | 43 | try: 44 | list_.elements[index_.value] = value_.value 45 | except: 46 | return RTResult().failure(RTError( 47 | self.pos_start, self.pos_end, 48 | f"Could not change value of index '{index_.value}' as it is not in range of list.", 49 | exec_ctx 50 | )) 51 | 52 | return RTResult().success(Number.ignore) -------------------------------------------------------------------------------- /whython/lexer.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################## 4 | 5 | from position import * 6 | from tokens import * 7 | from constants import * 8 | from errors import * 9 | 10 | # *################### 11 | # * LEXER 12 | # *################## 13 | 14 | class Lexer: 15 | def __init__(self, fn, text): 16 | self.fn = fn 17 | self.text = text 18 | self.pos = Position(-1, 0, -1, fn, text) 19 | self.current_char = None 20 | self.advance() 21 | 22 | def advance(self): 23 | self.pos.advance(self.current_char) 24 | self.current_char = self.text[self.pos.idx] if self.pos.idx < len(self.text) else None 25 | 26 | def make_tokens(self): 27 | allowed_tokens = { 28 | "+": TT_PLUS, 29 | "/": TT_DIV, 30 | "*": TT_MUL, 31 | "(": TT_LPAREN, 32 | ")": TT_RPAREN, 33 | "^": TT_EXPONENT, 34 | ",": TT_COMMA, 35 | "[": TT_LSQUARE, 36 | "]": TT_RSQUARE 37 | } 38 | tokens = [] 39 | 40 | while self.current_char is not None: 41 | if self.current_char in ' \t': 42 | self.advance() 43 | elif self.current_char == "#": 44 | self.skip_comment() 45 | elif self.current_char in ';\n': 46 | tokens.append(Token(TT_NEWLINE, pos_start=self.pos)) 47 | self.advance() 48 | elif self.current_char in DIGITS: 49 | tokens.append(self.make_number()) 50 | elif self.current_char in LETTERS_DIGITS: 51 | tokens.append(self.make_identifier()) 52 | elif self.current_char == "`": 53 | tokens.append(self.make_code_block()) 54 | elif self.current_char == '"': 55 | tokens.append(self.make_string()) 56 | elif self.current_char == "!": 57 | tok, error = self.make_not_equals() 58 | if error: return [], error 59 | tokens.append(tok) 60 | elif self.current_char == "=": 61 | tokens.append(self.make_equals()) 62 | elif self.current_char == "<": 63 | tokens.append(self.make_less_than()) 64 | elif self.current_char == ">": 65 | tokens.append(self.make_greater_than()) 66 | elif self.current_char == "-": 67 | tokens.append(self.make_minus_or_arrow()) 68 | else: 69 | found_token = False 70 | for allowed_token in allowed_tokens: 71 | if allowed_token == self.current_char: 72 | tokens.append(Token(allowed_tokens[allowed_token], pos_start=self.pos)) 73 | self.advance() 74 | found_token = True 75 | if not found_token: 76 | pos_start = self.pos.copy() 77 | char = self.current_char 78 | self.advance() 79 | return [], IllegalCharError(pos_start, self.pos, f"'{char}'") 80 | 81 | tokens.append(Token(TT_EOF, pos_start=self.pos)) 82 | return tokens, None 83 | 84 | def make_number(self): 85 | num_str: str = '' 86 | dot_count: int = 0 87 | pos_start = self.pos.copy() 88 | 89 | while self.current_char is not None and self.current_char in DIGITS + ".": 90 | if self.current_char == ".": 91 | if dot_count == 1: break 92 | dot_count += 1 93 | num_str += "." 94 | else: 95 | num_str += self.current_char 96 | self.advance() 97 | 98 | if dot_count == 0: 99 | return Token(TT_INT, int(num_str), pos_start, self.pos) 100 | else: 101 | return Token(TT_FLOAT, float(num_str), pos_start, self.pos) 102 | 103 | def make_identifier(self): 104 | id_str = "" 105 | pos_start = self.pos.copy() 106 | 107 | while self.current_char is not None and self.current_char in LETTERS_DIGITS + "_": 108 | id_str += self.current_char 109 | self.advance() 110 | 111 | tok_type = TT_KEYWORD if id_str in KEYWORDS else TT_IDENTIFIER 112 | return Token(tok_type, id_str, pos_start, self.pos) 113 | 114 | def make_not_equals(self): 115 | pos_start = self.pos.copy() 116 | self.advance() 117 | 118 | if self.current_char == "=": 119 | self.advance() 120 | return Token(TT_NE, pos_start=pos_start, pos_end=self.pos), None 121 | 122 | self.advance() 123 | return None, ExpectedCharError(pos_start, self.pos, "'=' (after '!')") 124 | 125 | def make_equals(self): 126 | tok_type = TT_EQ 127 | pos_start = self.pos.copy() 128 | self.advance() 129 | 130 | if self.current_char == "=": 131 | self.advance() 132 | tok_type = TT_EE 133 | 134 | return Token(tok_type, pos_start=pos_start, pos_end=self.pos) 135 | 136 | def make_less_than(self): 137 | tok_type = TT_LT 138 | pos_start = self.pos.copy() 139 | self.advance() 140 | 141 | if self.current_char == "=": 142 | self.advance() 143 | tok_type = TT_LTE 144 | 145 | return Token(tok_type, pos_start=pos_start, pos_end=self.pos) 146 | 147 | def make_greater_than(self): 148 | tok_type = TT_GT 149 | pos_start = self.pos.copy() 150 | self.advance() 151 | 152 | if self.current_char == "=": 153 | self.advance() 154 | tok_type = TT_GTE 155 | 156 | return Token(tok_type, pos_start=pos_start, pos_end=self.pos) 157 | 158 | def make_minus_or_arrow(self): 159 | tok_type = TT_MINUS 160 | pos_start = self.pos.copy() 161 | self.advance() 162 | 163 | if self.current_char == ">": 164 | self.advance() 165 | tok_type = TT_ARROW 166 | 167 | return Token(tok_type, pos_start=pos_start, pos_end=self.pos) 168 | 169 | def make_string(self): 170 | final_string = '' 171 | pos_start = self.pos.copy() 172 | escape_character = False 173 | self.advance() 174 | 175 | escape_characters = { 176 | 'n': '\n', 177 | 't': '\t' 178 | } 179 | 180 | while self.current_char is not None and (self.current_char != '"' or escape_character): 181 | if escape_character: 182 | final_string += escape_characters.get(self.current_char, self.current_char) 183 | escape_character = False 184 | else: 185 | if self.current_char == '\\': 186 | escape_character = True 187 | else: 188 | final_string += self.current_char 189 | self.advance() 190 | 191 | self.advance() 192 | return Token(TT_STRING, final_string, pos_start, self.pos) 193 | 194 | def make_code_block(self): 195 | final_string = "" 196 | pos_start = self.pos.copy() 197 | self.advance() 198 | 199 | while self.current_char is not None and self.current_char != "`": 200 | if self.current_char == ";": 201 | final_string += "\n" 202 | else: 203 | final_string += self.current_char 204 | self.advance() 205 | 206 | self.advance() 207 | return Token(TT_STRING, final_string, pos_start, self.pos) 208 | 209 | def skip_comment(self): 210 | self.advance() 211 | 212 | while self.current_char != "\n" and self.current_char is not None: 213 | self.advance() 214 | 215 | self.advance() 216 | -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_binop.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_binop.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_binop.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_binop.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_break.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_break.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_break.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_break.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_call.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_call.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_call.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_call.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_continue.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_continue.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_continue.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_continue.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_for.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_for.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_for.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_for.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_funcdef.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_funcdef.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_funcdef.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_funcdef.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_if.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_if.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_if.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_if.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_list.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_list.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_list.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_list.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_number.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_number.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_number.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_number.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_return.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_return.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_return.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_return.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_string.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_string.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_string.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_string.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_unaryop.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_unaryop.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_unaryop.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_unaryop.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_varaccess.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_varaccess.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_varaccess.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_varaccess.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_varassign.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_varassign.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_varassign.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_varassign.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_while.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_while.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/node_while.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/node_while.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/nodes.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/nodes.cpython-310.pyc -------------------------------------------------------------------------------- /whython/nodes_/__pycache__/nodes.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/nodes_/__pycache__/nodes.cpython-39.pyc -------------------------------------------------------------------------------- /whython/nodes_/node_binop.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * BINARY OPERATION 3 | # * NODE 4 | # *################### 5 | 6 | class BinOpNode: 7 | def __init__(self, left_node, op_tok, right_node): 8 | self.left_node = left_node 9 | self.op_tok = op_tok 10 | self.right_node = right_node 11 | 12 | self.pos_start = self.left_node.pos_start 13 | self.pos_end = self.right_node.pos_end 14 | 15 | def __repr__(self): 16 | return f"({self.left_node}, {self.op_tok}, {self.right_node})" 17 | -------------------------------------------------------------------------------- /whython/nodes_/node_break.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * BREAK NODE 3 | # *################### 4 | 5 | class BreakNode: 6 | def __init__(self, pos_start, pos_end): 7 | self.pos_start = pos_start 8 | self.pos_end = pos_end -------------------------------------------------------------------------------- /whython/nodes_/node_call.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * CALL NODE 3 | # *################### 4 | 5 | class CallNode: 6 | def __init__(self, node_to_call, arg_nodes): 7 | self.node_to_call = node_to_call 8 | self.arg_nodes = arg_nodes 9 | 10 | self.pos_start = self.node_to_call.pos_start 11 | 12 | if len(self.arg_nodes) > 0: 13 | self.pos_end = self.arg_nodes[len(self.arg_nodes) - 1].pos_end 14 | else: 15 | self.pos_end = self.node_to_call.pos_end -------------------------------------------------------------------------------- /whython/nodes_/node_continue.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * CONTINUE NODE 3 | # *################### 4 | 5 | class ContinueNode: 6 | def __init__(self, pos_start, pos_end): 7 | self.pos_start = pos_start 8 | self.pos_end = pos_end 9 | -------------------------------------------------------------------------------- /whython/nodes_/node_for.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * FOR NODE 3 | # *################### 4 | 5 | class ForNode: 6 | def __init__(self, var_name_tok, start_value_node, end_value_node, step_value_node, body_node, should_return_null): 7 | self.var_name_tok = var_name_tok 8 | self.start_value_node = start_value_node 9 | self.end_value_node = end_value_node 10 | self.step_value_node = step_value_node 11 | self.body_node = body_node 12 | self.should_return_null = should_return_null 13 | 14 | self.pos_start = self.var_name_tok.pos_start 15 | self.pos_end = self.body_node.pos_end 16 | -------------------------------------------------------------------------------- /whython/nodes_/node_funcdef.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * FUNCTION DEFINITION 3 | # * NODE 4 | # *################### 5 | 6 | class FuncDefNode: 7 | def __init__(self, var_name_tok, arg_name_toks, body_node, should_auto_return): 8 | self.var_name_tok = var_name_tok 9 | self.arg_name_toks = arg_name_toks 10 | self.body_node = body_node 11 | self.should_auto_return = should_auto_return 12 | 13 | if self.var_name_tok: 14 | self.pos_start = self.var_name_tok.pos_start 15 | elif len(self.arg_name_toks) > 0: 16 | self.pos_start = self.arg_name_toks[0].pos_start 17 | else: 18 | self.pos_start = self.body_node.pos_start 19 | 20 | self.pos_end = self.body_node.pos_end -------------------------------------------------------------------------------- /whython/nodes_/node_if.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IF NODE 3 | # *################### 4 | 5 | class IfNode: 6 | def __init__(self, cases, else_case): 7 | self.cases = cases 8 | self.else_case = else_case 9 | 10 | self.pos_start = self.cases[0][0].pos_start 11 | self.pos_end = (self.else_case or self.cases[len(cases) - 1])[0].pos_end -------------------------------------------------------------------------------- /whython/nodes_/node_list.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * LIST NODE 3 | # *################### 4 | 5 | class ListNode: 6 | def __init__(self, element_nodes, pos_start, pos_end): 7 | self.element_nodes = element_nodes 8 | 9 | self.pos_start = pos_start 10 | self.pos_end = pos_end 11 | -------------------------------------------------------------------------------- /whython/nodes_/node_number.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * NUMBER NODE 3 | # *################### 4 | 5 | class NumberNode: 6 | def __init__(self, tok): 7 | self.tok = tok 8 | 9 | self.pos_start = self.tok.pos_start 10 | self.pos_end = self.tok.pos_end 11 | 12 | def __repr__(self): 13 | return f"{self.tok}" -------------------------------------------------------------------------------- /whython/nodes_/node_return.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * RETURN NODE 3 | # *################### 4 | 5 | class ReturnNode: 6 | def __init__(self, node_to_return, pos_start, pos_end): 7 | self.node_to_return = node_to_return 8 | self.pos_start = pos_start 9 | self.pos_end = pos_end 10 | -------------------------------------------------------------------------------- /whython/nodes_/node_string.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * STRING 3 | # *################### 4 | 5 | class StringNode: 6 | def __init__(self, tok): 7 | self.tok = tok 8 | 9 | self.pos_start = self.tok.pos_start 10 | self.pos_end = self.tok.pos_end 11 | 12 | def __repr__(self): 13 | return f"{self.tok}" -------------------------------------------------------------------------------- /whython/nodes_/node_unaryop.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * UNARY OPERATION 3 | # * NODE 4 | # *################### 5 | 6 | class UnaryOpNode: 7 | def __init__(self, op_tok, node): 8 | self.op_tok = op_tok 9 | self.node = node 10 | 11 | self.pos_start = self.op_tok.pos_start 12 | self.pos_end = node.pos_end 13 | 14 | def __repr__(self): 15 | return f"({self.op_tok}, {self.node})" -------------------------------------------------------------------------------- /whython/nodes_/node_varaccess.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * VAR ACCESS NODE 3 | # *################### 4 | 5 | class VarAccessNode: 6 | def __init__(self, var_name_tok): 7 | self.var_name_tok = var_name_tok 8 | 9 | self.pos_start = self.var_name_tok.pos_start 10 | self.pos_end = self.var_name_tok.pos_end 11 | -------------------------------------------------------------------------------- /whython/nodes_/node_varassign.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * VAR ASSIGN NODE 3 | # *################### 4 | 5 | class VarAssignNode: 6 | def __init__(self, var_name_tok, value_node): 7 | self.var_name_tok = var_name_tok 8 | self.value_node = value_node 9 | 10 | self.pos_start = self.var_name_tok.pos_start 11 | self.pos_end = self.var_name_tok.pos_end -------------------------------------------------------------------------------- /whython/nodes_/node_while.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * WHILE NODE 3 | # *################### 4 | 5 | class WhileNode: 6 | def __init__(self, condition_node, body_node, should_return_null): 7 | self.condition_node = condition_node 8 | self.body_node = body_node 9 | self.should_return_null = should_return_null 10 | 11 | self.pos_start = self.condition_node.pos_start 12 | self.pos_end = self.body_node.pos_end 13 | -------------------------------------------------------------------------------- /whython/nodes_/nodes.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * NODES 3 | # *################### 4 | 5 | from nodes_.node_binop import BinOpNode 6 | from nodes_.node_break import BreakNode 7 | from nodes_.node_call import CallNode 8 | from nodes_.node_continue import ContinueNode 9 | from nodes_.node_for import ForNode 10 | from nodes_.node_funcdef import FuncDefNode 11 | from nodes_.node_if import IfNode 12 | from nodes_.node_list import ListNode 13 | from nodes_.node_number import NumberNode 14 | from nodes_.node_return import ReturnNode 15 | from nodes_.node_string import StringNode 16 | from nodes_.node_unaryop import UnaryOpNode 17 | from nodes_.node_varaccess import VarAccessNode 18 | from nodes_.node_varassign import VarAssignNode 19 | from nodes_.node_while import WhileNode -------------------------------------------------------------------------------- /whython/position.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * POSITION 3 | # *################### 4 | 5 | class Position: 6 | def __init__(self, idx, ln, col, fn, ftxt): 7 | self.idx = idx 8 | self.ln = ln 9 | self.col = col 10 | self.fn = fn 11 | self.ftxt = ftxt 12 | 13 | def advance(self, current_char=None): 14 | self.idx += 1 15 | self.col += 1 16 | 17 | if current_char == "\n": 18 | self.ln += 1 19 | self.col = 0 20 | 21 | return self 22 | 23 | def copy(self): 24 | return Position(self.idx, self.ln, self.col, self.fn, self.ftxt) 25 | -------------------------------------------------------------------------------- /whython/run.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from interpreter import * 6 | from context import Context 7 | from editable_.editable import global_symbol_table 8 | 9 | # *################### 10 | # * RUN 11 | # *################### 12 | 13 | def run(fn, text): 14 | # Generate tokens 15 | lexer = Lexer(fn, text) 16 | tokens, error = lexer.make_tokens() 17 | if error: return None, error 18 | 19 | # Generate AST 20 | parser = Parser(tokens) 21 | ast = parser.parse() 22 | if ast.error: return None, ast.error 23 | 24 | # Run program 25 | interpreter = Interpreter() 26 | context = Context('') 27 | context.symbol_table = global_symbol_table 28 | result = interpreter.visit(ast.node, context) 29 | 30 | return result.value, result.error 31 | -------------------------------------------------------------------------------- /whython/runtime_results.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * RUNTIME RESULTS 3 | # *################### 4 | 5 | class RTResult: 6 | def __init__(self): 7 | self.value = None 8 | self.error = None 9 | self.func_return_value = None 10 | self.loop_should_continue = False 11 | self.loop_should_break = False 12 | self.reset() 13 | 14 | def reset(self): 15 | self.value = None 16 | self.error = None 17 | self.func_return_value = None 18 | self.loop_should_continue = False 19 | self.loop_should_break = False 20 | 21 | def register(self, res): 22 | if res.error: self.error = res.error 23 | self.func_return_value = res.func_return_value 24 | self.loop_should_continue = res.loop_should_continue 25 | self.loop_should_break = res.loop_should_break 26 | return res.value 27 | 28 | def success(self, value): 29 | self.reset() 30 | self.value = value 31 | return self 32 | 33 | def success_return(self, value): 34 | self.reset() 35 | self.func_return_value = value 36 | return self 37 | 38 | def success_continue(self): 39 | self.reset() 40 | self.loop_should_continue = True 41 | return self 42 | 43 | def success_break(self): 44 | self.reset() 45 | self.loop_should_break = True 46 | return self 47 | 48 | def failure(self, error): 49 | self.reset() 50 | self.error = error 51 | return self 52 | 53 | def should_return(self): 54 | return ( 55 | self.error or 56 | self.func_return_value or 57 | self.loop_should_continue or 58 | self.loop_should_break 59 | ) 60 | -------------------------------------------------------------------------------- /whython/shell.py: -------------------------------------------------------------------------------- 1 | import run as whython 2 | import os 3 | 4 | def main(): 5 | welcome() 6 | while True: 7 | try: 8 | text = input("whython > ") 9 | if text.strip() == "": continue 10 | if text.strip() == "exit": print("Goodbye!"); return 11 | result, error = whython.run("", text) 12 | 13 | if error: print(error.as_string()) 14 | elif result: 15 | for element in result.elements: 16 | try: 17 | if element.value is not None: 18 | print(element) 19 | except AttributeError: 20 | pass 21 | except KeyboardInterrupt: 22 | print("\nType 'Exit' to leave shell.") 23 | 24 | def welcome(): 25 | print("Welcome to whython v1.3") 26 | 27 | # Get info about saves 28 | editing_location = os.path.abspath("editable_/editable.py") 29 | print(f"Current save location for editing func/var names is: {editing_location}\n") 30 | 31 | if __name__ == "__main__": 32 | main() -------------------------------------------------------------------------------- /whython/strings_with_arrows.py: -------------------------------------------------------------------------------- 1 | def string_with_arrows(text, pos_start, pos_end): 2 | result = '' 3 | 4 | # Calculate indices 5 | idx_start = max(text.rfind('\n', 0, pos_start.idx), 0) 6 | idx_end = text.find('\n', idx_start + 1) 7 | if idx_end < 0: idx_end = len(text) 8 | 9 | # Generate each line 10 | line_count = pos_end.ln - pos_start.ln + 1 11 | for i in range(line_count): 12 | # Calculate line columns 13 | line = text[idx_start:idx_end] 14 | col_start = pos_start.col if i == 0 else 0 15 | col_end = pos_end.col if i == line_count - 1 else len(line) - 1 16 | 17 | # Append to result 18 | result += line + '\n' 19 | result += ' ' * col_start + '^' * (col_end - col_start) 20 | 21 | # Re-calculate indices 22 | idx_start = idx_end 23 | idx_end = text.find('\n', idx_start + 1) 24 | if idx_end < 0: idx_end = len(text) 25 | 26 | return result.replace('\t', '') -------------------------------------------------------------------------------- /whython/symbol_table.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * SYMBOL TABLE 3 | # *################### 4 | 5 | class SymbolTable: 6 | def __init__(self, parent=None): 7 | self.symbols = {} 8 | self.parent = parent 9 | 10 | def get(self, name): 11 | value = self.symbols.get(name, None) 12 | if value is None and self.parent: 13 | return self.parent.get(name) 14 | return value 15 | 16 | def set(self, name, value): 17 | self.symbols[name] = value 18 | 19 | def remove(self, name): 20 | del self.symbols[name] -------------------------------------------------------------------------------- /whython/tokens.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from editable_.editable import KEYWORDS_DICT 6 | 7 | # *################### 8 | # * TOKENS 9 | # * DON'T EDIT THESE! 10 | # *################### 11 | 12 | TT_INT = "INT" 13 | TT_FLOAT = "FLOAT" 14 | TT_STRING = "STRING" 15 | 16 | TT_PLUS = "PLUS" 17 | TT_MINUS = "MINUS" 18 | TT_MUL = "MUL" 19 | TT_DIV = "DIV" 20 | TT_EXPONENT = "EXPONENT" 21 | 22 | TT_IDENTIFIER = "IDENTIFIER" 23 | TT_KEYWORD = "KEYWORD" 24 | TT_EQ = "EQ" 25 | 26 | TT_EE = "EE" 27 | TT_NE = "NE" 28 | TT_LT = "LT" 29 | TT_GT = "GT" 30 | TT_LTE = "LTE" 31 | TT_GTE = "GTE" 32 | 33 | TT_COMMA = "COMMA" 34 | TT_ARROW = "ARROW" 35 | TT_NEWLINE = "NEWLINE" 36 | 37 | TT_LPAREN = "LPAREN" 38 | TT_RPAREN = "RPAREN" 39 | TT_LSQUARE = "[" 40 | TT_RSQUARE = "]" 41 | 42 | TT_EOF = "EOF" 43 | 44 | KEYWORDS = [] 45 | for keyword_index in KEYWORDS_DICT: 46 | KEYWORDS.append(KEYWORDS_DICT[keyword_index]) 47 | 48 | class Token: 49 | def __init__(self, type_, value=None, pos_start=None, pos_end=None): 50 | self.type = type_ 51 | self.value = value 52 | 53 | if pos_start: 54 | self.pos_start = pos_start.copy() 55 | self.pos_end = pos_start.copy() 56 | self.pos_end.advance() 57 | 58 | if pos_end: 59 | self.pos_end = pos_end 60 | 61 | def matches(self, type_, value): 62 | return self.type == type_ and self.value == value 63 | 64 | def __repr__(self): 65 | if self.value: return f'{self.type}:{self.value}' 66 | return f'{self.type}' -------------------------------------------------------------------------------- /whython/values/__pycache__/value_basefunction.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_basefunction.cpython-310.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_basefunction.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_basefunction.cpython-39.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_builtinfunc.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_builtinfunc.cpython-310.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_builtinfunc.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_builtinfunc.cpython-39.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_function.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_function.cpython-310.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_function.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_function.cpython-39.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_list.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_list.cpython-310.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_list.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_list.cpython-39.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_number.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_number.cpython-310.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_number.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_number.cpython-39.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_string.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_string.cpython-310.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_string.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_string.cpython-39.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_values.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_values.cpython-310.pyc -------------------------------------------------------------------------------- /whython/values/__pycache__/value_values.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython/values/__pycache__/value_values.cpython-39.pyc -------------------------------------------------------------------------------- /whython/values/value_basefunction.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_values import Value 6 | from values.value_number import Number 7 | 8 | from context import Context 9 | from symbol_table import SymbolTable 10 | from runtime_results import RTResult 11 | from errors import RTError 12 | 13 | # *################### 14 | # * BASE FUNCTION 15 | # *################### 16 | 17 | class BaseFunction(Value): 18 | def __init__(self, name): 19 | super().__init__() 20 | self.name = name or "" 21 | self.args = [] 22 | self.arg_names = [] 23 | 24 | def generate_new_context(self): 25 | new_context = Context(self.name, self.context, self.pos_start) 26 | new_context.symbol_table = SymbolTable(new_context.parent.symbol_table) 27 | return new_context 28 | 29 | def check_args(self): 30 | res = RTResult() 31 | 32 | for i in range(len(self.arg_names)): 33 | arg = self.arg_names[i] 34 | if "=" in arg: 35 | try: 36 | _ = self.args[i] 37 | except: 38 | try: 39 | self.args.append(Number(int(arg.split("=")[-1]))) 40 | except: 41 | self.args.append(arg.split("=")[-1]) 42 | 43 | if len(self.args) > len(self.arg_names): 44 | return res.failure(RTError( 45 | self.pos_start, self.pos_end, 46 | f"{len(self.args) - len(self.arg_names)} too many args passed into {self}", 47 | self.context 48 | )) 49 | 50 | if len(self.args) < len(self.arg_names): 51 | return res.failure(RTError( 52 | self.pos_start, self.pos_end, 53 | f"{len(self.arg_names) - len(self.args)} too few args passed into {self}", 54 | self.context 55 | )) 56 | 57 | return res.success(None) 58 | 59 | def populate_args(self, exec_ctx): 60 | for i in range(len(self.args)): 61 | arg_name = self.arg_names[i] 62 | arg_value = self.args[i] 63 | arg_value.set_context(exec_ctx) 64 | exec_ctx.symbol_table.set(arg_name, arg_value) 65 | 66 | def check_and_populate_args(self, arg_names, args, exec_ctx): 67 | res = RTResult() 68 | self.arg_names = arg_names 69 | self.args = args 70 | res.register(self.check_args()) 71 | if res.should_return(): return res 72 | self.populate_args(exec_ctx) 73 | return res.success(None) -------------------------------------------------------------------------------- /whython/values/value_function.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_basefunction import BaseFunction 6 | from values.value_number import Number 7 | 8 | from runtime_results import RTResult 9 | 10 | # *################### 11 | # * FUNCTION 12 | # *################### 13 | 14 | class Function(BaseFunction): 15 | def __init__(self, name, body_node, arg_names, should_auto_return): 16 | super().__init__(name) 17 | self.body_node = body_node 18 | self.arg_names = arg_names 19 | self.should_auto_return = should_auto_return 20 | 21 | def execute(self, args): 22 | from interpreter import Interpreter 23 | res = RTResult() 24 | interpreter = Interpreter() 25 | exec_ctx = self.generate_new_context() 26 | 27 | res.register(self.check_and_populate_args(self.arg_names, args, exec_ctx)) 28 | if res.should_return(): return res 29 | 30 | value = res.register(interpreter.visit(self.body_node, exec_ctx)) 31 | if res.should_return() and res.func_return_value is None: return res 32 | 33 | ret_value = (value if self.should_auto_return else None) or res.func_return_value or Number.null 34 | return res.success(ret_value) 35 | 36 | def copy(self): 37 | copy = Function(self.name, self.body_node, self.arg_names, self.should_auto_return) 38 | copy.set_context(self.context) 39 | copy.set_pos(self.pos_start, self.pos_end) 40 | return copy 41 | 42 | def __repr__(self): 43 | return f"" -------------------------------------------------------------------------------- /whython/values/value_list.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_values import Value 6 | from values.value_number import Number 7 | 8 | from errors import RTError 9 | 10 | # *################### 11 | # * STRING 12 | # *################### 13 | 14 | class List(Value): 15 | """ 16 | List class 17 | Examples: 18 | -------------------------- 19 | Using "+" will append to the list 20 | 21 | var list = [1, 2, 3] 22 | list + 4 -> [1, 2, 3, 4] 23 | -------------------------- 24 | Using "-" will pop from the list at index 25 | 26 | var list = [1, 2, 3] 27 | var popped = list - 1 -> [1, 3] 28 | popped: 2 29 | -------------------------- 30 | Using "*" will extend 2 lists 31 | 32 | var list_a = [1, 2, 3] 33 | var list_b = [4, 5, 6] 34 | 35 | list_a*list_b -> [1, 2, 3, 4, 5, 6] 36 | list_a -> [1, 2, 3, 4, 5, 6] 37 | -------------------------- 38 | Using "/" will get the item at that index 39 | 40 | var list = [1, 2, 3] 41 | list/1 -> 2 42 | """ 43 | def __init__(self, elements): 44 | super().__init__() 45 | self.elements = elements 46 | 47 | def added_to(self, other): 48 | new_list = self.copy() 49 | new_list.elements.append(other) 50 | return new_list, None 51 | 52 | def multiplied_by(self, other): 53 | if isinstance(other, List): 54 | new_list = self.copy() 55 | new_list.elements.extend(other.elements) 56 | return new_list, None 57 | else: 58 | return None, Value.illegal_operation(self, other) 59 | 60 | def subtracted_by(self, other): 61 | if isinstance(other, Number): 62 | new_list = self.copy() 63 | try: 64 | new_list.elements.pop(other.value) 65 | return new_list, None 66 | except: 67 | return None, RTError( 68 | other.pos_start, other.pos_end, 69 | 'Element at this index could not be removed from list because index is out of bounds', 70 | self.context 71 | ) 72 | else: 73 | return None, Value.illegal_operation(self, other) 74 | 75 | def divided_by(self, other): 76 | if isinstance(other, Number): 77 | try: 78 | return self.elements[other.value], None 79 | except: 80 | return None, RTError( 81 | other.pos_start, other.pos_end, 82 | 'Element at this index could not be retrieved from list because index is out of bounds', 83 | self.context 84 | ) 85 | else: 86 | return None, Value.illegal_operation(self, other) 87 | 88 | def copy(self): 89 | copy = List(self.elements) 90 | copy.set_pos(self.pos_start, self.pos_end) 91 | copy.set_context(self.context) 92 | return copy 93 | 94 | def __str__(self): 95 | return f"{', '.join([str(x) for x in self.elements])}" 96 | 97 | def __repr__(self): 98 | return f"[{', '.join([str(x) for x in self.elements])}]" -------------------------------------------------------------------------------- /whython/values/value_number.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_values import Value 6 | from errors import RTError 7 | 8 | import math 9 | 10 | # *################### 11 | # * NUMBER 12 | # *################### 13 | 14 | class Number(Value): 15 | def __init__(self, value): 16 | super().__init__() 17 | self.value = value 18 | 19 | def added_to(self, other): 20 | if isinstance(other, Number): 21 | return Number(self.value + other.value).set_context(self.context), None 22 | else: 23 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 24 | 25 | def subtracted_by(self, other): 26 | if isinstance(other, Number): 27 | return Number(self.value - other.value).set_context(self.context), None 28 | else: 29 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 30 | 31 | def multiplied_by(self, other): 32 | if isinstance(other, Number): 33 | return Number(self.value * other.value).set_context(self.context), None 34 | else: 35 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 36 | 37 | def exponent_by(self, other): 38 | if isinstance(other, Number): 39 | return Number(self.value ** other.value).set_context(self.context), None 40 | else: 41 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 42 | 43 | def get_comparison_eq(self, other): 44 | if isinstance(other, Number): 45 | return Number(int(self.value == other.value)).set_context(self.context), None 46 | else: 47 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 48 | 49 | def get_comparison_ne(self, other): 50 | if isinstance(other, Number): 51 | return Number(int(self.value != other.value)).set_context(self.context), None 52 | else: 53 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 54 | 55 | def get_comparison_lt(self, other): 56 | if isinstance(other, Number): 57 | return Number(int(self.value < other.value)).set_context(self.context), None 58 | else: 59 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 60 | 61 | def get_comparison_lte(self, other): 62 | if isinstance(other, Number): 63 | return Number(int(self.value <= other.value)).set_context(self.context), None 64 | else: 65 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 66 | 67 | def get_comparison_gt(self, other): 68 | if isinstance(other, Number): 69 | return Number(int(self.value > other.value)).set_context(self.context), None 70 | else: 71 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 72 | 73 | def get_comparison_gte(self, other): 74 | if isinstance(other, Number): 75 | return Number(int(self.value >= other.value)).set_context(self.context), None 76 | else: 77 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 78 | 79 | def anded_by(self, other): 80 | if isinstance(other, Number): 81 | return Number(int(self.value and other.value)).set_context(self.context), None 82 | else: 83 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 84 | 85 | def ored_by(self, other): 86 | if isinstance(other, Number): 87 | return Number(int(self.value or other.value)).set_context(self.context), None 88 | else: 89 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 90 | 91 | def notted(self): 92 | return Number(1 if self.value == 0 else 0).set_context(self.context), None 93 | 94 | def divided_by(self, other): 95 | if isinstance(other, Number): 96 | if other.value == 0: 97 | return None, RTError( 98 | other.pos_start, other.pos_end, 99 | "Division by zero.", 100 | self.context 101 | ) 102 | 103 | return Number(self.value / other.value).set_context(self.context), None 104 | else: 105 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 106 | 107 | def copy(self): 108 | copy = Number(self.value) 109 | copy.set_pos(self.pos_start, self.pos_end) 110 | copy.set_context(self.context) 111 | return copy 112 | 113 | def is_true(self): 114 | return self.value != 0 115 | 116 | def __repr__(self): 117 | return str(self.value) 118 | 119 | Number.null = Number(0) 120 | Number.ignore = Number(None) 121 | Number.false = Number(0) 122 | Number.true = Number(1) 123 | Number.pi = Number(math.pi) -------------------------------------------------------------------------------- /whython/values/value_string.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_values import Value 6 | from values.value_number import Number 7 | 8 | # *################### 9 | # * STRING 10 | # *################### 11 | 12 | 13 | class String(Value): 14 | def __init__(self, value): 15 | super().__init__() 16 | self.value = value 17 | 18 | def added_to(self, other): 19 | if isinstance(other, String): 20 | return String(self.value + other.value).set_context(self.context), None 21 | else: 22 | return None, Value.illegal_operation(self, other) 23 | 24 | def multiplied_by(self, other): 25 | if isinstance(other, Number): 26 | return String(self.value * other.value).set_context(self.context), None 27 | else: 28 | return None, Value.illegal_operation(self, other) 29 | 30 | def is_true(self): 31 | return len(self.value) > 0 32 | 33 | def copy(self): 34 | copy = String(self.value) 35 | copy.set_pos(self.pos_start, self.pos_end) 36 | copy.set_context(self.context) 37 | return copy 38 | 39 | def __str__(self): 40 | return self.value 41 | 42 | def __repr__(self): 43 | return f'"{self.value}"' -------------------------------------------------------------------------------- /whython/values/value_values.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from errors import RTError 6 | from runtime_results import RTResult 7 | 8 | # *################### 9 | # * VALUE 10 | # *################### 11 | 12 | class Value: 13 | def __init__(self): 14 | self.set_pos() 15 | self.set_context() 16 | 17 | self.pos_start = None 18 | self.pos_end = None 19 | self.context = None 20 | 21 | def set_pos(self, pos_start=None, pos_end=None): 22 | self.pos_start = pos_start 23 | self.pos_end = pos_end 24 | return self 25 | 26 | def set_context(self, context=None): 27 | self.context = context 28 | return self 29 | 30 | def added_to(self, other): 31 | return None, self.illegal_operation(other) 32 | 33 | def subbed_by(self, other): 34 | return None, self.illegal_operation(other) 35 | 36 | def multed_by(self, other): 37 | return None, self.illegal_operation(other) 38 | 39 | def dived_by(self, other): 40 | return None, self.illegal_operation(other) 41 | 42 | def powed_by(self, other): 43 | return None, self.illegal_operation(other) 44 | 45 | def get_comparison_eq(self, other): 46 | return None, self.illegal_operation(other) 47 | 48 | def get_comparison_ne(self, other): 49 | return None, self.illegal_operation(other) 50 | 51 | def get_comparison_lt(self, other): 52 | return None, self.illegal_operation(other) 53 | 54 | def get_comparison_gt(self, other): 55 | return None, self.illegal_operation(other) 56 | 57 | def get_comparison_lte(self, other): 58 | return None, self.illegal_operation(other) 59 | 60 | def get_comparison_gte(self, other): 61 | return None, self.illegal_operation(other) 62 | 63 | def anded_by(self, other): 64 | return None, self.illegal_operation(other) 65 | 66 | def ored_by(self, other): 67 | return None, self.illegal_operation(other) 68 | 69 | def notted(self): 70 | return None, self.illegal_operation() 71 | 72 | def execute(self, args): 73 | return RTResult().failure(self.illegal_operation()) 74 | 75 | def copy(self): 76 | raise Exception('No copy method defined') 77 | 78 | def is_true(self): 79 | return False 80 | 81 | def illegal_operation(self, other=None): 82 | if not other: other = self 83 | return RTError( 84 | self.pos_start, other.pos_end, 85 | 'Illegal operation', 86 | self.context 87 | ) -------------------------------------------------------------------------------- /whython_emoji/__pycache__/constants.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/constants.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/constants.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/constants.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/context.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/context.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/context.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/context.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/errors.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/errors.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/errors.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/errors.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/interpreter.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/interpreter.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/interpreter.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/interpreter.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/lexer.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/lexer.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/lexer.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/lexer.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/parser_.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/parser_.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/parser_.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/parser_.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/position.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/position.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/position.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/position.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/run.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/run.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/run.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/run.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/runtime_results.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/runtime_results.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/runtime_results.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/runtime_results.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/strings_with_arrows.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/strings_with_arrows.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/strings_with_arrows.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/strings_with_arrows.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/symbol_table.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/symbol_table.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/symbol_table.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/symbol_table.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/tokens.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/tokens.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/__pycache__/tokens.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/__pycache__/tokens.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/constants.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | import string 6 | import emoji 7 | 8 | # *################### 9 | # * CONSTANTS 10 | # *################### 11 | 12 | emojis = [] 13 | for emoji_ in emoji.EMOJI_UNICODE["en"]: 14 | emojis.append(emoji.EMOJI_UNICODE["en"][emoji_]) 15 | 16 | DIGITS = '0123456789' 17 | LETTERS = string.ascii_letters 18 | EMOJIS = "".join(emojis) 19 | LETTERS_DIGITS = LETTERS + DIGITS + EMOJIS 20 | QUOTES = "'\"" -------------------------------------------------------------------------------- /whython_emoji/context.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * CONTEXT 3 | # *################### 4 | 5 | class Context: 6 | def __init__(self, display_name, parent=None, parent_entry_pos=None): 7 | self.display_name = display_name 8 | self.parent = parent 9 | self.parent_entry_pos = parent_entry_pos 10 | self.symbol_table = None -------------------------------------------------------------------------------- /whython_emoji/docs/docs.md: -------------------------------------------------------------------------------- 1 | # If statements 2 | ``` 3 | if value == value do 4 | # do something 5 | elif value == other_value do 6 | # do something 7 | else 8 | # do something 9 | end 10 | ``` 11 | 12 | # While loop 13 | ``` 14 | while value == value do 15 | # do something 16 | break/return/continue 17 | end 18 | ``` 19 | 20 | # For loop 21 | ``` 22 | for var i = 0 to 5 step 1 do 23 | print(i) 24 | break/return/continue 25 | end 26 | ``` -------------------------------------------------------------------------------- /whython_emoji/docs/grammar.txt: -------------------------------------------------------------------------------- 1 | (LESS) 2 | 3 | statements : NEWLINE* statement (NEWLINE+ statement)* NEWLINE* 4 | 5 | statement : KEYWORD:return expr? 6 | : KEYWORD:continue 7 | : KEYWORD:break 8 | : expr 9 | 10 | expr : KEYWORD:var IDENTIFIER EQ expr 11 | : comp_expr ((KEYWORD:and | KEYWORD:or | KEYWORD:not) comp_expr)* 12 | 13 | comp_expr : NOT comp_expr 14 | : arith_expr ((EE | LT | LTE | GT | GTE) arith_expr)* 15 | 16 | arith_expr : term ((PLUS | MINUS) term)* 17 | 18 | term : factor ((MUL | DIV) factor)* 19 | 20 | factor : (PLUS | MINUS) factor 21 | : power 22 | 23 | exponent : call (EXPONENT factor)* 24 | 25 | call : atom (LPAREN (expr (COMMA expr)*)? RPAREN)? 26 | 27 | atom : INT | FLOAT | STRING | IDENTIFIER 28 | : LPAREN expr RPAREN 29 | : list_expr 30 | : if_expr 31 | : for_expr 32 | : while_expr 33 | : func_def 34 | 35 | list_expr : LSQUARE (expr (COMMA expr)*)? RSQUARE 36 | 37 | if_expr : KEYWORD:if expr KEYWORD:then 38 | (statement if_expr_b | if_expr_c?) 39 | | (NEWLINE statements KEYWORD:end if_expr_b | if_expr_c) 40 | 41 | if_expr_b : KEYWORD:elif expr KEYWORD:then 42 | (statement if_expr_b | if_expr_c?) 43 | | (NEWLINE statements KEYWORD:end if_expr_b | if_expr_c) 44 | 45 | if_expr_c : KEYWORD:else 46 | statement 47 | | (NEWLINE statements KEYWORD:end) 48 | 49 | for_expr : KEYWORD:for KEYWORD:var IDENTIFIER EQ expr KEYWORD:to expr 50 | (KEYWORD:STEP expr)? KEYWORD:then 51 | statement 52 | | (NEWLINE statements KEYWORD:end) 53 | 54 | while_expr : KEYWORD:while expr KEYWORD:then 55 | statement 56 | | (NEWLINE statements KEYWORD:end) 57 | 58 | func_def : KEYWORD:func IDENTIFIER? 59 | LPAREN (IDENTIFIER (COMMA IDENTIFIER)*)? RPAREN 60 | (ARROW expr) 61 | | (NEWLINE statements KEYWORD:end) 62 | 63 | (MORE) 64 | -------------------------------------------------------------------------------- /whython_emoji/docs/todo.txt: -------------------------------------------------------------------------------- 1 | DONE: 2 | print 3 | input 4 | input_int 5 | clear 6 | exit 7 | update_value 8 | is_num 9 | is_string 10 | is_list 11 | is_function 12 | append 13 | pop 14 | extend 15 | run 16 | length 17 | randint 18 | to_str 19 | to_int 20 | use python code 21 | TODO: 22 | make builtins easier 23 | -------------------------------------------------------------------------------- /whython_emoji/editable_/__pycache__/editable.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/editable_/__pycache__/editable.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/editable_/__pycache__/editable.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/editable_/__pycache__/editable.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/editable_/editable.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from symbol_table import SymbolTable 6 | 7 | from values.value_builtinfunc import BuiltInFunction 8 | from values.value_number import Number 9 | 10 | # *################### 11 | # * KEYWORDS 12 | # * YOU CAN EDIT THIS! 13 | # *################### 14 | 15 | """ 16 | How to use: 17 | 18 | Change the value in the dict (right hand side) to the new value you want it to be. 19 | For example changing 20 | 21 | "var": "var", to "var": "let", 22 | will change 23 | var x = 10 to let x = 10 24 | 25 | You cannot change the value to be a value with spaces, for example 26 | 27 | "let this be" will not work but "let_this_be" will work! 28 | """ 29 | 30 | KEYWORDS_DICT = { 31 | "var": "😀", 32 | "and": "👌", 33 | "or": "🤏", 34 | "elif": "😑", 35 | "else": "🤬", 36 | "if": "❓", 37 | "not": "❌", 38 | "do": "⏩", 39 | "for": "🔁", 40 | "to": "👉", 41 | "step": "🦶", 42 | "while": "🤨", 43 | "func": "🥶", 44 | "end": "💀", 45 | "return": "👹", 46 | "continue": "😈", 47 | "break": "😱" 48 | } 49 | 50 | # *################### 51 | # * SYMBOL TABLE 52 | # * YOU CAN EDIT THIS! 53 | # *################### 54 | 55 | """ 56 | How to use: 57 | 58 | Change the value in the first argument of .set() 59 | For example: 60 | global_symbol_table.set("null", Number.null) 61 | -> 62 | global_symbol_table.set("nill", Number.null) 63 | 64 | This will change the value `null` to `nill` in the command line. 65 | """ 66 | 67 | global_symbol_table = SymbolTable() 68 | # changing the below to 69 | # global_symbol_table.set("nill", Number.null) 70 | # will make `nill` work instead of `null` in command line 71 | global_symbol_table.set("null", Number.null) 72 | global_symbol_table.set("true", Number.true) 73 | global_symbol_table.set("false", Number.false) 74 | global_symbol_table.set("pi", Number.pi) 75 | 76 | # changing the below to 77 | # global_symbol_table.set("shout", BuiltInFunction("print")) 78 | # will make shout("value") work instead of print("value") 79 | # If you want an example of what each of this functions do go to values/value_builtinfunc.py and find the correct function. 80 | global_symbol_table.set("📣", BuiltInFunction("print")) 81 | global_symbol_table.set("💬", BuiltInFunction("input")) 82 | global_symbol_table.set("🤓", BuiltInFunction("input_int")) 83 | global_symbol_table.set("🔄", BuiltInFunction("clear")) 84 | global_symbol_table.set("🤡", BuiltInFunction("exit")) 85 | global_symbol_table.set("📲", BuiltInFunction("update_value")) 86 | global_symbol_table.set("🔢", BuiltInFunction("is_num")) 87 | global_symbol_table.set("🔠", BuiltInFunction("is_str")) 88 | global_symbol_table.set("🔣", BuiltInFunction("is_list")) 89 | global_symbol_table.set("🚚", BuiltInFunction("is_func")) 90 | global_symbol_table.set("🔚", BuiltInFunction("append")) 91 | global_symbol_table.set("🔝", BuiltInFunction("pop")) 92 | global_symbol_table.set("🔛", BuiltInFunction("extend")) 93 | global_symbol_table.set("😳", BuiltInFunction("run")) 94 | global_symbol_table.set("📏", BuiltInFunction("len")) 95 | global_symbol_table.set("🤑", BuiltInFunction("randint")) 96 | global_symbol_table.set("👄", BuiltInFunction("to_str")) 97 | global_symbol_table.set("👅", BuiltInFunction("to_int")) 98 | global_symbol_table.set("🧠", BuiltInFunction("pyeval")) 99 | 100 | # *################### 101 | # * GRAMMAR RULES 102 | # * YOU CAN EDIT THIS! 103 | # *################### 104 | 105 | # With this True you will need "var". 106 | # With it False you can either use "var" or not. 107 | GRAMMAR_USE_IDENTIFIER_FOR_ASSIGNMENT = True 108 | # More coming soon.... -------------------------------------------------------------------------------- /whython_emoji/errors.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from strings_with_arrows import * 6 | 7 | # *################### 8 | # * ERRORS 9 | # *################### 10 | 11 | class Error: 12 | def __init__(self, pos_start, pos_end, error_name, details): 13 | self.error_name = error_name 14 | self.details = details 15 | self.pos_start = pos_start 16 | self.pos_end = pos_end 17 | 18 | def as_string(self): 19 | result = f"{self.error_name}: {self.details}" 20 | result += f"\nFile {self.pos_start.fn}, line {self.pos_start.ln + 1}" 21 | result += '\n\n' + string_with_arrows(self.pos_start.ftxt, self.pos_start, self.pos_end) 22 | return result 23 | 24 | class IllegalCharError(Error): 25 | def __init__(self, pos_start, pos_end, details): 26 | super().__init__(pos_start, pos_end, 'Illegal Character', details) 27 | 28 | 29 | class ExpectedCharError(Error): 30 | def __init__(self, pos_start, pos_end, details=''): 31 | super().__init__(pos_start, pos_end, 'Expected Character', details) 32 | 33 | 34 | class InvalidSyntaxError(Error): 35 | def __init__(self, pos_start, pos_end, details=''): 36 | super().__init__(pos_start, pos_end, 'Invalid Syntax', details) 37 | 38 | class CastingError(Error): 39 | def __init__(self, pos_start, pos_end, details=''): 40 | super().__init__(pos_start, pos_end, 'Casting Error', details) 41 | 42 | class RTError(Error): 43 | def __init__(self, pos_start, pos_end, details, context): 44 | super().__init__(pos_start, pos_end, 'Runtime Error', details) 45 | self.context = context 46 | 47 | def as_string(self): 48 | result = self.generate_traceback() 49 | result += f"{self.error_name}: {self.details}" 50 | result += '\n\n' + string_with_arrows(self.pos_start.ftxt, self.pos_start, self.pos_end) 51 | return result 52 | 53 | def generate_traceback(self): 54 | result = "" 55 | pos = self.pos_start 56 | ctx = self.context 57 | 58 | while ctx: 59 | result = f" >> File {pos.fn}, line {str(pos.ln + 1)}, in {ctx.display_name}\n" 60 | pos = ctx.parent_entry_pos 61 | ctx = ctx.parent 62 | 63 | return f"Traceback (most recent call last):\n {result}" -------------------------------------------------------------------------------- /whython_emoji/examples/emoji.whython: -------------------------------------------------------------------------------- 1 | # 😳("examples/emoji") 2 | 3 | 😀 number = 🤑(1, 100) 4 | 5 | 🥶 winner() 6 | 📣("You guessed correctly.") 7 | 💀 8 | 9 | 🥶 guesser() 10 | 🤨 true ⏩ 11 | 📣("Guess a number between 1 and 100") 12 | 😀 input = 🤓() 13 | ❓ input <= 100 👌 input >= 1 ⏩ 14 | ❓ input == number ⏩ 15 | 📣("You got it!") 16 | winner() 17 | 😱 18 | 😑 input < number ⏩ 19 | 📣("Too low") 20 | 😑 input > number ⏩ 21 | 📣("Too high") 22 | 💀 23 | 🤬 24 | 📣("You did not guess in the range, please try again") 25 | 💀 26 | 💀 27 | 💀 28 | 29 | guesser() -------------------------------------------------------------------------------- /whython_emoji/examples/eval.whython: -------------------------------------------------------------------------------- 1 | # run("examples/eval") 2 | 3 | var test_1 = `input("What's your name? ")` 4 | var name = eval(test_1) 5 | print(name) 6 | 7 | var test_2 = ` 8 | print("test_2") 9 | ` 10 | print("\n") 11 | eval(test_2) 12 | 13 | var test_3 = ` 14 | for i in range(10): 15 | print(f"hello, test_3! {i}") 16 | ` 17 | print("\n") 18 | eval(test_3) 19 | 20 | var test_4 = ` 21 | def test_4(): 22 | print("Test 4 is wrapped in a function!") 23 | test_4() 24 | ` 25 | print("\n") 26 | eval(test_4) -------------------------------------------------------------------------------- /whython_emoji/examples/guesser.whython: -------------------------------------------------------------------------------- 1 | number = randint(1, 100) 2 | 3 | func winner() 4 | print("This is the winner message!!!") 5 | end 6 | 7 | while true do 8 | print("Guess a number between 1 and 100") 9 | var x = input_int() 10 | if x <= 100 and x >= 1 do 11 | if x == number do 12 | print("You got it!") 13 | winner() 14 | break 15 | elif x < number do 16 | print("Too low!") 17 | elif x > number do 18 | print("Too high!") 19 | end 20 | else 21 | print("Number not within range of 1 and 100") 22 | end 23 | end -------------------------------------------------------------------------------- /whython_emoji/examples/hello_world.whython: -------------------------------------------------------------------------------- 1 | print("Hello, World!") -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_append.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_append.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_append.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_append.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_clear.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_clear.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_clear.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_clear.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_exit.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_exit.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_exit.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_exit.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_extend.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_extend.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_extend.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_extend.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_input.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_input.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_input.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_input.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_input_int.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_input_int.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_input_int.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_input_int.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_is_func.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_is_func.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_is_func.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_is_func.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_is_list.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_is_list.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_is_list.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_is_list.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_is_num.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_is_num.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_is_num.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_is_num.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_is_str.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_is_str.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_is_str.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_is_str.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_len.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_len.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_len.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_len.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_pop.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_pop.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_pop.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_pop.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_print.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_print.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_print.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_print.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_pyeval.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_pyeval.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_pyeval.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_pyeval.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_randint.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_randint.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_randint.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_randint.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_run.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_run.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_run.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_run.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_to_int.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_to_int.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_to_int.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_to_int.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_to_str.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_to_str.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_to_str.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_to_str.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_update_value.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_update_value.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/__pycache__/execute_update_value.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/execute/__pycache__/execute_update_value.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/execute/execute_append.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_list import List 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | from errors import RTError 10 | 11 | # *################### 12 | # * APPEND 13 | # *################### 14 | 15 | def execute_append_func(self, exec_ctx): 16 | list_ = exec_ctx.symbol_table.get("list") 17 | value = exec_ctx.symbol_table.get("value") 18 | 19 | if not isinstance(list_, List): 20 | return RTResult().failure(RTError( 21 | self.pos_start, self.pos_end, 22 | "First argument must be a list", 23 | exec_ctx 24 | )) 25 | 26 | list_.elements.append(value) 27 | return RTResult().success(Number.null) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_clear.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | import os 6 | 7 | from values.value_number import Number 8 | from runtime_results import RTResult 9 | 10 | # *################### 11 | # * PRINT 12 | # *################### 13 | 14 | def execute_clear_func(self, exec_ctx): 15 | os.system("cls" if os.name == "nt" else "clear") 16 | return RTResult().success(Number.null) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_exit.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | import sys 6 | 7 | # *################### 8 | # * RANDINT 9 | # *################### 10 | 11 | def execute_exit_func(self, exec_ctx): 12 | print("Exiting...") 13 | sys.exit() 14 | -------------------------------------------------------------------------------- /whython_emoji/execute/execute_extend.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_list import List 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | from errors import RTError 10 | 11 | # *################### 12 | # * EXTEND 13 | # *################### 14 | 15 | def execute_extend_func(self, exec_ctx): 16 | list_a = exec_ctx.symbol_table.get("list_a") 17 | list_b = exec_ctx.symbol_table.get("list_b") 18 | 19 | if not isinstance(list_a, List): 20 | return RTResult().failure(RTError( 21 | self.pos_start, self.pos_end, 22 | "First argument must be a list", 23 | exec_ctx 24 | )) 25 | 26 | if not isinstance(list_b, List): 27 | return RTResult().failure(RTError( 28 | self.pos_start, self.pos_end, 29 | "Second argument must be a list", 30 | exec_ctx 31 | )) 32 | 33 | list_a.elements.extend(list_b.elements) 34 | return RTResult().success(Number.null) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_input.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | 7 | from runtime_results import RTResult 8 | 9 | # *################### 10 | # * PRINT 11 | # *################### 12 | 13 | def execute_input_func(self, exec_ctx): 14 | prompt = exec_ctx.symbol_table.get("prompt=0") 15 | if isinstance(prompt, String): 16 | text_input = input(prompt) 17 | else: 18 | text_input = input() 19 | return RTResult().success(String(text_input)) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_input_int.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_number import Number 6 | from values.value_string import String 7 | 8 | from runtime_results import RTResult 9 | 10 | # *################### 11 | # * PRINT 12 | # *################### 13 | 14 | def execute_input_int_func(self, exec_ctx): 15 | prompt = exec_ctx.symbol_table.get("prompt=0") 16 | while True: 17 | if isinstance(prompt, String): 18 | text_input = input(prompt) 19 | else: 20 | text_input = input() 21 | try: 22 | text_int = int(text_input) 23 | break 24 | except ValueError: 25 | print(f"'{text_input}' is not an integer. Try again!") 26 | return RTResult().success(Number(text_int)) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_is_func.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_function import Function 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | 10 | # *################### 11 | # * IS FUNCTION 12 | # *################### 13 | 14 | def execute_is_func_func(self, exec_ctx): 15 | is_function = isinstance(exec_ctx.symbol_table.get("value"), Function) 16 | return RTResult().success(Number.true if is_function else Number.false) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_is_list.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_list import List 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | 10 | # *################### 11 | # * IS LIST 12 | # *################### 13 | 14 | def execute_is_list_func(self, exec_ctx): 15 | is_list = isinstance(exec_ctx.symbol_table.get("value"), List) 16 | return RTResult().success(Number.true if is_list else Number.false) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_is_num.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_number import Number 6 | from runtime_results import RTResult 7 | 8 | 9 | # *################### 10 | # * IS NUMBER 11 | # *################### 12 | 13 | def execute_is_num_func(self, exec_ctx): 14 | is_num = isinstance(exec_ctx.symbol_table.get("value"), Number) 15 | return RTResult().success(Number.true if is_num else Number.false) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_is_str.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | 10 | # *################### 11 | # * IS STRING 12 | # *################### 13 | 14 | def execute_is_str_func(self, exec_ctx): 15 | is_str = isinstance(exec_ctx.symbol_table.get("value"), String) 16 | return RTResult().success(Number.true if is_str else Number.false) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_len.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_list import List 6 | from values.value_string import String 7 | from values.value_number import Number 8 | from runtime_results import RTResult 9 | 10 | from errors import RTError 11 | 12 | # *################### 13 | # * LENGTH 14 | # *################### 15 | 16 | def execute_len_func(self, exec_ctx): 17 | item_ = exec_ctx.symbol_table.get("item") 18 | 19 | if isinstance(item_, List): 20 | return RTResult().success(Number(len(item_.elements))) 21 | elif isinstance(item_, String): 22 | return RTResult().success(Number(len(str(item_.value)))) 23 | else: 24 | return RTResult().failure(RTError( 25 | self.pos_start, self.pos_end, 26 | f"Them item was not a list of a string", 27 | exec_ctx 28 | )) 29 | -------------------------------------------------------------------------------- /whython_emoji/execute/execute_pop.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_list import List 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | from errors import RTError 10 | 11 | # *################### 12 | # * POP 13 | # *################### 14 | 15 | def execute_pop_func(self, exec_ctx): 16 | list_ = exec_ctx.symbol_table.get("list") 17 | index = exec_ctx.symbol_table.get("index") 18 | 19 | if not isinstance(list_, List): 20 | return RTResult().failure(RTError( 21 | self.pos_start, self.pos_end, 22 | "First argument must be a list", 23 | exec_ctx 24 | )) 25 | 26 | if not isinstance(index, Number): 27 | return RTResult().failure(RTError( 28 | self.pos_start, self.pos_end, 29 | "Second argument must be an integer", 30 | exec_ctx 31 | )) 32 | 33 | try: 34 | element = list_.elements.pop(index.value) 35 | except IndexError: 36 | return RTResult().failure(RTError( 37 | self.pos_start, self.pos_end, 38 | f"Element at index '{index.value}' could not be removed as it is out of range of the list.", 39 | exec_ctx 40 | )) 41 | return RTResult().success(element) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_print.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_number import Number 6 | 7 | from runtime_results import RTResult 8 | 9 | # *################### 10 | # * PRINT 11 | # *################### 12 | 13 | def execute_print_func(self, exec_ctx): 14 | print(str(exec_ctx.symbol_table.get("value"))) 15 | return RTResult().success(Number.ignore) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_pyeval.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | from runtime_results import RTResult 7 | from errors import RTError 8 | 9 | 10 | # *################### 11 | # * PYTHON EVAL 12 | # *################### 13 | 14 | def execute_pyeval_func(self, exec_ctx): 15 | code = exec_ctx.symbol_table.get("code") 16 | try: 17 | # code = compile(code.value, "script", "exec") 18 | try: 19 | response = eval(code.value) 20 | except: 21 | response = exec(code.value) 22 | return RTResult().success(String(response)) 23 | except Exception as e: 24 | return RTResult().failure(RTError( 25 | self.pos_start, self.pos_end, 26 | f"The code could not be evaluated. \n\n{e}", 27 | exec_ctx 28 | )) 29 | -------------------------------------------------------------------------------- /whython_emoji/execute/execute_randint.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_number import Number 6 | 7 | from runtime_results import RTResult 8 | from errors import RTError 9 | 10 | 11 | # *################### 12 | # * RANDINT 13 | # *################### 14 | 15 | def execute_randint_func(self, exec_ctx): 16 | import random 17 | from_ = exec_ctx.symbol_table.get("from") 18 | to_ = exec_ctx.symbol_table.get("to") 19 | 20 | if not isinstance(from_, Number): 21 | return RTResult().failure(RTError( 22 | self.pos_start, self.pos_end, 23 | "First argument must be a number", 24 | exec_ctx 25 | )) 26 | 27 | if not isinstance(to_, Number): 28 | return RTResult().failure(RTError( 29 | self.pos_start, self.pos_end, 30 | "Second argument must be a number", 31 | exec_ctx 32 | )) 33 | 34 | try: 35 | random_num = random.randint(from_.value, to_.value) 36 | return RTResult().success(Number(random_num)) 37 | except Exception as e: 38 | return RTResult().failure(RTError( 39 | self.pos_start, self.pos_end, 40 | f"Error generating number\n{e}", 41 | exec_ctx 42 | )) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_run.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | 9 | from errors import RTError 10 | 11 | # *################### 12 | # * RUN 13 | # *################### 14 | 15 | def execute_run_func(self, exec_ctx): 16 | from run import run 17 | fn = exec_ctx.symbol_table.get("filename") 18 | 19 | if not isinstance(fn, String): 20 | return RTResult().failure(RTError( 21 | self.pos_start, self.pos_end, 22 | "Argument must be a string", 23 | exec_ctx 24 | )) 25 | 26 | fn = fn.value 27 | 28 | try: 29 | if not fn.endswith(".whython"): 30 | fn += ".whython" 31 | with open(fn, "r") as f: 32 | script = f.read() 33 | except Exception as e: 34 | return RTResult().failure(RTError( 35 | self.pos_start, self.pos_end, 36 | f"Failed to load script '{fn}'\n{e}", 37 | exec_ctx 38 | )) 39 | 40 | _, error = run(fn, script) 41 | if error: 42 | return RTResult().failure(RTError( 43 | self.pos_start, self.pos_end, 44 | f"Failed to load script '{fn}'\n{error.as_string()}", 45 | exec_ctx 46 | )) 47 | 48 | return RTResult().success(Number.ignore) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_to_int.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | from values.value_number import Number 7 | from runtime_results import RTResult 8 | from errors import RTError 9 | 10 | 11 | # *################### 12 | # * TO INTEGER 13 | # *################### 14 | 15 | def execute_to_int_func(self, exec_ctx): 16 | value = exec_ctx.symbol_table.get("value") 17 | 18 | if not isinstance(value, String): 19 | return RTResult().failure(RTError( 20 | self.pos_start, self.pos_end, 21 | f"The first argument must be a string.", 22 | exec_ctx 23 | )) 24 | 25 | return RTResult().success(Number(int(value.value))) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_to_str.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_string import String 6 | from runtime_results import RTResult 7 | 8 | 9 | # *################### 10 | # * TO STRING 11 | # *################### 12 | 13 | def execute_to_str_func(self, exec_ctx): 14 | value = exec_ctx.symbol_table.get("value") 15 | return RTResult().success(String(str(value))) -------------------------------------------------------------------------------- /whython_emoji/execute/execute_update_value.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_number import Number 6 | from values.value_list import List 7 | from values.value_string import String 8 | 9 | from runtime_results import RTResult 10 | from errors import RTError 11 | 12 | 13 | # *################### 14 | # * UPDATE VALUE 15 | # *################### 16 | 17 | def execute_update_value_func(self, exec_ctx): 18 | list_ = exec_ctx.symbol_table.get("list") 19 | index_ = exec_ctx.symbol_table.get("index") 20 | value_ = exec_ctx.symbol_table.get("new_value") 21 | 22 | if not isinstance(list_, List): 23 | return RTResult().failure(RTError( 24 | self.pos_start, self.pos_end, 25 | "First argument must be a list", 26 | exec_ctx 27 | )) 28 | 29 | if not isinstance(index_, Number): 30 | return RTResult().failure(RTError( 31 | self.pos_start, self.pos_end, 32 | "Second argument must be a number", 33 | exec_ctx 34 | )) 35 | 36 | if not isinstance(value_, Number) or isinstance(value_, String): 37 | return RTResult().failure(RTError( 38 | self.pos_start, self.pos_end, 39 | "Third argument must be a number or a string", 40 | exec_ctx 41 | )) 42 | 43 | try: 44 | list_.elements[index_.value] = value_.value 45 | except: 46 | return RTResult().failure(RTError( 47 | self.pos_start, self.pos_end, 48 | f"Could not change value of index '{index_.value}' as it is not in range of list.", 49 | exec_ctx 50 | )) 51 | 52 | return RTResult().success(Number.ignore) -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_binop.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_binop.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_binop.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_binop.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_break.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_break.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_break.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_break.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_call.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_call.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_call.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_call.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_continue.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_continue.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_continue.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_continue.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_for.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_for.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_for.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_for.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_funcdef.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_funcdef.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_funcdef.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_funcdef.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_if.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_if.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_if.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_if.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_list.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_list.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_list.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_list.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_number.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_number.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_number.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_number.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_return.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_return.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_return.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_return.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_string.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_string.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_string.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_string.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_unaryop.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_unaryop.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_unaryop.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_unaryop.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_varaccess.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_varaccess.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_varaccess.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_varaccess.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_varassign.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_varassign.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_varassign.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_varassign.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_while.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_while.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/node_while.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/node_while.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/nodes.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/nodes.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/__pycache__/nodes.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/nodes_/__pycache__/nodes.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_binop.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * BINARY OPERATION 3 | # * NODE 4 | # *################### 5 | 6 | class BinOpNode: 7 | def __init__(self, left_node, op_tok, right_node): 8 | self.left_node = left_node 9 | self.op_tok = op_tok 10 | self.right_node = right_node 11 | 12 | self.pos_start = self.left_node.pos_start 13 | self.pos_end = self.right_node.pos_end 14 | 15 | def __repr__(self): 16 | return f"({self.left_node}, {self.op_tok}, {self.right_node})" 17 | -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_break.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * BREAK NODE 3 | # *################### 4 | 5 | class BreakNode: 6 | def __init__(self, pos_start, pos_end): 7 | self.pos_start = pos_start 8 | self.pos_end = pos_end -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_call.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * CALL NODE 3 | # *################### 4 | 5 | class CallNode: 6 | def __init__(self, node_to_call, arg_nodes): 7 | self.node_to_call = node_to_call 8 | self.arg_nodes = arg_nodes 9 | 10 | self.pos_start = self.node_to_call.pos_start 11 | 12 | if len(self.arg_nodes) > 0: 13 | self.pos_end = self.arg_nodes[len(self.arg_nodes) - 1].pos_end 14 | else: 15 | self.pos_end = self.node_to_call.pos_end -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_continue.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * CONTINUE NODE 3 | # *################### 4 | 5 | class ContinueNode: 6 | def __init__(self, pos_start, pos_end): 7 | self.pos_start = pos_start 8 | self.pos_end = pos_end 9 | -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_for.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * FOR NODE 3 | # *################### 4 | 5 | class ForNode: 6 | def __init__(self, var_name_tok, start_value_node, end_value_node, step_value_node, body_node, should_return_null): 7 | self.var_name_tok = var_name_tok 8 | self.start_value_node = start_value_node 9 | self.end_value_node = end_value_node 10 | self.step_value_node = step_value_node 11 | self.body_node = body_node 12 | self.should_return_null = should_return_null 13 | 14 | self.pos_start = self.var_name_tok.pos_start 15 | self.pos_end = self.body_node.pos_end 16 | -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_funcdef.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * FUNCTION DEFINITION 3 | # * NODE 4 | # *################### 5 | 6 | class FuncDefNode: 7 | def __init__(self, var_name_tok, arg_name_toks, body_node, should_auto_return): 8 | self.var_name_tok = var_name_tok 9 | self.arg_name_toks = arg_name_toks 10 | self.body_node = body_node 11 | self.should_auto_return = should_auto_return 12 | 13 | if self.var_name_tok: 14 | self.pos_start = self.var_name_tok.pos_start 15 | elif len(self.arg_name_toks) > 0: 16 | self.pos_start = self.arg_name_toks[0].pos_start 17 | else: 18 | self.pos_start = self.body_node.pos_start 19 | 20 | self.pos_end = self.body_node.pos_end -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_if.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IF NODE 3 | # *################### 4 | 5 | class IfNode: 6 | def __init__(self, cases, else_case): 7 | self.cases = cases 8 | self.else_case = else_case 9 | 10 | self.pos_start = self.cases[0][0].pos_start 11 | self.pos_end = (self.else_case or self.cases[len(cases) - 1])[0].pos_end -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_list.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * LIST NODE 3 | # *################### 4 | 5 | class ListNode: 6 | def __init__(self, element_nodes, pos_start, pos_end): 7 | self.element_nodes = element_nodes 8 | 9 | self.pos_start = pos_start 10 | self.pos_end = pos_end 11 | -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_number.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * NUMBER NODE 3 | # *################### 4 | 5 | class NumberNode: 6 | def __init__(self, tok): 7 | self.tok = tok 8 | 9 | self.pos_start = self.tok.pos_start 10 | self.pos_end = self.tok.pos_end 11 | 12 | def __repr__(self): 13 | return f"{self.tok}" -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_return.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * RETURN NODE 3 | # *################### 4 | 5 | class ReturnNode: 6 | def __init__(self, node_to_return, pos_start, pos_end): 7 | self.node_to_return = node_to_return 8 | self.pos_start = pos_start 9 | self.pos_end = pos_end 10 | -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_string.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * STRING 3 | # *################### 4 | 5 | class StringNode: 6 | def __init__(self, tok): 7 | self.tok = tok 8 | 9 | self.pos_start = self.tok.pos_start 10 | self.pos_end = self.tok.pos_end 11 | 12 | def __repr__(self): 13 | return f"{self.tok}" -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_unaryop.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * UNARY OPERATION 3 | # * NODE 4 | # *################### 5 | 6 | class UnaryOpNode: 7 | def __init__(self, op_tok, node): 8 | self.op_tok = op_tok 9 | self.node = node 10 | 11 | self.pos_start = self.op_tok.pos_start 12 | self.pos_end = node.pos_end 13 | 14 | def __repr__(self): 15 | return f"({self.op_tok}, {self.node})" -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_varaccess.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * VAR ACCESS NODE 3 | # *################### 4 | 5 | class VarAccessNode: 6 | def __init__(self, var_name_tok): 7 | self.var_name_tok = var_name_tok 8 | 9 | self.pos_start = self.var_name_tok.pos_start 10 | self.pos_end = self.var_name_tok.pos_end 11 | -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_varassign.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * VAR ASSIGN NODE 3 | # *################### 4 | 5 | class VarAssignNode: 6 | def __init__(self, var_name_tok, value_node): 7 | self.var_name_tok = var_name_tok 8 | self.value_node = value_node 9 | 10 | self.pos_start = self.var_name_tok.pos_start 11 | self.pos_end = self.var_name_tok.pos_end -------------------------------------------------------------------------------- /whython_emoji/nodes_/node_while.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * WHILE NODE 3 | # *################### 4 | 5 | class WhileNode: 6 | def __init__(self, condition_node, body_node, should_return_null): 7 | self.condition_node = condition_node 8 | self.body_node = body_node 9 | self.should_return_null = should_return_null 10 | 11 | self.pos_start = self.condition_node.pos_start 12 | self.pos_end = self.body_node.pos_end 13 | -------------------------------------------------------------------------------- /whython_emoji/nodes_/nodes.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * NODES 3 | # *################### 4 | 5 | from nodes_.node_binop import BinOpNode 6 | from nodes_.node_break import BreakNode 7 | from nodes_.node_call import CallNode 8 | from nodes_.node_continue import ContinueNode 9 | from nodes_.node_for import ForNode 10 | from nodes_.node_funcdef import FuncDefNode 11 | from nodes_.node_if import IfNode 12 | from nodes_.node_list import ListNode 13 | from nodes_.node_number import NumberNode 14 | from nodes_.node_return import ReturnNode 15 | from nodes_.node_string import StringNode 16 | from nodes_.node_unaryop import UnaryOpNode 17 | from nodes_.node_varaccess import VarAccessNode 18 | from nodes_.node_varassign import VarAssignNode 19 | from nodes_.node_while import WhileNode -------------------------------------------------------------------------------- /whython_emoji/position.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * POSITION 3 | # *################### 4 | 5 | class Position: 6 | def __init__(self, idx, ln, col, fn, ftxt): 7 | self.idx = idx 8 | self.ln = ln 9 | self.col = col 10 | self.fn = fn 11 | self.ftxt = ftxt 12 | 13 | def advance(self, current_char=None): 14 | self.idx += 1 15 | self.col += 1 16 | 17 | if current_char == "\n": 18 | self.ln += 1 19 | self.col = 0 20 | 21 | return self 22 | 23 | def copy(self): 24 | return Position(self.idx, self.ln, self.col, self.fn, self.ftxt) 25 | -------------------------------------------------------------------------------- /whython_emoji/run.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from interpreter import * 6 | from context import Context 7 | from editable_.editable import global_symbol_table 8 | 9 | # *################### 10 | # * RUN 11 | # *################### 12 | 13 | def run(fn, text): 14 | # Generate tokens 15 | lexer = Lexer(fn, text) 16 | tokens, error = lexer.make_tokens() 17 | if error: return None, error 18 | 19 | # Generate AST 20 | parser = Parser(tokens) 21 | ast = parser.parse() 22 | if ast.error: return None, ast.error 23 | 24 | # Run program 25 | interpreter = Interpreter() 26 | context = Context('') 27 | context.symbol_table = global_symbol_table 28 | result = interpreter.visit(ast.node, context) 29 | 30 | return result.value, result.error 31 | -------------------------------------------------------------------------------- /whython_emoji/runtime_results.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * RUNTIME RESULTS 3 | # *################### 4 | 5 | class RTResult: 6 | def __init__(self): 7 | self.value = None 8 | self.error = None 9 | self.func_return_value = None 10 | self.loop_should_continue = False 11 | self.loop_should_break = False 12 | self.reset() 13 | 14 | def reset(self): 15 | self.value = None 16 | self.error = None 17 | self.func_return_value = None 18 | self.loop_should_continue = False 19 | self.loop_should_break = False 20 | 21 | def register(self, res): 22 | if res.error: self.error = res.error 23 | self.func_return_value = res.func_return_value 24 | self.loop_should_continue = res.loop_should_continue 25 | self.loop_should_break = res.loop_should_break 26 | return res.value 27 | 28 | def success(self, value): 29 | self.reset() 30 | self.value = value 31 | return self 32 | 33 | def success_return(self, value): 34 | self.reset() 35 | self.func_return_value = value 36 | return self 37 | 38 | def success_continue(self): 39 | self.reset() 40 | self.loop_should_continue = True 41 | return self 42 | 43 | def success_break(self): 44 | self.reset() 45 | self.loop_should_break = True 46 | return self 47 | 48 | def failure(self, error): 49 | self.reset() 50 | self.error = error 51 | return self 52 | 53 | def should_return(self): 54 | return ( 55 | self.error or 56 | self.func_return_value or 57 | self.loop_should_continue or 58 | self.loop_should_break 59 | ) 60 | -------------------------------------------------------------------------------- /whython_emoji/shell.py: -------------------------------------------------------------------------------- 1 | import run as whython 2 | import os 3 | 4 | def main(): 5 | welcome() 6 | while True: 7 | try: 8 | text = input("whython > ") 9 | if text.strip() == "": continue 10 | if text.strip() == "exit": print("Goodbye!"); return 11 | result, error = whython.run("", text) 12 | 13 | if error: print(error.as_string()) 14 | elif result: 15 | for element in result.elements: 16 | try: 17 | if element.value is not None: 18 | print(element) 19 | except AttributeError: 20 | pass 21 | except KeyboardInterrupt: 22 | print("\nType 'Exit' to leave shell.") 23 | 24 | def welcome(): 25 | print("Welcome to whython v1.3") 26 | 27 | # Get info about saves 28 | editing_location = os.path.abspath("editable_/editable.py") 29 | print(f"Current save location for editing func/var names is: {editing_location}\n") 30 | 31 | if __name__ == "__main__": 32 | main() -------------------------------------------------------------------------------- /whython_emoji/strings_with_arrows.py: -------------------------------------------------------------------------------- 1 | def string_with_arrows(text, pos_start, pos_end): 2 | result = '' 3 | 4 | # Calculate indices 5 | idx_start = max(text.rfind('\n', 0, pos_start.idx), 0) 6 | idx_end = text.find('\n', idx_start + 1) 7 | if idx_end < 0: idx_end = len(text) 8 | 9 | # Generate each line 10 | line_count = pos_end.ln - pos_start.ln + 1 11 | for i in range(line_count): 12 | # Calculate line columns 13 | line = text[idx_start:idx_end] 14 | col_start = pos_start.col if i == 0 else 0 15 | col_end = pos_end.col if i == line_count - 1 else len(line) - 1 16 | 17 | # Append to result 18 | result += line + '\n' 19 | result += ' ' * col_start + '^' * (col_end - col_start) 20 | 21 | # Re-calculate indices 22 | idx_start = idx_end 23 | idx_end = text.find('\n', idx_start + 1) 24 | if idx_end < 0: idx_end = len(text) 25 | 26 | return result.replace('\t', '') -------------------------------------------------------------------------------- /whython_emoji/symbol_table.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * SYMBOL TABLE 3 | # *################### 4 | 5 | class SymbolTable: 6 | def __init__(self, parent=None): 7 | self.symbols = {} 8 | self.parent = parent 9 | 10 | def get(self, name): 11 | value = self.symbols.get(name, None) 12 | if value is None and self.parent: 13 | return self.parent.get(name) 14 | return value 15 | 16 | def set(self, name, value): 17 | self.symbols[name] = value 18 | 19 | def remove(self, name): 20 | del self.symbols[name] -------------------------------------------------------------------------------- /whython_emoji/tokens.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from editable_.editable import KEYWORDS_DICT 6 | 7 | # *################### 8 | # * TOKENS 9 | # * DON'T EDIT THESE! 10 | # *################### 11 | 12 | TT_INT = "INT" 13 | TT_FLOAT = "FLOAT" 14 | TT_STRING = "STRING" 15 | 16 | TT_PLUS = "PLUS" 17 | TT_MINUS = "MINUS" 18 | TT_MUL = "MUL" 19 | TT_DIV = "DIV" 20 | TT_EXPONENT = "EXPONENT" 21 | 22 | TT_IDENTIFIER = "IDENTIFIER" 23 | TT_KEYWORD = "KEYWORD" 24 | TT_EQ = "EQ" 25 | 26 | TT_EE = "EE" 27 | TT_NE = "NE" 28 | TT_LT = "LT" 29 | TT_GT = "GT" 30 | TT_LTE = "LTE" 31 | TT_GTE = "GTE" 32 | 33 | TT_COMMA = "COMMA" 34 | TT_ARROW = "ARROW" 35 | TT_NEWLINE = "NEWLINE" 36 | 37 | TT_LPAREN = "LPAREN" 38 | TT_RPAREN = "RPAREN" 39 | TT_LSQUARE = "[" 40 | TT_RSQUARE = "]" 41 | 42 | TT_EOF = "EOF" 43 | 44 | KEYWORDS = [] 45 | for keyword_index in KEYWORDS_DICT: 46 | KEYWORDS.append(KEYWORDS_DICT[keyword_index]) 47 | 48 | class Token: 49 | def __init__(self, type_, value=None, pos_start=None, pos_end=None): 50 | self.type = type_ 51 | self.value = value 52 | 53 | if pos_start: 54 | self.pos_start = pos_start.copy() 55 | self.pos_end = pos_start.copy() 56 | self.pos_end.advance() 57 | 58 | if pos_end: 59 | self.pos_end = pos_end 60 | 61 | def matches(self, type_, value): 62 | return self.type == type_ and self.value == value 63 | 64 | def __repr__(self): 65 | if self.value: return f'{self.type}:{self.value}' 66 | return f'{self.type}' -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_basefunction.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_basefunction.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_basefunction.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_basefunction.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_builtinfunc.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_builtinfunc.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_builtinfunc.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_builtinfunc.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_function.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_function.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_function.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_function.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_list.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_list.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_list.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_list.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_number.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_number.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_number.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_number.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_string.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_string.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_string.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_string.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_values.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_values.cpython-310.pyc -------------------------------------------------------------------------------- /whython_emoji/values/__pycache__/value_values.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NexInfinite/whython/b1fa118850956766012d81d779ad0ad7c7bbd58c/whython_emoji/values/__pycache__/value_values.cpython-39.pyc -------------------------------------------------------------------------------- /whython_emoji/values/value_basefunction.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_values import Value 6 | from values.value_number import Number 7 | 8 | from context import Context 9 | from symbol_table import SymbolTable 10 | from runtime_results import RTResult 11 | from errors import RTError 12 | 13 | # *################### 14 | # * BASE FUNCTION 15 | # *################### 16 | 17 | class BaseFunction(Value): 18 | def __init__(self, name): 19 | super().__init__() 20 | self.name = name or "" 21 | self.args = [] 22 | self.arg_names = [] 23 | 24 | def generate_new_context(self): 25 | new_context = Context(self.name, self.context, self.pos_start) 26 | new_context.symbol_table = SymbolTable(new_context.parent.symbol_table) 27 | return new_context 28 | 29 | def check_args(self): 30 | res = RTResult() 31 | 32 | for i in range(len(self.arg_names)): 33 | arg = self.arg_names[i] 34 | if "=" in arg: 35 | try: 36 | _ = self.args[i] 37 | except: 38 | try: 39 | self.args.append(Number(int(arg.split("=")[-1]))) 40 | except: 41 | self.args.append(arg.split("=")[-1]) 42 | 43 | if len(self.args) > len(self.arg_names): 44 | return res.failure(RTError( 45 | self.pos_start, self.pos_end, 46 | f"{len(self.args) - len(self.arg_names)} too many args passed into {self}", 47 | self.context 48 | )) 49 | 50 | if len(self.args) < len(self.arg_names): 51 | return res.failure(RTError( 52 | self.pos_start, self.pos_end, 53 | f"{len(self.arg_names) - len(self.args)} too few args passed into {self}", 54 | self.context 55 | )) 56 | 57 | return res.success(None) 58 | 59 | def populate_args(self, exec_ctx): 60 | for i in range(len(self.args)): 61 | arg_name = self.arg_names[i] 62 | arg_value = self.args[i] 63 | arg_value.set_context(exec_ctx) 64 | exec_ctx.symbol_table.set(arg_name, arg_value) 65 | 66 | def check_and_populate_args(self, arg_names, args, exec_ctx): 67 | res = RTResult() 68 | self.arg_names = arg_names 69 | self.args = args 70 | res.register(self.check_args()) 71 | if res.should_return(): return res 72 | self.populate_args(exec_ctx) 73 | return res.success(None) -------------------------------------------------------------------------------- /whython_emoji/values/value_function.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_basefunction import BaseFunction 6 | from values.value_number import Number 7 | 8 | from runtime_results import RTResult 9 | 10 | # *################### 11 | # * FUNCTION 12 | # *################### 13 | 14 | class Function(BaseFunction): 15 | def __init__(self, name, body_node, arg_names, should_auto_return): 16 | super().__init__(name) 17 | self.body_node = body_node 18 | self.arg_names = arg_names 19 | self.should_auto_return = should_auto_return 20 | 21 | def execute(self, args): 22 | from interpreter import Interpreter 23 | res = RTResult() 24 | interpreter = Interpreter() 25 | exec_ctx = self.generate_new_context() 26 | 27 | res.register(self.check_and_populate_args(self.arg_names, args, exec_ctx)) 28 | if res.should_return(): return res 29 | 30 | value = res.register(interpreter.visit(self.body_node, exec_ctx)) 31 | if res.should_return() and res.func_return_value is None: return res 32 | 33 | ret_value = (value if self.should_auto_return else None) or res.func_return_value or Number.null 34 | return res.success(ret_value) 35 | 36 | def copy(self): 37 | copy = Function(self.name, self.body_node, self.arg_names, self.should_auto_return) 38 | copy.set_context(self.context) 39 | copy.set_pos(self.pos_start, self.pos_end) 40 | return copy 41 | 42 | def __repr__(self): 43 | return f"" -------------------------------------------------------------------------------- /whython_emoji/values/value_list.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_values import Value 6 | from values.value_number import Number 7 | 8 | from errors import RTError 9 | 10 | # *################### 11 | # * STRING 12 | # *################### 13 | 14 | class List(Value): 15 | """ 16 | List class 17 | Examples: 18 | -------------------------- 19 | Using "+" will append to the list 20 | 21 | var list = [1, 2, 3] 22 | list + 4 -> [1, 2, 3, 4] 23 | -------------------------- 24 | Using "-" will pop from the list at index 25 | 26 | var list = [1, 2, 3] 27 | var popped = list - 1 -> [1, 3] 28 | popped: 2 29 | -------------------------- 30 | Using "*" will extend 2 lists 31 | 32 | var list_a = [1, 2, 3] 33 | var list_b = [4, 5, 6] 34 | 35 | list_a*list_b -> [1, 2, 3, 4, 5, 6] 36 | list_a -> [1, 2, 3, 4, 5, 6] 37 | -------------------------- 38 | Using "/" will get the item at that index 39 | 40 | var list = [1, 2, 3] 41 | list/1 -> 2 42 | """ 43 | def __init__(self, elements): 44 | super().__init__() 45 | self.elements = elements 46 | 47 | def added_to(self, other): 48 | new_list = self.copy() 49 | new_list.elements.append(other) 50 | return new_list, None 51 | 52 | def multiplied_by(self, other): 53 | if isinstance(other, List): 54 | new_list = self.copy() 55 | new_list.elements.extend(other.elements) 56 | return new_list, None 57 | else: 58 | return None, Value.illegal_operation(self, other) 59 | 60 | def subtracted_by(self, other): 61 | if isinstance(other, Number): 62 | new_list = self.copy() 63 | try: 64 | new_list.elements.pop(other.value) 65 | return new_list, None 66 | except: 67 | return None, RTError( 68 | other.pos_start, other.pos_end, 69 | 'Element at this index could not be removed from list because index is out of bounds', 70 | self.context 71 | ) 72 | else: 73 | return None, Value.illegal_operation(self, other) 74 | 75 | def divided_by(self, other): 76 | if isinstance(other, Number): 77 | try: 78 | return self.elements[other.value], None 79 | except: 80 | return None, RTError( 81 | other.pos_start, other.pos_end, 82 | 'Element at this index could not be retrieved from list because index is out of bounds', 83 | self.context 84 | ) 85 | else: 86 | return None, Value.illegal_operation(self, other) 87 | 88 | def copy(self): 89 | copy = List(self.elements) 90 | copy.set_pos(self.pos_start, self.pos_end) 91 | copy.set_context(self.context) 92 | return copy 93 | 94 | def __str__(self): 95 | return f"{', '.join([str(x) for x in self.elements])}" 96 | 97 | def __repr__(self): 98 | return f"[{', '.join([str(x) for x in self.elements])}]" -------------------------------------------------------------------------------- /whython_emoji/values/value_number.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_values import Value 6 | from errors import RTError 7 | 8 | import math 9 | 10 | # *################### 11 | # * NUMBER 12 | # *################### 13 | 14 | class Number(Value): 15 | def __init__(self, value): 16 | super().__init__() 17 | self.value = value 18 | 19 | def added_to(self, other): 20 | if isinstance(other, Number): 21 | return Number(self.value + other.value).set_context(self.context), None 22 | else: 23 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 24 | 25 | def subtracted_by(self, other): 26 | if isinstance(other, Number): 27 | return Number(self.value - other.value).set_context(self.context), None 28 | else: 29 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 30 | 31 | def multiplied_by(self, other): 32 | if isinstance(other, Number): 33 | return Number(self.value * other.value).set_context(self.context), None 34 | else: 35 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 36 | 37 | def exponent_by(self, other): 38 | if isinstance(other, Number): 39 | return Number(self.value ** other.value).set_context(self.context), None 40 | else: 41 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 42 | 43 | def get_comparison_eq(self, other): 44 | if isinstance(other, Number): 45 | return Number(int(self.value == other.value)).set_context(self.context), None 46 | else: 47 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 48 | 49 | def get_comparison_ne(self, other): 50 | if isinstance(other, Number): 51 | return Number(int(self.value != other.value)).set_context(self.context), None 52 | else: 53 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 54 | 55 | def get_comparison_lt(self, other): 56 | if isinstance(other, Number): 57 | return Number(int(self.value < other.value)).set_context(self.context), None 58 | else: 59 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 60 | 61 | def get_comparison_lte(self, other): 62 | if isinstance(other, Number): 63 | return Number(int(self.value <= other.value)).set_context(self.context), None 64 | else: 65 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 66 | 67 | def get_comparison_gt(self, other): 68 | if isinstance(other, Number): 69 | return Number(int(self.value > other.value)).set_context(self.context), None 70 | else: 71 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 72 | 73 | def get_comparison_gte(self, other): 74 | if isinstance(other, Number): 75 | return Number(int(self.value >= other.value)).set_context(self.context), None 76 | else: 77 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 78 | 79 | def anded_by(self, other): 80 | if isinstance(other, Number): 81 | return Number(int(self.value and other.value)).set_context(self.context), None 82 | else: 83 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 84 | 85 | def ored_by(self, other): 86 | if isinstance(other, Number): 87 | return Number(int(self.value or other.value)).set_context(self.context), None 88 | else: 89 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 90 | 91 | def notted(self): 92 | return Number(1 if self.value == 0 else 0).set_context(self.context), None 93 | 94 | def divided_by(self, other): 95 | if isinstance(other, Number): 96 | if other.value == 0: 97 | return None, RTError( 98 | other.pos_start, other.pos_end, 99 | "Division by zero.", 100 | self.context 101 | ) 102 | 103 | return Number(self.value / other.value).set_context(self.context), None 104 | else: 105 | return None, Value.illegal_operation(self.pos_start, other.pos_end) 106 | 107 | def copy(self): 108 | copy = Number(self.value) 109 | copy.set_pos(self.pos_start, self.pos_end) 110 | copy.set_context(self.context) 111 | return copy 112 | 113 | def is_true(self): 114 | return self.value != 0 115 | 116 | def __repr__(self): 117 | return str(self.value) 118 | 119 | Number.null = Number(0) 120 | Number.ignore = Number(None) 121 | Number.false = Number(0) 122 | Number.true = Number(1) 123 | Number.pi = Number(math.pi) -------------------------------------------------------------------------------- /whython_emoji/values/value_string.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from values.value_values import Value 6 | from values.value_number import Number 7 | 8 | # *################### 9 | # * STRING 10 | # *################### 11 | 12 | 13 | class String(Value): 14 | def __init__(self, value): 15 | super().__init__() 16 | self.value = value 17 | 18 | def added_to(self, other): 19 | if isinstance(other, String): 20 | return String(self.value + other.value).set_context(self.context), None 21 | else: 22 | return None, Value.illegal_operation(self, other) 23 | 24 | def multiplied_by(self, other): 25 | if isinstance(other, Number): 26 | return String(self.value * other.value).set_context(self.context), None 27 | else: 28 | return None, Value.illegal_operation(self, other) 29 | 30 | def is_true(self): 31 | return len(self.value) > 0 32 | 33 | def copy(self): 34 | copy = String(self.value) 35 | copy.set_pos(self.pos_start, self.pos_end) 36 | copy.set_context(self.context) 37 | return copy 38 | 39 | def __str__(self): 40 | return self.value 41 | 42 | def __repr__(self): 43 | return f'"{self.value}"' -------------------------------------------------------------------------------- /whython_emoji/values/value_values.py: -------------------------------------------------------------------------------- 1 | # *################### 2 | # * IMPORTS 3 | # *################### 4 | 5 | from errors import RTError 6 | from runtime_results import RTResult 7 | 8 | # *################### 9 | # * VALUE 10 | # *################### 11 | 12 | class Value: 13 | def __init__(self): 14 | self.set_pos() 15 | self.set_context() 16 | 17 | self.pos_start = None 18 | self.pos_end = None 19 | self.context = None 20 | 21 | def set_pos(self, pos_start=None, pos_end=None): 22 | self.pos_start = pos_start 23 | self.pos_end = pos_end 24 | return self 25 | 26 | def set_context(self, context=None): 27 | self.context = context 28 | return self 29 | 30 | def added_to(self, other): 31 | return None, self.illegal_operation(other) 32 | 33 | def subbed_by(self, other): 34 | return None, self.illegal_operation(other) 35 | 36 | def multed_by(self, other): 37 | return None, self.illegal_operation(other) 38 | 39 | def dived_by(self, other): 40 | return None, self.illegal_operation(other) 41 | 42 | def powed_by(self, other): 43 | return None, self.illegal_operation(other) 44 | 45 | def get_comparison_eq(self, other): 46 | return None, self.illegal_operation(other) 47 | 48 | def get_comparison_ne(self, other): 49 | return None, self.illegal_operation(other) 50 | 51 | def get_comparison_lt(self, other): 52 | return None, self.illegal_operation(other) 53 | 54 | def get_comparison_gt(self, other): 55 | return None, self.illegal_operation(other) 56 | 57 | def get_comparison_lte(self, other): 58 | return None, self.illegal_operation(other) 59 | 60 | def get_comparison_gte(self, other): 61 | return None, self.illegal_operation(other) 62 | 63 | def anded_by(self, other): 64 | return None, self.illegal_operation(other) 65 | 66 | def ored_by(self, other): 67 | return None, self.illegal_operation(other) 68 | 69 | def notted(self): 70 | return None, self.illegal_operation() 71 | 72 | def execute(self, args): 73 | return RTResult().failure(self.illegal_operation()) 74 | 75 | def copy(self): 76 | raise Exception('No copy method defined') 77 | 78 | def is_true(self): 79 | return False 80 | 81 | def illegal_operation(self, other=None): 82 | if not other: other = self 83 | return RTError( 84 | self.pos_start, other.pos_end, 85 | 'Illegal operation', 86 | self.context 87 | ) --------------------------------------------------------------------------------