Skip to main content

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.7.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

s_lang_mta-0.1.7-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file s_lang_mta-0.1.7.tar.gz.

File metadata

  • Download URL: s_lang_mta-0.1.7.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

Hashes for s_lang_mta-0.1.7.tar.gz
Algorithm Hash digest
SHA256 a5b9f621b59f9b3e4a92606962952c8023e04780486adc4af3af3f82185aae0b
MD5 dc58fb4a1ae85c5a932b7b671738bd7a
BLAKE2b-256 5b5792463cb5f10deea01ef42c438c66f3345a99edbb8b8b2127c1af58175eaf

See more details on using hashes here.

File details

Details for the file s_lang_mta-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: s_lang_mta-0.1.7-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

Hashes for s_lang_mta-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0a9d972b54a17e5fccc968cc2e1f79c369e90e842c003b2d6d9f8075f2606650
MD5 fdd3dc230c223b61771ce030e8e8b836
BLAKE2b-256 ab5b3caac7294edb6d7bf6bc85d2c2977e403f7e53bfaabdd378260332fbd659

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page