pystacker 1.8.0__tar.gz → 1.9.2__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.
- {pystacker-1.8.0 → pystacker-1.9.2}/PKG-INFO +134 -86
- {pystacker-1.8.0 → pystacker-1.9.2}/README.md +127 -80
- pystacker-1.9.2/pyproject.toml +41 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/pystacker.egg-info/PKG-INFO +134 -86
- pystacker-1.9.2/pystacker.egg-info/SOURCES.txt +99 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/pystacker.egg-info/entry_points.txt +0 -1
- pystacker-1.9.2/pystacker.egg-info/requires.txt +1 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/pystacker.egg-info/top_level.txt +0 -1
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/__main__.py +9 -8
- pystacker-1.9.2/stacker/engine/__init__.py +14 -0
- {pystacker-1.8.0/stacker → pystacker-1.9.2/stacker/engine}/core.py +374 -106
- {pystacker-1.8.0/stacker → pystacker-1.9.2/stacker/engine}/data_type.py +42 -1
- pystacker-1.9.2/stacker/engine/scope.py +243 -0
- pystacker-1.9.2/stacker/engine/sfunction.py +43 -0
- {pystacker-1.8.0/stacker → pystacker-1.9.2/stacker/engine}/slambda.py +8 -6
- pystacker-1.9.2/stacker/error_formatter.py +235 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/lib/ui_tools.py +4 -4
- pystacker-1.9.2/stacker/manager/__init__.py +3 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/defmacro.py +1 -1
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/defun.py +1 -1
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/eval.py +0 -20
- pystacker-1.9.2/stacker/operators/file.py +112 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/hof.py +15 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/lmd.py +1 -1
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/loop.py +12 -2
- pystacker-1.8.0/stacker/manager/operator_manager.py → pystacker-1.9.2/stacker/operators/manager.py +97 -41
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/math.py +11 -0
- pystacker-1.9.2/stacker/operators/os.py +49 -0
- pystacker-1.9.2/stacker/operators/setting.py +35 -0
- pystacker-1.9.2/stacker/operators/system.py +119 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/transform.py +2 -6
- pystacker-1.9.2/stacker/runtime/__init__.py +15 -0
- pystacker-1.9.2/stacker/runtime/exec_modes/__init__.py +13 -0
- {pystacker-1.8.0/stacker → pystacker-1.9.2/stacker/runtime}/exec_modes/commandline_mode.py +2 -2
- {pystacker-1.8.0/stacker → pystacker-1.9.2/stacker/runtime}/exec_modes/error.py +4 -0
- pystacker-1.9.2/stacker/runtime/exec_modes/execution_mode.py +215 -0
- pystacker-1.9.2/stacker/runtime/exec_modes/repl_mode.py +343 -0
- pystacker-1.9.2/stacker/runtime/exec_modes/script_mode.py +138 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/stacker.py +4 -24
- pystacker-1.9.2/stacker/syntax/lexer.py +210 -0
- pystacker-1.9.2/stacker/syntax/parser.py +376 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/syntax/test_parser.py +47 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/util/disp.py +5 -15
- {pystacker-1.8.0 → pystacker-1.9.2}/test/test_aggregate.py +6 -39
- pystacker-1.9.2/test/test_error_formatter.py +140 -0
- pystacker-1.9.2/test/test_error_messages.py +153 -0
- pystacker-1.9.2/test/test_inline_comments.py +178 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/test/test_lambda.py +2 -4
- pystacker-1.9.2/test/test_no_dollar_in_blocks.py +63 -0
- pystacker-1.9.2/test/test_no_dollar_syntax.py +164 -0
- pystacker-1.9.2/test/test_reduce.py +75 -0
- pystacker-1.9.2/test/test_scope.py +886 -0
- pystacker-1.8.0/test/test_operator.py → pystacker-1.9.2/test/test_stacker.py +8 -43
- pystacker-1.9.2/test/test_string_apostrophe.py +72 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/test/test_transform.py +5 -33
- pystacker-1.8.0/pystacker.egg-info/SOURCES.txt +0 -103
- pystacker-1.8.0/pystacker.egg-info/requires.txt +0 -1
- pystacker-1.8.0/setup.py +0 -47
- pystacker-1.8.0/stacker/exec_modes/__init__.py +0 -13
- pystacker-1.8.0/stacker/exec_modes/excution_mode.py +0 -151
- pystacker-1.8.0/stacker/exec_modes/repl_mode.py +0 -206
- pystacker-1.8.0/stacker/exec_modes/script_mode.py +0 -65
- pystacker-1.8.0/stacker/lib/function/file.py +0 -35
- pystacker-1.8.0/stacker/lib/function/setting.py +0 -95
- pystacker-1.8.0/stacker/manager/__init__.py +0 -3
- pystacker-1.8.0/stacker/sfunction.py +0 -32
- pystacker-1.8.0/stacker/slib/macro.stk +0 -0
- pystacker-1.8.0/stacker/slib/sfunction.stk +0 -5
- pystacker-1.8.0/stacker/syntax/lexer.py +0 -79
- pystacker-1.8.0/stacker/syntax/parser.py +0 -518
- pystacker-1.8.0/stacker/syntax/test_lexer.py +0 -48
- pystacker-1.8.0/stacker/valiable.py +0 -80
- pystacker-1.8.0/test/__init__.py +0 -0
- pystacker-1.8.0/test/test_algebra_operator.py +0 -19
- pystacker-1.8.0/test/test_arith_operator.py +0 -198
- pystacker-1.8.0/test/test_base_operator.py +0 -65
- pystacker-1.8.0/test/test_bitwise_operator.py +0 -99
- pystacker-1.8.0/test/test_block.py +0 -28
- pystacker-1.8.0/test/test_comparation_operator.py +0 -99
- pystacker-1.8.0/test/test_hpf_operator.py +0 -59
- pystacker-1.8.0/test/test_list_operator.py +0 -49
- pystacker-1.8.0/test/test_logic_operator.py +0 -46
- pystacker-1.8.0/test/test_math_operator.py +0 -284
- pystacker-1.8.0/test/test_special_operator.py +0 -93
- pystacker-1.8.0/test/test_stack_operator.py +0 -211
- pystacker-1.8.0/test/test_token.py +0 -94
- {pystacker-1.8.0 → pystacker-1.9.2}/LICENSE +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/pystacker.egg-info/dependency_links.txt +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/setup.cfg +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/__init__.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/constant.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/data/about.txt +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/data/help.txt +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/data/top.txt +0 -0
- {pystacker-1.8.0/stacker → pystacker-1.9.2/stacker/engine}/smacro.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/error.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/include/__init__.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/include/include.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/include/stk_file_read.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/lib/__init__.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/lib/config.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/__init__.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/aggregate.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/algebra.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/arith.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/base.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/bitwise.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/comparison.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/exit.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/if_else.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/include.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/io.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/list.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/logic.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/random.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/stack.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/string.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/time.py +0 -0
- {pystacker-1.8.0/stacker/lib/function → pystacker-1.9.2/stacker/operators}/types.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/plugins/__init__.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/plugins/matrix.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/plugins/whos.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/reserved.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/slib/__init__.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/syntax/__init__.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/util/__init__.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/stacker/util/color.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/test/test_defmacro.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/test/test_defun.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/test/test_if_else_statement.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/test/test_include.py +0 -0
- {pystacker-1.8.0 → pystacker-1.9.2}/test/test_loop_statement.py +0 -0
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: pystacker
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.9.2
|
|
4
4
|
Summary: Stacker: RPN Calculator in Python
|
|
5
|
-
Home-page: https://github.com/remokasu/stacker
|
|
6
5
|
Author: remokasu
|
|
7
6
|
License: MIT License
|
|
8
7
|
|
|
@@ -26,10 +25,13 @@ License: MIT License
|
|
|
26
25
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
26
|
SOFTWARE.
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
Project-URL: Homepage, https://github.com/remokasu/stacker
|
|
29
|
+
Keywords: reverse-polish-calculator,rpn,terminal-app
|
|
30
|
+
Requires-Python: >=3.10
|
|
31
31
|
Description-Content-Type: text/markdown
|
|
32
32
|
License-File: LICENSE
|
|
33
|
+
Requires-Dist: prompt-toolkit>=3.0.0
|
|
34
|
+
Dynamic: license-file
|
|
33
35
|
|
|
34
36
|
# Stacker: An RPN Calculator and Extensible Programming Language
|
|
35
37
|
|
|
@@ -38,6 +40,19 @@ License-File: LICENSE
|
|
|
38
40
|
|
|
39
41
|
Stacker is a powerful Reverse Polish Notation (RPN) calculator built with Python, featuring basic mathematical operations and extensibility through plugins.
|
|
40
42
|
|
|
43
|
+
## Table of Contents
|
|
44
|
+
|
|
45
|
+
- [Installation](#installation)
|
|
46
|
+
- [Dependencies](#dependencies)
|
|
47
|
+
- [Usage](#usage)
|
|
48
|
+
- [Running Scripts](#running-scripts)
|
|
49
|
+
- [VSCode Syntax Highlighting](#vscode-syntax-highlighting)
|
|
50
|
+
- [Error Formatting](#error-formatting)
|
|
51
|
+
- [Command Line Execution](#command-line-execution)
|
|
52
|
+
- [Configuration File](#configuration-file)
|
|
53
|
+
- [Creating Plugins](#creating-plugins)
|
|
54
|
+
- [Supported Operations](#supported-operations)
|
|
55
|
+
|
|
41
56
|
## Installation
|
|
42
57
|
|
|
43
58
|
```bash
|
|
@@ -46,6 +61,16 @@ cd stacker
|
|
|
46
61
|
pip install .
|
|
47
62
|
```
|
|
48
63
|
|
|
64
|
+
### Optional: VSCode Syntax Highlighting
|
|
65
|
+
|
|
66
|
+
For syntax highlighting support in VSCode:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
cp -r .vscode-extension ~/.vscode/extensions/stacker-language
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Reload VSCode (Ctrl+Shift+P → "Developer: Reload Window") and `.stk` files will be highlighted.
|
|
73
|
+
|
|
49
74
|
|
|
50
75
|
## Dependencies
|
|
51
76
|
|
|
@@ -132,20 +157,29 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
132
157
|
- ### Variables:
|
|
133
158
|
- syntax:
|
|
134
159
|
``` bash
|
|
135
|
-
value
|
|
160
|
+
value name set
|
|
161
|
+
# or
|
|
162
|
+
value name =
|
|
136
163
|
```
|
|
137
164
|
- example:
|
|
138
165
|
```bash
|
|
139
|
-
stacker:0> 3
|
|
140
|
-
```
|
|
141
|
-
In this example, we assign `3` to `x`.
|
|
142
|
-
If you input an undefined symbol, you need to prefix the symbol name with a dollar sign ($). <br>
|
|
143
|
-
Hereafter, when x is used, 3 will be pushed onto the stack. Additionally, when using predefined symbols, the dollar sign is not required.
|
|
144
|
-
``` bash
|
|
145
|
-
stacker:0> 3 $x set
|
|
166
|
+
stacker:0> 3 x set
|
|
146
167
|
stacker:1> x
|
|
147
168
|
[3]
|
|
169
|
+
|
|
170
|
+
# Using = operator (equivalent to set)
|
|
171
|
+
stacker:2> 5 y =
|
|
172
|
+
stacker:3> y
|
|
173
|
+
[5]
|
|
148
174
|
```
|
|
175
|
+
In this example, we assign `3` to `x` using `set`, and `5` to `y` using `=`. Both operators work identically.
|
|
176
|
+
|
|
177
|
+
**Note:** The `$` prefix (e.g., `$x`) is supported for backward compatibility but no longer required.
|
|
178
|
+
|
|
179
|
+
**Note:** The `=` operator is an alias for `set` and can be used interchangeably. Use whichever feels more natural for your coding style.
|
|
180
|
+
|
|
181
|
+
**Important:** Avoid using built-in operator names (like `sum`, `max`, `min`) as variable names,
|
|
182
|
+
as this will shadow the operator. See [VARIABLE_NAMING.md](VARIABLE_NAMING.md) for details.
|
|
149
183
|
|
|
150
184
|
- Arrays:
|
|
151
185
|
- Single-line array:
|
|
@@ -162,50 +196,41 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
162
196
|
```
|
|
163
197
|
|
|
164
198
|
|
|
165
|
-
- ### Code blocks:
|
|
166
|
-
|
|
167
|
-
Code blocks are enclosed in curly braces ({}). These blocks are pushed onto the stack in their raw form and can be executed later. For example: {1 2 +}. These blocks are particularly useful for deferred (lazy) evaluation. Specific use-cases include conditional statements and loop controls.
|
|
168
|
-
|
|
169
|
-
- syntax:
|
|
170
|
-
```bash
|
|
171
|
-
{1 2 +}
|
|
172
|
-
```
|
|
173
|
-
- example:
|
|
174
|
-
```bash
|
|
175
|
-
stacker:0> {1 2 +}
|
|
176
|
-
[{1 2 +}]
|
|
177
|
-
```
|
|
178
|
-
In this command, the block `{1 2 +}` is pushed (added) to the stack.
|
|
179
|
-
|
|
180
199
|
- ### Code Blocks
|
|
181
200
|
|
|
182
|
-
Code blocks
|
|
201
|
+
Code blocks are fundamental structures in Stacker that enable deferred evaluation and control flow management. They are enclosed in curly braces `{}`.
|
|
183
202
|
|
|
184
|
-
Syntax
|
|
203
|
+
**Syntax:**
|
|
185
204
|
```bash
|
|
186
205
|
{code_elements}
|
|
187
206
|
```
|
|
188
207
|
|
|
189
|
-
Key Characteristics
|
|
190
|
-
1.
|
|
191
|
-
2.
|
|
192
|
-
3.
|
|
193
|
-
4. Execution: Code blocks can be executed at a later time when needed.
|
|
208
|
+
**Key Characteristics:**
|
|
209
|
+
1. **Deferred Evaluation**: Code blocks are not executed immediately when encountered
|
|
210
|
+
2. **Stack Interaction**: Pushed onto the stack as single units in their raw form
|
|
211
|
+
3. **Delayed Execution**: Can be executed later when needed (via `eval`, `if`, `times`, etc.)
|
|
194
212
|
|
|
195
|
-
Common Use Cases
|
|
196
|
-
- Conditional statements
|
|
197
|
-
- Loop controls
|
|
198
|
-
- Function definitions
|
|
213
|
+
**Common Use Cases:**
|
|
214
|
+
- Conditional statements (`if`, `ifelse`)
|
|
215
|
+
- Loop controls (`times`, `do`, `dolist`)
|
|
216
|
+
- Function definitions (`defun`, `lambda`)
|
|
217
|
+
- Lazy evaluation patterns
|
|
199
218
|
|
|
200
|
-
|
|
219
|
+
**Examples:**
|
|
201
220
|
```bash
|
|
221
|
+
# Create a code block
|
|
202
222
|
stacker:0> {1 2 +}
|
|
203
223
|
[{1 2 +}]
|
|
204
|
-
```
|
|
205
224
|
|
|
206
|
-
|
|
225
|
+
# Execute with eval
|
|
226
|
+
stacker:1> {1 2 +} eval
|
|
227
|
+
[3]
|
|
228
|
+
|
|
229
|
+
# Use in function definitions
|
|
230
|
+
stacker:2> {x y} {x y *} multiply defun
|
|
231
|
+
```
|
|
207
232
|
|
|
208
|
-
Note
|
|
233
|
+
**Note**: Code blocks are stored but not executed until explicitly triggered. This allows for flexible program control, lazy evaluation, and higher-order programming patterns.
|
|
209
234
|
|
|
210
235
|
- ### Control Structures in Stacker
|
|
211
236
|
|
|
@@ -226,7 +251,7 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
226
251
|
|
|
227
252
|
Example:
|
|
228
253
|
```bash
|
|
229
|
-
stacker:0> 0
|
|
254
|
+
stacker:0> 0 x set
|
|
230
255
|
stacker:1> x 0 == {3 4 +} if
|
|
231
256
|
[7]
|
|
232
257
|
```
|
|
@@ -244,7 +269,7 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
244
269
|
|
|
245
270
|
Example:
|
|
246
271
|
```bash
|
|
247
|
-
stacker:0> 0
|
|
272
|
+
stacker:0> 0 x set
|
|
248
273
|
stacker:1> x 0 == {3 4 +} {3 4 -} ifelse
|
|
249
274
|
[7]
|
|
250
275
|
```
|
|
@@ -261,12 +286,12 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
261
286
|
|
|
262
287
|
Syntax:
|
|
263
288
|
```bash
|
|
264
|
-
start_value end_value
|
|
289
|
+
start_value end_value symbol {body} do
|
|
265
290
|
```
|
|
266
291
|
|
|
267
292
|
Example:
|
|
268
293
|
```bash
|
|
269
|
-
stacker:0> 1 10
|
|
294
|
+
stacker:0> 1 10 i {i echo} do
|
|
270
295
|
1
|
|
271
296
|
2
|
|
272
297
|
3
|
|
@@ -279,7 +304,7 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
279
304
|
10
|
|
280
305
|
```
|
|
281
306
|
|
|
282
|
-
Result: Prints numbers from
|
|
307
|
+
Result: Prints numbers from 1 to 10.
|
|
283
308
|
|
|
284
309
|
- ##### dolist
|
|
285
310
|
|
|
@@ -287,12 +312,12 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
287
312
|
|
|
288
313
|
Syntax:
|
|
289
314
|
```bash
|
|
290
|
-
[value1 value2 ... valueN]
|
|
315
|
+
[value1 value2 ... valueN] symbol {body} dolist
|
|
291
316
|
```
|
|
292
317
|
|
|
293
318
|
Example:
|
|
294
319
|
```bash
|
|
295
|
-
stacker:0> [1 2 3 4 5]
|
|
320
|
+
stacker:0> [1 2 3 4 5] i {i echo} dolist
|
|
296
321
|
1
|
|
297
322
|
2
|
|
298
323
|
3
|
|
@@ -329,8 +354,8 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
329
354
|
```
|
|
330
355
|
- example:
|
|
331
356
|
```bash
|
|
332
|
-
stacker:0> 0
|
|
333
|
-
stacker:1> 0 9
|
|
357
|
+
stacker:0> 0 i set
|
|
358
|
+
stacker:1> 0 9 i {{break} i 5 == if i echo} do
|
|
334
359
|
0
|
|
335
360
|
1
|
|
336
361
|
2
|
|
@@ -343,11 +368,11 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
343
368
|
- ### Define a function:
|
|
344
369
|
- syntax:
|
|
345
370
|
```bash
|
|
346
|
-
{arg1 arg2 ... argN} {body}
|
|
371
|
+
{arg1 arg2 ... argN} {body} name defun
|
|
347
372
|
```
|
|
348
373
|
- example:
|
|
349
374
|
```bash
|
|
350
|
-
stacker:0> {x y} {x y *}
|
|
375
|
+
stacker:0> {x y} {x y *} multiply defun
|
|
351
376
|
stacker:1> 10 20 multiply
|
|
352
377
|
[200]
|
|
353
378
|
```
|
|
@@ -356,11 +381,11 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
356
381
|
- ### Define a macro:
|
|
357
382
|
- syntax:
|
|
358
383
|
```bash
|
|
359
|
-
{body}
|
|
384
|
+
{body} name defmacro
|
|
360
385
|
```
|
|
361
386
|
- example:
|
|
362
387
|
```bash
|
|
363
|
-
stacker:0> {2 ^ 3 * 5 +}
|
|
388
|
+
stacker:0> {2 ^ 3 * 5 +} calculatePowerAndAdd defmacro
|
|
364
389
|
stacker:1> 5 calculatePowerAndAdd
|
|
365
390
|
[80]
|
|
366
391
|
```
|
|
@@ -381,7 +406,7 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
381
406
|
|
|
382
407
|
- example:
|
|
383
408
|
```bash
|
|
384
|
-
stacker:0> {x y} {x y *} lambda
|
|
409
|
+
stacker:0> {x y} {x y *} lambda multiply set
|
|
385
410
|
stacker:1> 3 4 multiply
|
|
386
411
|
[12]
|
|
387
412
|
```
|
|
@@ -396,32 +421,14 @@ Stacker allows for straightforward RPN input. For example:
|
|
|
396
421
|
```
|
|
397
422
|
All functions, macros and variables defined in "my_script.stk" are added to the current stack.
|
|
398
423
|
|
|
399
|
-
- ### File Writing and Reading
|
|
400
|
-
- Writing to a file:
|
|
401
|
-
```bash
|
|
402
|
-
stacker:0> "output.txt" "hoge" write
|
|
403
|
-
```
|
|
404
|
-
This writes the string "hoge" to the file "output.txt".
|
|
405
|
-
|
|
406
|
-
- Reading from a file:
|
|
407
|
-
```bash
|
|
408
|
-
stacker:0> "output.txt" read
|
|
409
|
-
[hoge]
|
|
410
|
-
```
|
|
411
|
-
This reads the contents of "output.txt" and executes it.
|
|
412
|
-
|
|
413
|
-
```
|
|
414
|
-
stacker:0> "output.txt" read $text set
|
|
415
|
-
```
|
|
416
|
-
You can also set the contents of the file to a variable using the `set` command.
|
|
417
424
|
|
|
418
425
|
## Running Scripts
|
|
419
426
|
Stacker scripts can be created in `.stk` files. To run a script, simply execute it with Stacker. For example:
|
|
420
427
|
|
|
421
428
|
- my_script.stk:
|
|
422
429
|
```bash
|
|
423
|
-
0
|
|
424
|
-
0 100000
|
|
430
|
+
0 p set
|
|
431
|
+
0 100000 k {
|
|
425
432
|
-1 k ^ 2 k * 1 + / p + p set
|
|
426
433
|
} do
|
|
427
434
|
4 p * p set
|
|
@@ -434,6 +441,42 @@ Stacker scripts can be created in `.stk` files. To run a script, simply execute
|
|
|
434
441
|
```
|
|
435
442
|
|
|
436
443
|
|
|
444
|
+
## VSCode Syntax Highlighting
|
|
445
|
+
|
|
446
|
+
Stacker provides syntax highlighting support for `.stk` files in Visual Studio Code, making it easier to read and write Stacker code.
|
|
447
|
+
|
|
448
|
+
### Installation
|
|
449
|
+
|
|
450
|
+
Install the syntax highlighting extension by copying it to your VSCode extensions directory:
|
|
451
|
+
|
|
452
|
+
```bash
|
|
453
|
+
# For VSCode Server (Remote SSH)
|
|
454
|
+
mkdir -p ~/.vscode-server/extensions/stacker-language-0.1.0
|
|
455
|
+
cp -r .vscode-extension/* ~/.vscode-server/extensions/stacker-language-0.1.0/
|
|
456
|
+
|
|
457
|
+
# For local VSCode
|
|
458
|
+
mkdir -p ~/.vscode/extensions/stacker-language-0.1.0
|
|
459
|
+
cp -r .vscode-extension/* ~/.vscode/extensions/stacker-language-0.1.0/
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
Then reload VSCode (Ctrl+Shift+P → "Developer: Reload Window").
|
|
463
|
+
|
|
464
|
+
### Features
|
|
465
|
+
|
|
466
|
+
- **Comment highlighting** (`#`) - Green, italic
|
|
467
|
+
- **String literals** (`"..."`, `'...'`) - Brown
|
|
468
|
+
- **Number literals** (`42`, `3.14`, `0xFF`, `0b1010`) - Light green
|
|
469
|
+
- **Operators** (`+`, `-`, `and`, `or`, etc.) - Blue
|
|
470
|
+
- **Control flow** (`if`, `do`, `times`) - Purple
|
|
471
|
+
- **Function definitions** (`defun`, `defmacro`, `lambda`) - Teal, bold
|
|
472
|
+
- **Variables** (`$x`, `a`) - Light blue
|
|
473
|
+
- **Assignment** (`set`, `=`, `global`) - White, bold
|
|
474
|
+
- Auto-closing brackets (`{`, `[`, `"`, `'`)
|
|
475
|
+
- Code folding support
|
|
476
|
+
|
|
477
|
+
For detailed installation instructions, see [VSCODE_SETUP.md](VSCODE_SETUP.md).
|
|
478
|
+
|
|
479
|
+
|
|
437
480
|
## Command Line Execution
|
|
438
481
|
You can directly execute a specified RPN expression from the command line.
|
|
439
482
|
|
|
@@ -499,7 +542,7 @@ You can automatically load settings at startup. The configuration file should be
|
|
|
499
542
|
```bash
|
|
500
543
|
disable_disp_logo
|
|
501
544
|
disable_disp_stack
|
|
502
|
-
|
|
545
|
+
enable_disp_ans
|
|
503
546
|
```
|
|
504
547
|
|
|
505
548
|
## Creating Plugins
|
|
@@ -648,6 +691,7 @@ print(stacker.eval("3 4 +"))
|
|
|
648
691
|
| random | Generate a random floating-point number between 0 and 1| `random` |
|
|
649
692
|
| randint | Generate a random integer within a specified range | `1 6 randint` |
|
|
650
693
|
| uniform | Generate a random floating-point number within a specified range | `1 2 uniform` |
|
|
694
|
+
| frac | Fraction | `3 6 frac` |
|
|
651
695
|
| dice | Roll dice (e.g., 3d6) | `3 6 dice` |
|
|
652
696
|
|
|
653
697
|
|
|
@@ -681,7 +725,7 @@ print(stacker.eval("3 4 +"))
|
|
|
681
725
|
| if | Conditional statement | `{...} true if` |
|
|
682
726
|
| ifelse | Conditional statement with an else block | `{true block} {false block} true ifelse` |
|
|
683
727
|
| iferror | Conditional statement for error handling | `{try block} {catch block} iferror` |
|
|
684
|
-
| do | Loop | `0 10
|
|
728
|
+
| do | Loop | `0 10 i {i echo} do` |
|
|
685
729
|
| times | Loop a specified number of times | `{dup ++} 10 times` |
|
|
686
730
|
| break | Break out of a loop | `break` |
|
|
687
731
|
|
|
@@ -689,10 +733,12 @@ print(stacker.eval("3 4 +"))
|
|
|
689
733
|
### Function, Macro, Lambda, and Variable Operators
|
|
690
734
|
| Operator | Description | Example |
|
|
691
735
|
|----------|-------------------------------------------------------|----------------------------|
|
|
692
|
-
| defun | Define a function | `{x y} {x y *}
|
|
693
|
-
| defmacro | Define a macro | `{2 ^ 3 * 5 +}
|
|
736
|
+
| defun | Define a function | `{x y} {x y *} multiply defun` |
|
|
737
|
+
| defmacro | Define a macro | `{2 ^ 3 * 5 +} calculatePowerAndAdd defmacro` |
|
|
694
738
|
| lambda | Create a lambda function | `{x y} {x y *} lambda` |
|
|
695
|
-
| set | Assign a value to a variable | `3
|
|
739
|
+
| set | Assign a value to a variable | `3 x set` |
|
|
740
|
+
| = | Assign a value to a variable (alias for `set`) | `3 x =` |
|
|
741
|
+
| global | Assign a value to a global variable | `42 $answer global` |
|
|
696
742
|
|
|
697
743
|
|
|
698
744
|
### Array Operators
|
|
@@ -712,11 +758,14 @@ print(stacker.eval("3 4 +"))
|
|
|
712
758
|
| subn | Cluster elements between the top and the nth (make substacks) | `3 subn` |
|
|
713
759
|
| include | Include the specified file | `"file.stk" include` |
|
|
714
760
|
| eval | Evaluate the specified RPN expression | `'3 5 +' eval` |
|
|
715
|
-
| evalpy | Evaluate the specified Python expression | `'3+5' evalpy` |
|
|
716
761
|
| echo | Print the specified value to stdout without adding it to the stack | `3 4 + echo` |
|
|
717
762
|
| input | Get input from the user | `input` |
|
|
718
|
-
| read |
|
|
719
|
-
| write
|
|
763
|
+
| read | Reads a string from the console | `read` |
|
|
764
|
+
| write-to-file | Write the top element of the stack to a file | `3 "output.txt" write-to-file` |
|
|
765
|
+
| append-to-file | Append the top element of the stack to a file | `3 "output.txt" append-to-file` |
|
|
766
|
+
| read-from-file | Read the contents of a file and push it to the stack | `"input.txt" read-from-file` |
|
|
767
|
+
| file-exists | Check if a file exists | `"file.txt" file-exists` |
|
|
768
|
+
|
|
720
769
|
|
|
721
770
|
|
|
722
771
|
## Constants
|
|
@@ -729,4 +778,3 @@ print(stacker.eval("3 4 +"))
|
|
|
729
778
|
| inf | Infinity |
|
|
730
779
|
| true | Boolean true |
|
|
731
780
|
| false | Boolean false |
|
|
732
|
-
|