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.4.tar.gz (3.5 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.4-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: s_lang_mta-0.1.4.tar.gz
  • Upload date:
  • Size: 3.5 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.4.tar.gz
Algorithm Hash digest
SHA256 363b7a516a1245916586aeae22bdecd727d760bd0cafa0772ddfc545beecec91
MD5 3e990fc79418ba0895a5d4dc3ce495fa
BLAKE2b-256 3ce44b6c5586346be4241f46df7aadc5e1286ff4db8319f06727f233ed03fa23

See more details on using hashes here.

File details

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

File metadata

  • Download URL: s_lang_mta-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 4.9 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f6365d806870e86d0ded9e1ef7818ac33d58263d27aca146e18ef40fc24f7a9f
MD5 3cb6be8f242cb941b034320b17539b3b
BLAKE2b-256 ac7a8b246bb70be951ef04bcf607f05714d923a28c01b734b282e66b2adaf5d7

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