sipl-kit 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sipl_kit-0.4.0/.gitignore +17 -0
- sipl_kit-0.4.0/CHANGELOG.md +33 -0
- sipl_kit-0.4.0/LICENSE +21 -0
- sipl_kit-0.4.0/PKG-INFO +184 -0
- sipl_kit-0.4.0/README.md +161 -0
- sipl_kit-0.4.0/docs/architecture.md +24 -0
- sipl_kit-0.4.0/docs/cli.md +90 -0
- sipl_kit-0.4.0/docs/language.md +73 -0
- sipl_kit-0.4.0/docs/schema/cli-output.schema.json +106 -0
- sipl_kit-0.4.0/examples/divides.sipl +7 -0
- sipl_kit-0.4.0/examples/double_factorial_even.sipl +10 -0
- sipl_kit-0.4.0/examples/errors/infinite_loop.sipl +6 -0
- sipl_kit-0.4.0/examples/errors/missing_else.sipl +3 -0
- sipl_kit-0.4.0/examples/errors/trailing_semicolon.sipl +4 -0
- sipl_kit-0.4.0/examples/errors/undefined_variable.sipl +4 -0
- sipl_kit-0.4.0/examples/fibonacci.sipl +14 -0
- sipl_kit-0.4.0/examples/gcd.sipl +6 -0
- sipl_kit-0.4.0/examples/isqrt.sipl +6 -0
- sipl_kit-0.4.0/examples/parity.sipl +7 -0
- sipl_kit-0.4.0/examples/power.sipl +9 -0
- sipl_kit-0.4.0/examples/prime.sipl +10 -0
- sipl_kit-0.4.0/grammar/README.md +27 -0
- sipl_kit-0.4.0/pyproject.toml +58 -0
- sipl_kit-0.4.0/src/sipl/__init__.py +7 -0
- sipl_kit-0.4.0/src/sipl/__main__.py +5 -0
- sipl_kit-0.4.0/src/sipl/ast.py +270 -0
- sipl_kit-0.4.0/src/sipl/cli.py +276 -0
- sipl_kit-0.4.0/src/sipl/diagnostics.py +64 -0
- sipl_kit-0.4.0/src/sipl/grammar/__init__.py +0 -0
- sipl_kit-0.4.0/src/sipl/grammar/sipl.lark +77 -0
- sipl_kit-0.4.0/src/sipl/interpreter/__init__.py +27 -0
- sipl_kit-0.4.0/src/sipl/interpreter/events.py +43 -0
- sipl_kit-0.4.0/src/sipl/interpreter/runtime.py +201 -0
- sipl_kit-0.4.0/src/sipl/parser.py +203 -0
- sipl_kit-0.4.0/src/sipl/printer.py +65 -0
- sipl_kit-0.4.0/src/sipl/semantics/__init__.py +35 -0
- sipl_kit-0.4.0/src/sipl/semantics/terms.py +258 -0
- sipl_kit-0.4.0/tests/conftest.py +10 -0
- sipl_kit-0.4.0/tests/grammar/invalid/01_empty.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/02_no_begin.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/03_empty_block.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/04_trailing_semicolon.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/05_missing_semicolon.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/06_if_without_else.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/07_eq_instead_assign.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/08_bad_char.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/09_condition_is_number.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/10_unclosed_paren.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/11_keyword_as_var.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/12_missing_end.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/13_two_programs.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/14_assign_to_number.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/invalid/15_double_plus.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/01_skip.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/02_assign.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/03_seq.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/04_if.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/05_while.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/06_nested_block.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/07_precedence.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/08_negative.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/09_conditions.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/10_comments.sipl +4 -0
- sipl_kit-0.4.0/tests/grammar/valid/11_div_mod.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/12_keyword_prefix_vars.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/13_nested_if_while.sipl +1 -0
- sipl_kit-0.4.0/tests/grammar/valid/14_paren_cond.sipl +1 -0
- sipl_kit-0.4.0/tests/test_cli.py +175 -0
- sipl_kit-0.4.0/tests/test_grammar.py +35 -0
- sipl_kit-0.4.0/tests/test_interpreter.py +128 -0
- sipl_kit-0.4.0/tests/test_parser.py +156 -0
- sipl_kit-0.4.0/tests/test_printer.py +28 -0
- sipl_kit-0.4.0/tests/test_semantics.py +87 -0
- sipl_kit-0.4.0/tests/test_trace.py +66 -0
- sipl_kit-0.4.0/vscode-sipl/CHANGELOG.md +5 -0
- sipl_kit-0.4.0/vscode-sipl/LICENSE +21 -0
- sipl_kit-0.4.0/vscode-sipl/README.md +36 -0
- sipl_kit-0.4.0/vscode-sipl/src/cli.js +118 -0
- sipl_kit-0.4.0/vscode-sipl/src/extension.js +216 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Format: [Keep a Changelog](https://keepachangelog.com/), versions: [SemVer](https://semver.org/).
|
|
4
|
+
One version number is used for the Python package `sipl-kit` and the VS Code extension `sipl-vscode`.
|
|
5
|
+
|
|
6
|
+
## [0.4.0] - 2026-11-18
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- VS Code extension `sipl-vscode` (IDE-01, IDE-02): `.sipl` language registration, TextMate highlighting,
|
|
10
|
+
comments, `begin`/`end` brackets, auto indent, snippets.
|
|
11
|
+
- Commands *SIPL: Run*, *Check*, *Trace*, *Show Semantic Term*; live diagnostics with exact line and column.
|
|
12
|
+
- Release workflow: GitHub Release with wheel, sdist and `.vsix`; publishing to PyPI.
|
|
13
|
+
|
|
14
|
+
## [0.3.0] - 2026-11-13
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- `sipl` CLI (CORE-05): `parse`, `check`, `run`, `trace`, `term`; `--json` output with JSON Schema
|
|
18
|
+
`docs/schema/cli-output.schema.json`; stable exit codes 0-4.
|
|
19
|
+
- Semantic terms in course notation with the list of applied rules (SEM-01).
|
|
20
|
+
|
|
21
|
+
## [0.2.0] - 2026-11-10
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- Interpreter (CORE-03): states, `:=`, `;`, `if`, `while`, `begin/end`, `skip`; step limit for infinite loops;
|
|
25
|
+
runtime errors with source position.
|
|
26
|
+
- Event model (CORE-04): `start`, `before_statement`, `after_statement`, `assign`, `condition`, `finish`, `error`.
|
|
27
|
+
|
|
28
|
+
## [0.1.0] - 2026-11-09
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
- Lark grammar of SIPL following the course BNF, with 14 valid and 15 invalid test programs (CORE-01).
|
|
32
|
+
- Parser with typed AST and `SourceSpan` for every node, syntax diagnostics with expected tokens (CORE-02).
|
|
33
|
+
- CI on GitHub Actions: ruff, mypy, pytest with 80% coverage gate on Linux and Windows (REL-01).
|
sipl_kit-0.4.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vitalii Fedin
|
|
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.
|
sipl_kit-0.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: sipl-kit
|
|
3
|
+
Version: 0.4.0
|
|
4
|
+
Summary: SIPL (SImple Programming Language) toolkit: grammar, parser, interpreter, trace, semantic terms and CLI
|
|
5
|
+
Project-URL: Homepage, https://github.com/exite-off/sipl-toolkit
|
|
6
|
+
Project-URL: Changelog, https://github.com/exite-off/sipl-toolkit/blob/main/CHANGELOG.md
|
|
7
|
+
Author-email: Vitalii Fedin <vfedin868@gmail.com>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: education,interpreter,programming-theory,semantics,sipl
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Education
|
|
13
|
+
Classifier: Topic :: Software Development :: Interpreters
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Requires-Dist: lark<2,>=1.1
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: jsonschema>=4; extra == 'dev'
|
|
18
|
+
Requires-Dist: mypy>=1.10; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
20
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
21
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# SIPL Language Toolkit
|
|
25
|
+
|
|
26
|
+
[](https://github.com/exite-off/sipl-toolkit/actions/workflows/ci.yml)
|
|
27
|
+
[](https://pypi.org/project/sipl-kit/)
|
|
28
|
+
|
|
29
|
+
Інструменти для мови SIPL (SImple Programming Language) з курсу «Теорія програмування»:
|
|
30
|
+
граматика, парсер у типізоване AST, інтерпретатор із trace, семантичні терми в нотації курсу,
|
|
31
|
+
CLI з JSON-режимом і розширення для VS Code.
|
|
32
|
+
|
|
33
|
+
Курсовий проєкт. Виконавець: **Vitalii Fedin**, група **ТК-32**.
|
|
34
|
+
|
|
35
|
+
## Обрані завдання
|
|
36
|
+
|
|
37
|
+
| ID | Завдання | Бали | Де реалізовано |
|
|
38
|
+
|---|---|---|---|
|
|
39
|
+
| CORE-01 | Формальна специфікація SIPL | 0.5 | `src/sipl/grammar/sipl.lark`, `docs/language.md`, `tests/grammar/` |
|
|
40
|
+
| CORE-02 | Парсер і типізоване AST з SourceSpan | 1.5 | `src/sipl/parser.py`, `src/sipl/ast.py` |
|
|
41
|
+
| CORE-03 | Інтерпретатор | 2.0 | `src/sipl/interpreter/runtime.py` |
|
|
42
|
+
| CORE-04 | Подієва модель виконання та trace | 1.0 | `src/sipl/interpreter/events.py`, `sipl trace` |
|
|
43
|
+
| CORE-05 | CLI parse/check/run/trace, JSON | 1.0 | `src/sipl/cli.py`, `docs/cli.md`, `docs/schema/` |
|
|
44
|
+
| IDE-01 | VS Code: мова, підсвітка, сніпети, .vsix | 1.0 | `vscode-sipl/` |
|
|
45
|
+
| IDE-02 | VS Code: Run/Check, diagnostics | 1.0 | `vscode-sipl/src/extension.js` |
|
|
46
|
+
| REL-01 | CI | 0.5 | `.github/workflows/ci.yml` |
|
|
47
|
+
| REL-02 | GitHub Releases + SemVer + CHANGELOG | 0.5 | `.github/workflows/release.yml`, `CHANGELOG.md` |
|
|
48
|
+
| REL-03 | Публікація в PyPI | 0.5 | пакет `sipl-kit` |
|
|
49
|
+
| REL-04 | Публікація VS Code extension (.vsix) | 0.5 | `.vsix` у GitHub Release |
|
|
50
|
+
| | **Разом** | **10.0** | |
|
|
51
|
+
| SEM-01 | Семантичний терм (додатково, запас) | 2.0 | `src/sipl/semantics/terms.py`, `sipl term` |
|
|
52
|
+
|
|
53
|
+
Заявлено 12.0 бали, оцінка обмежується 10.
|
|
54
|
+
|
|
55
|
+
## Встановлення
|
|
56
|
+
|
|
57
|
+
Потрібен Python 3.10+.
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install sipl-kit
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Для розробки (з тестами й лінтерами):
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
git clone https://github.com/exite-off/sipl-toolkit.git
|
|
67
|
+
cd sipl-toolkit
|
|
68
|
+
python -m venv .venv
|
|
69
|
+
# Windows: .venv\Scripts\activate Linux/macOS: source .venv/bin/activate
|
|
70
|
+
pip install -e ".[dev]"
|
|
71
|
+
pytest
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Якщо в PowerShell активація блокується політикою виконання:
|
|
75
|
+
`Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`.
|
|
76
|
+
|
|
77
|
+
## Використання
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
$ sipl run examples/power.sipl -s X=5,Y=2
|
|
81
|
+
[X ↦ 5, Y ↦ 0, R ↦ 25]
|
|
82
|
+
|
|
83
|
+
$ sipl check examples/errors/missing_else.sipl
|
|
84
|
+
examples/errors/missing_else.sipl:3:1: error: unexpected 'end', expected 'else' (in SIPL every 'if' needs an 'else' branch) [E101]
|
|
85
|
+
|
|
86
|
+
$ sipl run examples/errors/infinite_loop.sipl --max-steps 50
|
|
87
|
+
examples/errors/infinite_loop.sipl:5:9: error: step limit of 50 exceeded (possible infinite loop) [E300]
|
|
88
|
+
state at failure: [X ↦ 24]
|
|
89
|
+
|
|
90
|
+
$ sipl trace examples/power.sipl -s X=5,Y=2
|
|
91
|
+
#0 2:1 start [X ↦ 5, Y ↦ 2]
|
|
92
|
+
#1 3:5 before_statement Assign
|
|
93
|
+
#1 3:5 assign R: ⊥ -> 1
|
|
94
|
+
#1 3:5 after_statement Assign
|
|
95
|
+
#2 4:5 before_statement While
|
|
96
|
+
#2 4:11 condition while -> true (iteration 0)
|
|
97
|
+
...
|
|
98
|
+
#8 4:11 condition while -> false (iteration 2)
|
|
99
|
+
#8 4:5 after_statement While
|
|
100
|
+
#8 2:1 finish [X ↦ 5, Y ↦ 0, R ↦ 25]
|
|
101
|
+
[X ↦ 5, Y ↦ 0, R ↦ 25]
|
|
102
|
+
|
|
103
|
+
$ sipl term examples/power.sipl
|
|
104
|
+
AS^R(1) · WH(S^2(gr, Y⇒, 0), AS^R(S^2(mult, R⇒, X⇒)) · AS^Y(S^2(sub, Y⇒, 1)))
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`sipl term --steps` виводить усі застосовані правила (`NS_Prog`, `NS_Stm_Seq`, `NS_Stm_As`, ...)
|
|
108
|
+
так само, як у практичній роботі 2. Кожна команда має `--json` для інтеграцій.
|
|
109
|
+
Повний опис команд, кодів завершення та JSON-формату: [docs/cli.md](docs/cli.md).
|
|
110
|
+
|
|
111
|
+
Як бібліотека:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from sipl import parse
|
|
115
|
+
from sipl.interpreter import run, trace
|
|
116
|
+
from sipl.semantics import derive
|
|
117
|
+
|
|
118
|
+
program = parse(open("examples/power.sipl", encoding="utf-8").read())
|
|
119
|
+
print(run(program, {"X": 5, "Y": 2}).state) # {'X': 5, 'Y': 0, 'R': 25}
|
|
120
|
+
print(derive(program).term) # AS^R(1) · WH(...)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## VS Code
|
|
124
|
+
|
|
125
|
+
1. Встановіть пакет: `pip install sipl-kit`.
|
|
126
|
+
2. Завантажте `sipl-vscode-<версія>.vsix` з [Releases](https://github.com/exite-off/sipl-toolkit/releases)
|
|
127
|
+
і встановіть: `code --install-extension sipl-vscode-0.4.0.vsix`.
|
|
128
|
+
3. Відкрийте `.sipl`-файл. Помилки підсвічуються одразу під час набору.
|
|
129
|
+
Кнопки ▶ (Run) і ✓ (Check) у заголовку редактора, Ctrl+F5 запускає програму.
|
|
130
|
+
Команди *SIPL: Trace* і *SIPL: Show Semantic Term* доступні з Command Palette.
|
|
131
|
+
|
|
132
|
+
Якщо Python не в PATH, вкажіть інтерпретатор у налаштуванні `sipl.pythonPath`.
|
|
133
|
+
Сумісність: VS Code 1.85+, Windows / Linux / macOS.
|
|
134
|
+
|
|
135
|
+
<!-- screenshots: docs/images/highlight.png, docs/images/run.png -->
|
|
136
|
+
|
|
137
|
+
## Приклади
|
|
138
|
+
|
|
139
|
+
`examples/` містить програми для варіантів практичних робіт: степінь (приклад з посібника),
|
|
140
|
+
(2n)!!, числа Фібоначчі, парність, подільність, ⌊√n⌋, простота числа, НСД.
|
|
141
|
+
`examples/errors/` містить програми з типовими помилками.
|
|
142
|
+
|
|
143
|
+
## Структура
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
grammar/ опис граматики і відповідність БНФ курсу
|
|
147
|
+
src/sipl/
|
|
148
|
+
grammar/sipl.lark машинозчитувана граматика (Lark, LALR(1))
|
|
149
|
+
ast.py типізовані вузли AST, SourceSpan
|
|
150
|
+
parser.py текст -> AST, синтаксична діагностика
|
|
151
|
+
printer.py AST -> текст
|
|
152
|
+
diagnostics.py коди помилок
|
|
153
|
+
interpreter/ виконання, стани, події trace
|
|
154
|
+
semantics/ семантичні терми, правила NS_*
|
|
155
|
+
cli.py команди parse/check/run/trace/term
|
|
156
|
+
examples/ приклади SIPL
|
|
157
|
+
tests/ pytest, покриття ядра понад 95%
|
|
158
|
+
docs/ мова, CLI, JSON Schema, архітектура
|
|
159
|
+
vscode-sipl/ VS Code extension, клієнт CLI
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
Як дані проходять через шари: [docs/architecture.md](docs/architecture.md).
|
|
163
|
+
|
|
164
|
+
## Тести
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
pytest # Python: граматика, парсер, інтерпретатор, trace, CLI, терми
|
|
168
|
+
cd vscode-sipl && npm ci && npm test # extension: підсвітка на TextMate-рушії VS Code, інтеграція з CLI
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
CI запускає ruff, mypy і pytest на Linux і Windows (Python 3.10, 3.12, 3.13), збирає wheel
|
|
172
|
+
і `.vsix`. Тег `vX.Y.Z` створює GitHub Release і публікує пакет у PyPI.
|
|
173
|
+
|
|
174
|
+
## Обмеження
|
|
175
|
+
|
|
176
|
+
- `while` без завершення виявляється лише через ліміт кроків (`--max-steps`, типово 100000).
|
|
177
|
+
Це обмеження інструменту, а не доведення незавершуваності.
|
|
178
|
+
- Читання змінної, якої немає в стані, є помилкою: у курсі `x⇒` на такому стані не визначена.
|
|
179
|
+
- `div`, `mod` і коментарі є розширенням SIPL+, у БНФ курсу їх немає ([docs/language.md](docs/language.md)).
|
|
180
|
+
- Розширення VS Code не містить власного парсера: без встановленого `sipl-kit` воно не працює.
|
|
181
|
+
|
|
182
|
+
## Ліцензія
|
|
183
|
+
|
|
184
|
+
MIT
|
sipl_kit-0.4.0/README.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# SIPL Language Toolkit
|
|
2
|
+
|
|
3
|
+
[](https://github.com/exite-off/sipl-toolkit/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/sipl-kit/)
|
|
5
|
+
|
|
6
|
+
Інструменти для мови SIPL (SImple Programming Language) з курсу «Теорія програмування»:
|
|
7
|
+
граматика, парсер у типізоване AST, інтерпретатор із trace, семантичні терми в нотації курсу,
|
|
8
|
+
CLI з JSON-режимом і розширення для VS Code.
|
|
9
|
+
|
|
10
|
+
Курсовий проєкт. Виконавець: **Vitalii Fedin**, група **ТК-32**.
|
|
11
|
+
|
|
12
|
+
## Обрані завдання
|
|
13
|
+
|
|
14
|
+
| ID | Завдання | Бали | Де реалізовано |
|
|
15
|
+
|---|---|---|---|
|
|
16
|
+
| CORE-01 | Формальна специфікація SIPL | 0.5 | `src/sipl/grammar/sipl.lark`, `docs/language.md`, `tests/grammar/` |
|
|
17
|
+
| CORE-02 | Парсер і типізоване AST з SourceSpan | 1.5 | `src/sipl/parser.py`, `src/sipl/ast.py` |
|
|
18
|
+
| CORE-03 | Інтерпретатор | 2.0 | `src/sipl/interpreter/runtime.py` |
|
|
19
|
+
| CORE-04 | Подієва модель виконання та trace | 1.0 | `src/sipl/interpreter/events.py`, `sipl trace` |
|
|
20
|
+
| CORE-05 | CLI parse/check/run/trace, JSON | 1.0 | `src/sipl/cli.py`, `docs/cli.md`, `docs/schema/` |
|
|
21
|
+
| IDE-01 | VS Code: мова, підсвітка, сніпети, .vsix | 1.0 | `vscode-sipl/` |
|
|
22
|
+
| IDE-02 | VS Code: Run/Check, diagnostics | 1.0 | `vscode-sipl/src/extension.js` |
|
|
23
|
+
| REL-01 | CI | 0.5 | `.github/workflows/ci.yml` |
|
|
24
|
+
| REL-02 | GitHub Releases + SemVer + CHANGELOG | 0.5 | `.github/workflows/release.yml`, `CHANGELOG.md` |
|
|
25
|
+
| REL-03 | Публікація в PyPI | 0.5 | пакет `sipl-kit` |
|
|
26
|
+
| REL-04 | Публікація VS Code extension (.vsix) | 0.5 | `.vsix` у GitHub Release |
|
|
27
|
+
| | **Разом** | **10.0** | |
|
|
28
|
+
| SEM-01 | Семантичний терм (додатково, запас) | 2.0 | `src/sipl/semantics/terms.py`, `sipl term` |
|
|
29
|
+
|
|
30
|
+
Заявлено 12.0 бали, оцінка обмежується 10.
|
|
31
|
+
|
|
32
|
+
## Встановлення
|
|
33
|
+
|
|
34
|
+
Потрібен Python 3.10+.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install sipl-kit
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Для розробки (з тестами й лінтерами):
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
git clone https://github.com/exite-off/sipl-toolkit.git
|
|
44
|
+
cd sipl-toolkit
|
|
45
|
+
python -m venv .venv
|
|
46
|
+
# Windows: .venv\Scripts\activate Linux/macOS: source .venv/bin/activate
|
|
47
|
+
pip install -e ".[dev]"
|
|
48
|
+
pytest
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Якщо в PowerShell активація блокується політикою виконання:
|
|
52
|
+
`Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`.
|
|
53
|
+
|
|
54
|
+
## Використання
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
$ sipl run examples/power.sipl -s X=5,Y=2
|
|
58
|
+
[X ↦ 5, Y ↦ 0, R ↦ 25]
|
|
59
|
+
|
|
60
|
+
$ sipl check examples/errors/missing_else.sipl
|
|
61
|
+
examples/errors/missing_else.sipl:3:1: error: unexpected 'end', expected 'else' (in SIPL every 'if' needs an 'else' branch) [E101]
|
|
62
|
+
|
|
63
|
+
$ sipl run examples/errors/infinite_loop.sipl --max-steps 50
|
|
64
|
+
examples/errors/infinite_loop.sipl:5:9: error: step limit of 50 exceeded (possible infinite loop) [E300]
|
|
65
|
+
state at failure: [X ↦ 24]
|
|
66
|
+
|
|
67
|
+
$ sipl trace examples/power.sipl -s X=5,Y=2
|
|
68
|
+
#0 2:1 start [X ↦ 5, Y ↦ 2]
|
|
69
|
+
#1 3:5 before_statement Assign
|
|
70
|
+
#1 3:5 assign R: ⊥ -> 1
|
|
71
|
+
#1 3:5 after_statement Assign
|
|
72
|
+
#2 4:5 before_statement While
|
|
73
|
+
#2 4:11 condition while -> true (iteration 0)
|
|
74
|
+
...
|
|
75
|
+
#8 4:11 condition while -> false (iteration 2)
|
|
76
|
+
#8 4:5 after_statement While
|
|
77
|
+
#8 2:1 finish [X ↦ 5, Y ↦ 0, R ↦ 25]
|
|
78
|
+
[X ↦ 5, Y ↦ 0, R ↦ 25]
|
|
79
|
+
|
|
80
|
+
$ sipl term examples/power.sipl
|
|
81
|
+
AS^R(1) · WH(S^2(gr, Y⇒, 0), AS^R(S^2(mult, R⇒, X⇒)) · AS^Y(S^2(sub, Y⇒, 1)))
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`sipl term --steps` виводить усі застосовані правила (`NS_Prog`, `NS_Stm_Seq`, `NS_Stm_As`, ...)
|
|
85
|
+
так само, як у практичній роботі 2. Кожна команда має `--json` для інтеграцій.
|
|
86
|
+
Повний опис команд, кодів завершення та JSON-формату: [docs/cli.md](docs/cli.md).
|
|
87
|
+
|
|
88
|
+
Як бібліотека:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from sipl import parse
|
|
92
|
+
from sipl.interpreter import run, trace
|
|
93
|
+
from sipl.semantics import derive
|
|
94
|
+
|
|
95
|
+
program = parse(open("examples/power.sipl", encoding="utf-8").read())
|
|
96
|
+
print(run(program, {"X": 5, "Y": 2}).state) # {'X': 5, 'Y': 0, 'R': 25}
|
|
97
|
+
print(derive(program).term) # AS^R(1) · WH(...)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## VS Code
|
|
101
|
+
|
|
102
|
+
1. Встановіть пакет: `pip install sipl-kit`.
|
|
103
|
+
2. Завантажте `sipl-vscode-<версія>.vsix` з [Releases](https://github.com/exite-off/sipl-toolkit/releases)
|
|
104
|
+
і встановіть: `code --install-extension sipl-vscode-0.4.0.vsix`.
|
|
105
|
+
3. Відкрийте `.sipl`-файл. Помилки підсвічуються одразу під час набору.
|
|
106
|
+
Кнопки ▶ (Run) і ✓ (Check) у заголовку редактора, Ctrl+F5 запускає програму.
|
|
107
|
+
Команди *SIPL: Trace* і *SIPL: Show Semantic Term* доступні з Command Palette.
|
|
108
|
+
|
|
109
|
+
Якщо Python не в PATH, вкажіть інтерпретатор у налаштуванні `sipl.pythonPath`.
|
|
110
|
+
Сумісність: VS Code 1.85+, Windows / Linux / macOS.
|
|
111
|
+
|
|
112
|
+
<!-- screenshots: docs/images/highlight.png, docs/images/run.png -->
|
|
113
|
+
|
|
114
|
+
## Приклади
|
|
115
|
+
|
|
116
|
+
`examples/` містить програми для варіантів практичних робіт: степінь (приклад з посібника),
|
|
117
|
+
(2n)!!, числа Фібоначчі, парність, подільність, ⌊√n⌋, простота числа, НСД.
|
|
118
|
+
`examples/errors/` містить програми з типовими помилками.
|
|
119
|
+
|
|
120
|
+
## Структура
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
grammar/ опис граматики і відповідність БНФ курсу
|
|
124
|
+
src/sipl/
|
|
125
|
+
grammar/sipl.lark машинозчитувана граматика (Lark, LALR(1))
|
|
126
|
+
ast.py типізовані вузли AST, SourceSpan
|
|
127
|
+
parser.py текст -> AST, синтаксична діагностика
|
|
128
|
+
printer.py AST -> текст
|
|
129
|
+
diagnostics.py коди помилок
|
|
130
|
+
interpreter/ виконання, стани, події trace
|
|
131
|
+
semantics/ семантичні терми, правила NS_*
|
|
132
|
+
cli.py команди parse/check/run/trace/term
|
|
133
|
+
examples/ приклади SIPL
|
|
134
|
+
tests/ pytest, покриття ядра понад 95%
|
|
135
|
+
docs/ мова, CLI, JSON Schema, архітектура
|
|
136
|
+
vscode-sipl/ VS Code extension, клієнт CLI
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Як дані проходять через шари: [docs/architecture.md](docs/architecture.md).
|
|
140
|
+
|
|
141
|
+
## Тести
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
pytest # Python: граматика, парсер, інтерпретатор, trace, CLI, терми
|
|
145
|
+
cd vscode-sipl && npm ci && npm test # extension: підсвітка на TextMate-рушії VS Code, інтеграція з CLI
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
CI запускає ruff, mypy і pytest на Linux і Windows (Python 3.10, 3.12, 3.13), збирає wheel
|
|
149
|
+
і `.vsix`. Тег `vX.Y.Z` створює GitHub Release і публікує пакет у PyPI.
|
|
150
|
+
|
|
151
|
+
## Обмеження
|
|
152
|
+
|
|
153
|
+
- `while` без завершення виявляється лише через ліміт кроків (`--max-steps`, типово 100000).
|
|
154
|
+
Це обмеження інструменту, а не доведення незавершуваності.
|
|
155
|
+
- Читання змінної, якої немає в стані, є помилкою: у курсі `x⇒` на такому стані не визначена.
|
|
156
|
+
- `div`, `mod` і коментарі є розширенням SIPL+, у БНФ курсу їх немає ([docs/language.md](docs/language.md)).
|
|
157
|
+
- Розширення VS Code не містить власного парсера: без встановленого `sipl-kit` воно не працює.
|
|
158
|
+
|
|
159
|
+
## Ліцензія
|
|
160
|
+
|
|
161
|
+
MIT
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
source text ──► parser.py ──► ast.Program ──┬──► interpreter/ ──► ExecutionResult + Event stream
|
|
5
|
+
(.sipl) (Lark LALR, (typed nodes │ runtime.py (state, steps, trace)
|
|
6
|
+
grammar/ with │ events.py
|
|
7
|
+
sipl.lark) SourceSpan) ├──► semantics/terms.py ──► Term + list of applied rules
|
|
8
|
+
└──► printer.py ──► source text (round trip)
|
|
9
|
+
|
|
10
|
+
cli.py: parse | check | run | trace | term (text or --json, stable exit codes)
|
|
11
|
+
▲
|
|
12
|
+
│ spawn "python -m sipl <cmd> - --json", source on stdin
|
|
13
|
+
vscode-sipl/src/extension.js: diagnostics, Run/Check/Trace/Term commands, output panel
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
- `parser.py` turns the Lark parse tree into own dataclasses from `ast.py`; library trees never leave the module.
|
|
17
|
+
Syntax errors become `SiplSyntaxError` with a `SourceSpan` and a list of tokens that were expected.
|
|
18
|
+
- `ast.py` nodes are immutable and comparable by value (spans are ignored by `==`), so tests can compare trees
|
|
19
|
+
and the printer round trip can be checked by `parse(print(p)) == p`.
|
|
20
|
+
- `interpreter/runtime.py` is a direct big-step interpreter. Every statement is reported to listeners
|
|
21
|
+
(`Event`), so the same run can feed a trace printer, a debugger or a visualizer without changes in the interpreter.
|
|
22
|
+
- `semantics/terms.py` implements `sem_P/sem_S/sem_A/sem_B` recursively over the AST and records each rule.
|
|
23
|
+
- The VS Code extension has no parser or interpreter of its own. It is a client of the CLI and uses only
|
|
24
|
+
the JSON contract from `docs/schema/cli-output.schema.json`.
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# Command line interface
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
sipl parse FILE [--json] AST of the program
|
|
5
|
+
sipl check FILE [--json] syntax check
|
|
6
|
+
sipl run FILE [-s X=5 -s Y=2 | -s X=5,Y=2] [--max-steps N] [-v] [--json]
|
|
7
|
+
sipl trace FILE [-s ...] [--max-steps N] [--json] execution with all events
|
|
8
|
+
sipl term FILE [--steps] [--ascii] [--json] semantic term (course notation)
|
|
9
|
+
sipl --version
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
`FILE` can be `-` to read the program from standard input (the VS Code extension uses this,
|
|
13
|
+
so unsaved buffers can be checked). `python -m sipl ...` works the same way as `sipl ...`.
|
|
14
|
+
|
|
15
|
+
## Exit codes
|
|
16
|
+
|
|
17
|
+
| Code | Meaning |
|
|
18
|
+
|---|---|
|
|
19
|
+
| 0 | success |
|
|
20
|
+
| 1 | syntax error |
|
|
21
|
+
| 2 | runtime error (undefined variable, division by zero) |
|
|
22
|
+
| 3 | step limit exceeded |
|
|
23
|
+
| 4 | usage error (bad arguments, file cannot be read, bad `-s` value) |
|
|
24
|
+
|
|
25
|
+
## Text output
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
$ sipl run examples/power.sipl -s X=5,Y=2
|
|
29
|
+
[X ↦ 5, Y ↦ 0, R ↦ 25]
|
|
30
|
+
|
|
31
|
+
$ sipl check examples/errors/missing_else.sipl
|
|
32
|
+
examples/errors/missing_else.sipl:3:1: error: unexpected 'end', expected 'else' (in SIPL every 'if' needs an 'else' branch) [E101]
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Errors go to stderr in the format `file:line:column: error: message [code]`, which most editors understand.
|
|
36
|
+
|
|
37
|
+
## JSON output
|
|
38
|
+
|
|
39
|
+
With `--json` every command prints one JSON object to stdout, even on errors.
|
|
40
|
+
The format is described by the JSON Schema [`docs/schema/cli-output.schema.json`](schema/cli-output.schema.json)
|
|
41
|
+
(`schema_version: 1`) and tests check every command against it.
|
|
42
|
+
|
|
43
|
+
Common fields: `schema_version`, `command`, `file`, `ok`, `diagnostics`.
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"schema_version": 1,
|
|
48
|
+
"command": "run",
|
|
49
|
+
"file": "examples/power.sipl",
|
|
50
|
+
"ok": true,
|
|
51
|
+
"diagnostics": [],
|
|
52
|
+
"status": "ok",
|
|
53
|
+
"initial_state": {"X": 5, "Y": 2},
|
|
54
|
+
"state": {"X": 5, "Y": 0, "R": 25},
|
|
55
|
+
"steps": 8
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
A diagnostic:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{"severity": "error", "code": "E101", "message": "unexpected 'end', expected 'else' ...",
|
|
63
|
+
"span": {"line": 3, "column": 1, "end_line": 3, "end_column": 4, "start": 35, "end": 38}}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Lines and columns are 1-based, `end_column` points right after the last character,
|
|
67
|
+
`start`/`end` are character offsets in the source.
|
|
68
|
+
|
|
69
|
+
Trace event (`sipl trace --json`, field `trace`):
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{"kind": "assign", "step": 3, "node": "Assign", "span": {...}, "variable": "R", "old": 1, "new": 5,
|
|
73
|
+
"state": {"X": 5, "Y": 2, "R": 5}}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Event kinds: `start`, `before_statement`, `after_statement`, `assign` (`variable`, `old`, `new`),
|
|
77
|
+
`condition` (`construct`: `if`/`while`, `value`, `iteration` for loops), `finish`, `error` (`error`).
|
|
78
|
+
`state` is the state right after the event. `step` counts executed statements (assignments, `skip`,
|
|
79
|
+
`if`, `while` and every loop iteration); `begin ... end` and `;` do not count.
|
|
80
|
+
|
|
81
|
+
Error codes:
|
|
82
|
+
|
|
83
|
+
| Code | Meaning |
|
|
84
|
+
|---|---|
|
|
85
|
+
| E101 | unexpected token |
|
|
86
|
+
| E102 | unexpected end of input |
|
|
87
|
+
| E103 | unexpected character |
|
|
88
|
+
| E201 | variable has no value in the current state |
|
|
89
|
+
| E202 | division by zero |
|
|
90
|
+
| E300 | step limit exceeded |
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# SIPL language reference (version 1.0 of the grammar)
|
|
2
|
+
|
|
3
|
+
Source: О.В. Шишацька, А.В. Криволап, А.В. Шишацький. «Теорія програмування. Практикум», 2024,
|
|
4
|
+
practical work 1 (BNF of SIPL) and practical work 2 (semantic terms).
|
|
5
|
+
|
|
6
|
+
## Lexical structure
|
|
7
|
+
|
|
8
|
+
| Token | Form |
|
|
9
|
+
|---|---|
|
|
10
|
+
| keywords | `begin end if then else while do skip` and `or not div mod` |
|
|
11
|
+
| variable | `[A-Za-z_][A-Za-z0-9_]*`, not a keyword (`beginX`, `orange` are variables) |
|
|
12
|
+
| number | `[0-9]+`, a literal may have a leading minus: `-1` (the course allows `... -1 \| 0 \| 1 ...`) |
|
|
13
|
+
| operators | `:= ; + - * = > ( )` |
|
|
14
|
+
| disjunction | `or`, `∨`, `\/` |
|
|
15
|
+
| negation | `not`, `¬`, `!` |
|
|
16
|
+
| whitespace | ignored |
|
|
17
|
+
| comments (SIPL+) | `// to end of line` and `/* block */` |
|
|
18
|
+
|
|
19
|
+
## Syntax
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
P ::= begin S end
|
|
23
|
+
S ::= x := a | S1 ; S2 | if b then S1 else S2 | while b do S | begin S end | skip
|
|
24
|
+
a ::= n | x | a1 + a2 | a1 - a2 | a1 * a2 | (a)
|
|
25
|
+
b ::= a1 = a2 | a1 > a2 | b1 ∨ b2 | ¬ b | (b)
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The BNF is ambiguous, so the implementation fixes priorities (from weakest to strongest):
|
|
29
|
+
|
|
30
|
+
1. `;` is the weakest operator. `while b do S1; S2` is `(while b do S1); S2`, exactly as in the
|
|
31
|
+
textbook ("оператор циклу має вищий пріоритет ніж оператор послідовного виконання").
|
|
32
|
+
To put several statements into a loop or branch use `begin ... end`.
|
|
33
|
+
`S1; S2; S3` is grouped to the left, `(S1; S2); S3`; the meaning does not depend on it because `·` is associative.
|
|
34
|
+
2. `else` is mandatory, so there is no dangling else problem.
|
|
35
|
+
3. In conditions `not` binds tighter than `or`: `not X = 1 or X > 2` is `(¬(X = 1)) ∨ (X > 2)`.
|
|
36
|
+
4. In expressions `*` (and `div`, `mod`) bind tighter than `+` and `-`; all binary operators are left associative:
|
|
37
|
+
`1 - 2 - 3` is `(1 - 2) - 3`.
|
|
38
|
+
|
|
39
|
+
`;` separates statements, it does not terminate them: `begin X := 1; end` is a syntax error.
|
|
40
|
+
|
|
41
|
+
## SIPL+ extensions
|
|
42
|
+
|
|
43
|
+
Not part of the course BNF, documented here as an explicit extension:
|
|
44
|
+
|
|
45
|
+
- `a div b`, `a mod b`: several course variants use them (practical works 1-2, variants 2, 4, 9, 15).
|
|
46
|
+
`div` is floor division, `mod` has the sign of the divisor (`-7 div 2 = -4`, `-7 mod 2 = 1`).
|
|
47
|
+
Division by zero is a runtime error `E202`.
|
|
48
|
+
- comments `//` and `/* */`.
|
|
49
|
+
- ASCII spellings `or`/`not`, `\/`/`!` for `∨`/`¬`.
|
|
50
|
+
|
|
51
|
+
A program without these features is a plain SIPL program.
|
|
52
|
+
|
|
53
|
+
## Semantics used by the interpreter
|
|
54
|
+
|
|
55
|
+
A state is a finite map from variables to integers, `[X ↦ 5, Y ↦ 2]`. Integers are unbounded.
|
|
56
|
+
|
|
57
|
+
- `x := a` evaluates `a` in the current state and updates `x` (`st∇[x ↦ a(st)]`).
|
|
58
|
+
- reading a variable that has no value is an error `E201`: the naming function `x⇒` is undefined
|
|
59
|
+
on such a state, so the program result is undefined.
|
|
60
|
+
- `while` that does not stop has an undefined result. The interpreter detects this only through
|
|
61
|
+
a step limit (default 100000, error `E300`); this is a limit of the tool, not a proof of non-termination.
|
|
62
|
+
|
|
63
|
+
## Semantic terms
|
|
64
|
+
|
|
65
|
+
`sem_P`, `sem_S`, `sem_A`, `sem_B` are implemented with the rules of practical work 2
|
|
66
|
+
(`NS_Prog`, `NS_Stm_As`, `NS_Stm_Seq`, `NS_Stm_If`, `NS_Stm_Wh`, `NS_Stm_BE`, `NS_Stm_skip`,
|
|
67
|
+
`NS_A_Num`, `NS_A_Var`, `NS_A_Add`, `NS_A_Sub`, `NS_A_Mult`, `NS_B_eq`, `NS_B_gr`, `NS_B_or`, `NS_B_neg`),
|
|
68
|
+
plus `NS_A_Div`, `NS_A_Mod` for the extension. Parenthesis rules `NS_A_Par`, `NS_B_Par` are applied by the
|
|
69
|
+
parser: brackets do not appear in the AST.
|
|
70
|
+
|
|
71
|
+
Notation: `AS^x(f)` for assignment, `S^n(f, g1, ..., gn)` for superposition, `x⇒` for naming,
|
|
72
|
+
`f1 · f2` for sequential execution, `IF(b, f1, f2)`, `WH(b, f)`, `id`.
|
|
73
|
+
The brackets from `NS_Stm_BE` are printed only where they group a composition inside another composition.
|