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.3.tar.gz (4.1 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.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: s_lang_mta-0.1.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.0 Windows/10

File hashes

Hashes for s_lang_mta-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b55dfd4f99751e0aa7d3dd23348cb04fa3f2b3fddc591eb269e366ba26376060
MD5 c6513765071fad2e991b143da71435f6
BLAKE2b-256 de466a24b5b57338033e1709bb398b2533f496d5e196961a60c31307b68ac99e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: s_lang_mta-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.0 Windows/10

File hashes

Hashes for s_lang_mta-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 47da3cdce4b7ece7dd794055337f1ac58264329b24e2722682af5e4767fe5739
MD5 c97d4e665b287d9dcc42327818417146
BLAKE2b-256 d642f9239115bda60c90d7c19a73758e2b03e8861e8d970034272e3af39852b1

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