S lang interpreter
Project description
s-lang
s-lang interpreter
Basic usage:
from s_lang import run
def main() -> None:
inputs = [5]
code = """
Z <- Z + 1
[A] IF X != 0 GOTO B
IF Z != 0 GOTO E
[B] Y <- Y + 1
X <- X - 1
IF Z != 0 GOTO A
"""
result: int = run(code, inputs)
print(result)
if __name__ == "__main__":
main()
Notes:
- The interpreter is sensitive to both white space and letter case.
- Variable names must be an upper-case X, Z or Y. X or Z vars may or may not have an adjacent positive index (X1, X2, Z10)
- Labels must be an upper-case letter and may or may not have an adjacent positive index (L, A1, B5)
- A variable or label which are not indexed will be indexed by 1 as default
Instruction with tags:
[L] {...}
Supported commands:
| V <- V | V: VAR | assign V to itself |
|---|---|---|
| V <- V + 1 | V: VAR | increase V by 1 |
| V <- V - 1 | V: VAR | decrease V by 1 |
| IF V != 0 GOTO L | V: VAR, L:LABEL | if V is not eq to 0 jump to the instruction tagged with L, else continue to the next instruction |
| V <- V + k | V: VAR, k: CONST | increase V by k |
| V <- V - k | V: VAR, k: CONST | decrease V by k |
| IF V = 0 GOTO L | V: VAR, L: LABEL | if V is eq to 0 jump to the instruction tagged with L, else continue to the next instruction |
| GOTO L | L: LABEL | jump to the instruction tagged with L |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
s_lang_mta-0.1.5.tar.gz
(3.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file s_lang_mta-0.1.5.tar.gz.
File metadata
- Download URL: s_lang_mta-0.1.5.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.0 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69b71401635cd2a24e892b6c6ebf46f47d184230e6b6484f30e5c989eb446df4
|
|
| MD5 |
aa7097288cd0f38eaa55b7e6519f9efe
|
|
| BLAKE2b-256 |
d28fbad7064eccf289bf3d62d2a3c4765b2c85b1f5042db8f5eab0f60aca716d
|
File details
Details for the file s_lang_mta-0.1.5-py3-none-any.whl.
File metadata
- Download URL: s_lang_mta-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.0 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d37d5e48ba3dc7e141444524d811862db9cc7a0f0e866546f5e375ea83ea2f3
|
|
| MD5 |
0c0a80fc62e4b916717ced9485a04290
|
|
| BLAKE2b-256 |
dac5551537e4261f1026d748c9d10bc96b9162b615ef23859a4bac38c21f9e12
|