sipl-kit 0.4.0__py3-none-any.whl
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/__init__.py +7 -0
- sipl/__main__.py +5 -0
- sipl/ast.py +270 -0
- sipl/cli.py +276 -0
- sipl/diagnostics.py +64 -0
- sipl/grammar/__init__.py +0 -0
- sipl/grammar/sipl.lark +77 -0
- sipl/interpreter/__init__.py +27 -0
- sipl/interpreter/events.py +43 -0
- sipl/interpreter/runtime.py +201 -0
- sipl/parser.py +203 -0
- sipl/printer.py +65 -0
- sipl/semantics/__init__.py +35 -0
- sipl/semantics/terms.py +258 -0
- sipl_kit-0.4.0.dist-info/METADATA +184 -0
- sipl_kit-0.4.0.dist-info/RECORD +19 -0
- sipl_kit-0.4.0.dist-info/WHEEL +4 -0
- sipl_kit-0.4.0.dist-info/entry_points.txt +2 -0
- sipl_kit-0.4.0.dist-info/licenses/LICENSE +21 -0
sipl/semantics/terms.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
"""Semantic terms of the SIPL program algebra (practical work 2).
|
|
2
|
+
|
|
3
|
+
sem_P: Prog -> TFS, sem_S: Stm -> TFS, sem_A: Aexp -> TFA, sem_B: Bexp -> TFB.
|
|
4
|
+
The term is built recursively over the AST, every applied rule is recorded,
|
|
5
|
+
so the derivation can be shown in the same form as in the textbook.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from typing import Any
|
|
12
|
+
|
|
13
|
+
from .. import ast
|
|
14
|
+
from ..printer import to_source
|
|
15
|
+
|
|
16
|
+
ARITH_NAMES = {"+": "add", "-": "sub", "*": "mult", "div": "div", "mod": "mod"}
|
|
17
|
+
COMPARE_NAMES = {"=": "eq", ">": "gr"}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Term:
|
|
21
|
+
def render(self, ascii_only: bool = False, top: bool = True) -> str:
|
|
22
|
+
raise NotImplementedError
|
|
23
|
+
|
|
24
|
+
def to_dict(self) -> dict[str, Any]:
|
|
25
|
+
raise NotImplementedError
|
|
26
|
+
|
|
27
|
+
def __str__(self) -> str:
|
|
28
|
+
return self.render()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@dataclass(frozen=True)
|
|
32
|
+
class Const(Term):
|
|
33
|
+
# constant function n(st) = n
|
|
34
|
+
value: int
|
|
35
|
+
|
|
36
|
+
def render(self, ascii_only: bool = False, top: bool = True) -> str:
|
|
37
|
+
return str(self.value)
|
|
38
|
+
|
|
39
|
+
def to_dict(self) -> dict[str, Any]:
|
|
40
|
+
return {"term": "const", "value": self.value}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
@dataclass(frozen=True)
|
|
44
|
+
class Denom(Term):
|
|
45
|
+
# naming (denomination) function x=>(st) = st(x)
|
|
46
|
+
name: str
|
|
47
|
+
|
|
48
|
+
def render(self, ascii_only: bool = False, top: bool = True) -> str:
|
|
49
|
+
return f"{self.name}=>" if ascii_only else f"{self.name}⇒"
|
|
50
|
+
|
|
51
|
+
def to_dict(self) -> dict[str, Any]:
|
|
52
|
+
return {"term": "denom", "name": self.name}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@dataclass(frozen=True)
|
|
56
|
+
class Superpos(Term):
|
|
57
|
+
# S^n(f, g1, ..., gn)
|
|
58
|
+
func: str
|
|
59
|
+
args: tuple[Term, ...]
|
|
60
|
+
|
|
61
|
+
def render(self, ascii_only: bool = False, top: bool = True) -> str:
|
|
62
|
+
inner = ", ".join([self.func] + [a.render(ascii_only, True) for a in self.args])
|
|
63
|
+
return f"S^{len(self.args)}({inner})"
|
|
64
|
+
|
|
65
|
+
def to_dict(self) -> dict[str, Any]:
|
|
66
|
+
return {"term": "superposition", "func": self.func, "args": [a.to_dict() for a in self.args]}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@dataclass(frozen=True)
|
|
70
|
+
class AssignT(Term):
|
|
71
|
+
# AS^x(fa)
|
|
72
|
+
var: str
|
|
73
|
+
value: Term
|
|
74
|
+
|
|
75
|
+
def render(self, ascii_only: bool = False, top: bool = True) -> str:
|
|
76
|
+
return f"AS^{self.var}({self.value.render(ascii_only, True)})"
|
|
77
|
+
|
|
78
|
+
def to_dict(self) -> dict[str, Any]:
|
|
79
|
+
return {"term": "assign", "var": self.var, "value": self.value.to_dict()}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@dataclass(frozen=True)
|
|
83
|
+
class SeqT(Term):
|
|
84
|
+
# fs1 · fs2 (first fs1, then fs2)
|
|
85
|
+
first: Term
|
|
86
|
+
second: Term
|
|
87
|
+
|
|
88
|
+
def render(self, ascii_only: bool = False, top: bool = True) -> str:
|
|
89
|
+
dot = " . " if ascii_only else " · "
|
|
90
|
+
return self.first.render(ascii_only, False) + dot + self.second.render(ascii_only, False)
|
|
91
|
+
|
|
92
|
+
def to_dict(self) -> dict[str, Any]:
|
|
93
|
+
return {"term": "seq", "first": self.first.to_dict(), "second": self.second.to_dict()}
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@dataclass(frozen=True)
|
|
97
|
+
class IfT(Term):
|
|
98
|
+
cond: Term
|
|
99
|
+
then_branch: Term
|
|
100
|
+
else_branch: Term
|
|
101
|
+
|
|
102
|
+
def render(self, ascii_only: bool = False, top: bool = True) -> str:
|
|
103
|
+
parts = [t.render(ascii_only, True) for t in (self.cond, self.then_branch, self.else_branch)]
|
|
104
|
+
return f"IF({', '.join(parts)})"
|
|
105
|
+
|
|
106
|
+
def to_dict(self) -> dict[str, Any]:
|
|
107
|
+
return {
|
|
108
|
+
"term": "if",
|
|
109
|
+
"cond": self.cond.to_dict(),
|
|
110
|
+
"then": self.then_branch.to_dict(),
|
|
111
|
+
"else": self.else_branch.to_dict(),
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@dataclass(frozen=True)
|
|
116
|
+
class WhT(Term):
|
|
117
|
+
cond: Term
|
|
118
|
+
body: Term
|
|
119
|
+
|
|
120
|
+
def render(self, ascii_only: bool = False, top: bool = True) -> str:
|
|
121
|
+
return f"WH({self.cond.render(ascii_only, True)}, {self.body.render(ascii_only, True)})"
|
|
122
|
+
|
|
123
|
+
def to_dict(self) -> dict[str, Any]:
|
|
124
|
+
return {"term": "while", "cond": self.cond.to_dict(), "body": self.body.to_dict()}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@dataclass(frozen=True)
|
|
128
|
+
class IdT(Term):
|
|
129
|
+
def render(self, ascii_only: bool = False, top: bool = True) -> str:
|
|
130
|
+
return "id"
|
|
131
|
+
|
|
132
|
+
def to_dict(self) -> dict[str, Any]:
|
|
133
|
+
return {"term": "id"}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
@dataclass(frozen=True)
|
|
137
|
+
class Group(Term):
|
|
138
|
+
# (fs) from rule NS_Stm_BE; brackets are dropped where they change nothing
|
|
139
|
+
body: Term
|
|
140
|
+
|
|
141
|
+
def render(self, ascii_only: bool = False, top: bool = True) -> str:
|
|
142
|
+
inner = self.body.render(ascii_only, top)
|
|
143
|
+
if top or not isinstance(self.body, SeqT):
|
|
144
|
+
return inner
|
|
145
|
+
return f"({inner})"
|
|
146
|
+
|
|
147
|
+
def to_dict(self) -> dict[str, Any]:
|
|
148
|
+
return {"term": "group", "body": self.body.to_dict()}
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@dataclass(frozen=True)
|
|
152
|
+
class RuleStep:
|
|
153
|
+
rule: str
|
|
154
|
+
lhs: str
|
|
155
|
+
rhs: str
|
|
156
|
+
|
|
157
|
+
def to_dict(self) -> dict[str, str]:
|
|
158
|
+
return {"rule": self.rule, "lhs": self.lhs, "rhs": self.rhs}
|
|
159
|
+
|
|
160
|
+
def __str__(self) -> str:
|
|
161
|
+
return f"{self.rule}: {self.lhs} = {self.rhs}"
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@dataclass
|
|
165
|
+
class Derivation:
|
|
166
|
+
term: Term
|
|
167
|
+
steps: list[RuleStep] = field(default_factory=list)
|
|
168
|
+
|
|
169
|
+
def to_dict(self, ascii_only: bool = False) -> dict[str, Any]:
|
|
170
|
+
return {
|
|
171
|
+
"term": self.term.render(ascii_only),
|
|
172
|
+
"tree": self.term.to_dict(),
|
|
173
|
+
"rules": [s.to_dict() for s in self.steps],
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
class _Builder:
|
|
178
|
+
def __init__(self) -> None:
|
|
179
|
+
self.steps: list[RuleStep] = []
|
|
180
|
+
|
|
181
|
+
def _record(self, rule: str, func: str, node: ast.Node, rhs: str) -> None:
|
|
182
|
+
self.steps.append(RuleStep(rule, f"{func}({to_source(node)})", rhs))
|
|
183
|
+
|
|
184
|
+
def prog(self, p: ast.Program) -> Term:
|
|
185
|
+
self._record("NS_Prog", "sem_P", p, f"sem_S({to_source(p.body)})")
|
|
186
|
+
return self.stm(p.body)
|
|
187
|
+
|
|
188
|
+
def stm(self, s: ast.Stm) -> Term:
|
|
189
|
+
if isinstance(s, ast.Assign):
|
|
190
|
+
self._record("NS_Stm_As", "sem_S", s, f"AS^{s.target}(sem_A({to_source(s.value)}))")
|
|
191
|
+
return AssignT(s.target, self.aexp(s.value))
|
|
192
|
+
if isinstance(s, ast.Seq):
|
|
193
|
+
self._record(
|
|
194
|
+
"NS_Stm_Seq", "sem_S", s, f"sem_S({to_source(s.first)}) · sem_S({to_source(s.second)})"
|
|
195
|
+
)
|
|
196
|
+
return SeqT(self.stm(s.first), self.stm(s.second))
|
|
197
|
+
if isinstance(s, ast.If):
|
|
198
|
+
self._record(
|
|
199
|
+
"NS_Stm_If",
|
|
200
|
+
"sem_S",
|
|
201
|
+
s,
|
|
202
|
+
f"IF(sem_B({to_source(s.cond)}), sem_S({to_source(s.then_branch)}), "
|
|
203
|
+
f"sem_S({to_source(s.else_branch)}))",
|
|
204
|
+
)
|
|
205
|
+
return IfT(self.bexp(s.cond), self.stm(s.then_branch), self.stm(s.else_branch))
|
|
206
|
+
if isinstance(s, ast.While):
|
|
207
|
+
self._record(
|
|
208
|
+
"NS_Stm_Wh", "sem_S", s, f"WH(sem_B({to_source(s.cond)}), sem_S({to_source(s.body)}))"
|
|
209
|
+
)
|
|
210
|
+
return WhT(self.bexp(s.cond), self.stm(s.body))
|
|
211
|
+
if isinstance(s, ast.Block):
|
|
212
|
+
self._record("NS_Stm_BE", "sem_S", s, f"(sem_S({to_source(s.body)}))")
|
|
213
|
+
return Group(self.stm(s.body))
|
|
214
|
+
self._record("NS_Stm_skip", "sem_S", s, "id")
|
|
215
|
+
return IdT()
|
|
216
|
+
|
|
217
|
+
def aexp(self, a: ast.Aexp) -> Term:
|
|
218
|
+
if isinstance(a, ast.Num):
|
|
219
|
+
self._record("NS_A_Num", "sem_A", a, str(a.value))
|
|
220
|
+
return Const(a.value)
|
|
221
|
+
if isinstance(a, ast.Var):
|
|
222
|
+
self._record("NS_A_Var", "sem_A", a, f"{a.name}⇒")
|
|
223
|
+
return Denom(a.name)
|
|
224
|
+
name = ARITH_NAMES[a.op]
|
|
225
|
+
rule = {"add": "NS_A_Add", "sub": "NS_A_Sub", "mult": "NS_A_Mult"}.get(name, f"NS_A_{name.title()}")
|
|
226
|
+
self._record(
|
|
227
|
+
rule, "sem_A", a, f"S^2({name}, sem_A({to_source(a.left)}), sem_A({to_source(a.right)}))"
|
|
228
|
+
)
|
|
229
|
+
return Superpos(name, (self.aexp(a.left), self.aexp(a.right)))
|
|
230
|
+
|
|
231
|
+
def bexp(self, b: ast.Bexp) -> Term:
|
|
232
|
+
if isinstance(b, ast.Compare):
|
|
233
|
+
name = COMPARE_NAMES[b.op]
|
|
234
|
+
self._record(
|
|
235
|
+
f"NS_B_{name}",
|
|
236
|
+
"sem_B",
|
|
237
|
+
b,
|
|
238
|
+
f"S^2({name}, sem_A({to_source(b.left)}), sem_A({to_source(b.right)}))",
|
|
239
|
+
)
|
|
240
|
+
return Superpos(name, (self.aexp(b.left), self.aexp(b.right)))
|
|
241
|
+
if isinstance(b, ast.Or):
|
|
242
|
+
self._record(
|
|
243
|
+
"NS_B_or", "sem_B", b, f"S^2(or, sem_B({to_source(b.left)}), sem_B({to_source(b.right)}))"
|
|
244
|
+
)
|
|
245
|
+
return Superpos("or", (self.bexp(b.left), self.bexp(b.right)))
|
|
246
|
+
self._record("NS_B_neg", "sem_B", b, f"S^1(neg, sem_B({to_source(b.operand)}))")
|
|
247
|
+
return Superpos("neg", (self.bexp(b.operand),))
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
def derive(program: ast.Program) -> Derivation:
|
|
251
|
+
"""Build the semantic term of a program with the list of applied rules."""
|
|
252
|
+
b = _Builder()
|
|
253
|
+
term = b.prog(program)
|
|
254
|
+
return Derivation(term, b.steps)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def sem_p(program: ast.Program) -> Term:
|
|
258
|
+
return derive(program).term
|
|
@@ -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
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
sipl/__init__.py,sha256=cEjEd6SE5dyMvZv6Gmb9GTK6wAStzi64MYo4sMedXxg,188
|
|
2
|
+
sipl/__main__.py,sha256=E6Gls0DNz8GQK2K-kOUIx8cYhgANW_CH54VKrfCfs14,52
|
|
3
|
+
sipl/ast.py,sha256=9NhKeLfHuzep5dK6qGxOytpUAAjpPVcjS9X2fPqHqFk,6033
|
|
4
|
+
sipl/cli.py,sha256=X955UZw4hPgwjrJHwybrhPzqcntfigwHGoVKye6gVeM,9862
|
|
5
|
+
sipl/diagnostics.py,sha256=qwjFX_Yf1jMy2QT7tqfxNL2b9yqSm0ojVn1wJSA9db8,1474
|
|
6
|
+
sipl/parser.py,sha256=uBOserEAXmMOvGSIhg0OFHLuo0a3Yy_dE-Ac5rDRKg0,6560
|
|
7
|
+
sipl/printer.py,sha256=WoD6kk31HcOn11wu1HIi3a8T_N4rMbZ0VO-ShOWsuyw,2312
|
|
8
|
+
sipl/grammar/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
sipl/grammar/sipl.lark,sha256=SNXYw53lCMi2mXIibXAXe7DPnL7KCETLIrwgXWX3xF4,1839
|
|
10
|
+
sipl/interpreter/__init__.py,sha256=PPtJbCz6zgCfaGyi8T31JCE-8l8GqyhOUll71mJXcns,478
|
|
11
|
+
sipl/interpreter/events.py,sha256=YElY09s5W7O7qeTZtl7qdAT5sPPZMyHxDqX1AbPgX4Q,1137
|
|
12
|
+
sipl/interpreter/runtime.py,sha256=ph0Kc0T_AgHTxqTaFmuBRi5418OuLAFGR1UFhxeD4ec,6807
|
|
13
|
+
sipl/semantics/__init__.py,sha256=p1HUHTseHClffMWQMiDJDx33kViZHp8P_c_C3eG0f7c,444
|
|
14
|
+
sipl/semantics/terms.py,sha256=_nsnj_2xxCkMyLA6TjzV5nLgRlLfIbX5Ax6Pqe4-Y0I,8471
|
|
15
|
+
sipl_kit-0.4.0.dist-info/METADATA,sha256=vxgaY5yerOGLKQyl-iy-zFAW5Zv9a5omhWCwyq6-30k,9062
|
|
16
|
+
sipl_kit-0.4.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
17
|
+
sipl_kit-0.4.0.dist-info/entry_points.txt,sha256=vre4JEfIcPIH7R5tPX66XHb0MOyBtGwL4Zx7a-xqi9g,39
|
|
18
|
+
sipl_kit-0.4.0.dist-info/licenses/LICENSE,sha256=lVpBjNb6EsnN_LDXUyh8ZLQ6ZN89s8da9aw-newIJm8,1070
|
|
19
|
+
sipl_kit-0.4.0.dist-info/RECORD,,
|
|
@@ -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.
|