├── .gitignore ├── LICENSE ├── README.md ├── civar.py └── example.civar /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | MANIFEST 27 | 28 | # PyInstaller 29 | # Usually these files are written by a python script from a template 30 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 31 | *.manifest 32 | *.spec 33 | 34 | # Installer logs 35 | pip-log.txt 36 | pip-delete-this-directory.txt 37 | 38 | # Unit test / coverage reports 39 | htmlcov/ 40 | .tox/ 41 | .coverage 42 | .coverage.* 43 | .cache 44 | nosetests.xml 45 | coverage.xml 46 | *.cover 47 | .hypothesis/ 48 | .pytest_cache/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | db.sqlite3 58 | 59 | # Flask stuff: 60 | instance/ 61 | .webassets-cache 62 | 63 | # Scrapy stuff: 64 | .scrapy 65 | 66 | # Sphinx documentation 67 | docs/_build/ 68 | 69 | # PyBuilder 70 | target/ 71 | 72 | # Jupyter Notebook 73 | .ipynb_checkpoints 74 | 75 | # pyenv 76 | .python-version 77 | 78 | # celery beat schedule file 79 | celerybeat-schedule 80 | 81 | # SageMath parsed files 82 | *.sage.py 83 | 84 | # Environments 85 | .env 86 | .venv 87 | env/ 88 | venv/ 89 | ENV/ 90 | env.bak/ 91 | venv.bak/ 92 | 93 | # Spyder project settings 94 | .spyderproject 95 | .spyproject 96 | 97 | # Rope project settings 98 | .ropeproject 99 | 100 | # mkdocs documentation 101 | /site 102 | 103 | # mypy 104 | .mypy_cache/ 105 | 106 | .vscode/ 107 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 CIVAR 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 | # 시바랭 2 | 3 | 배우면 시바와 대화할 수 있게 되는 언어입니다. 4 | 5 | ## 예시 6 | 7 | 입력 : 8 | ``` 9 | 시이이이이이이바......... 하.. 시이이이이이이이바... 하,, 시이바... 하아... 10 | 아,,,, 시이이이이이이이바,,,,,,, 하 시이이바,,, 아...... 11 | 시이이이이이이이바......... 하.. 시바,,,,, 아... 하.. 12 | 시이이바,, 하 시이이바,, 아,,,, 시이이이이이이이바,,,,,,, 하.. 13 | ``` 14 | 15 | 출력 : 16 | ``` 17 | Hello, world! 18 | ``` 19 | 20 | ## 언어 명세 21 | 22 | 이 언어에서 실질적으로 유효한 기능을 수행하는 문자는 총 6개로, `시` `이` `바` `.` `,` ` ` 가 있습니다. 내부적으로 하나의 정수를 저장할 수 있는 저장 공간이 있습니다. (이하 저장 공간) 23 | 24 | ### 시이바... & 시이바,,, 단계 25 | 26 | 이 단계는 `시이(중략)이바` 와 마침표 여러 개 혹은 쉼표 여러 개로 이루어져 있습니다. 마침표의 경우 본 단계가 끝나면 (공백 문자를 만나면) 저장 공간에 `시이(중략)이바` 의 글자 수와 마침표 개수를 곱한 값이 더해집니다. 쉼표의 경우 곱한 값이 빠집니다. 27 | 28 | ### 하아... & 하아,,, 단계 29 | 30 | 이 단계는 `하아(중략)아` 와 마침표 여러 개 혹은 쉼표 여러 개로 이루어져 있습니다. 현재 저장 공간에 담긴 정수에 대응되는 문자 (유니코드 기준) 를 "`하아(중략)아` 글자 수"번 출력합니다. 출력 후에 마침표의 경우 마침표 개수가 저장 공간에 더해지고, 쉼표의 경우 빠집니다. 31 | 32 | ### 공백 문자 33 | 34 | 현재 허용되는 공백 문자의 종류는 ` ` 하나입니다. 공백을 기준으로 `시이바... & 시이바,,, 단계` 가 끝납니다. -------------------------------------------------------------------------------- /civar.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | import re 3 | from enum import Enum 4 | 5 | class State(Enum): 6 | none = 0 7 | civar = 1 8 | dot = 2 9 | comma = 3 10 | ha = 4 11 | space = 5 12 | 13 | def interpret_civar(line): 14 | line = line.replace('\n', ' ') 15 | parser_exp = re.compile(r'[.]+|[,]+|시이*바|하아*|아+| +') 16 | parse_result = parser_exp.findall(line) 17 | 18 | civar_count = 0 19 | dot_count = 0 20 | comma_count = 0 21 | 22 | def tag_block(block): 23 | if block.startswith('시'): 24 | return State.civar 25 | elif block.startswith('.'): 26 | return State.dot 27 | elif block.startswith(','): 28 | return State.comma 29 | elif block.startswith(('하', '아')): 30 | return State.ha 31 | elif block.startswith(' '): 32 | return State.space 33 | 34 | current_state = State.none 35 | previous_state = State.none 36 | 37 | current_num = 0 38 | final_str = "" 39 | 40 | for block in parse_result: 41 | current_state = tag_block(block) 42 | block_len = len(block) 43 | 44 | if current_state == State.civar: 45 | civar_count += block_len 46 | 47 | elif current_state == State.dot: 48 | if previous_state == State.civar: 49 | dot_count += block_len 50 | elif previous_state == State.ha: 51 | current_num += block_len 52 | 53 | elif current_state == State.comma: 54 | if previous_state == State.civar: 55 | comma_count += block_len 56 | elif previous_state == State.ha: 57 | current_num -= block_len 58 | 59 | elif current_state == State.ha: 60 | final_str += chr(current_num) * block_len 61 | 62 | elif current_state == State.space: 63 | if dot_count > 0: 64 | current_num += civar_count * dot_count 65 | elif comma_count > 0: 66 | current_num -= civar_count * comma_count 67 | 68 | civar_count = 0 69 | dot_count = 0 70 | comma_count = 0 71 | 72 | previous_state = current_state 73 | 74 | return final_str 75 | 76 | def run_repl(): 77 | while True: 78 | line = input('>> ').strip() 79 | if line == ':quit': 80 | break 81 | 82 | print(interpret_civar(line)) 83 | 84 | def main(): 85 | parser = argparse.ArgumentParser(description="CIVAR-lang interpreter") 86 | parser.add_argument("input", nargs='?', help="Location of an input file") 87 | args, _ = parser.parse_known_args() 88 | 89 | if args.input is not None: 90 | with open(args.input, 'r') as code_file: 91 | print(interpret_civar(code_file.read())) 92 | else: 93 | run_repl() 94 | 95 | if __name__ == "__main__": 96 | main() -------------------------------------------------------------------------------- /example.civar: -------------------------------------------------------------------------------- 1 | 시이이이이이이바......... 하.. 시이이이이이이이바... 하,, 시이바... 하아... 2 | 아,,,, 시이이이이이이이바,,,,,,, 하 시이이바,,, 아...... 3 | 시이이이이이이이바......... 하.. 시바,,,,, 아... 하.. 4 | 시이이바,, 하 시이이바,, 아,,,, 시이이이이이이이바,,,,,,, 하.. --------------------------------------------------------------------------------