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.6.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.6-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: s_lang_mta-0.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 8214d90be2a1966c8c29a7c6195a76da20e2c8e190913659e48e0b537f3f248d
MD5 ce25b3a6cea620d40932ecd3ac46023c
BLAKE2b-256 9d084c159498d36a42d784d639f50bf74aa016ab0671419f38c1d61c51a3d5ca

See more details on using hashes here.

File details

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

File metadata

  • Download URL: s_lang_mta-0.1.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 8b1d24c757b1e4464fbc10461e11e0a1713d094633d1eab3c540a65a3c01b082
MD5 3d7b7b4ddbb2303eea8828324c5aef86
BLAKE2b-256 16228249a5f903a48e7901077a90f4c28031a8b48f1e2b1a9b8408be41c8336a

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