Skip to main content

Sup: an English-like programming language (MVP)

Project description

Sup Language

An English-like programming language (MVP) that emphasizes readability with deterministic semantics.

Quickstart

  1. Create a virtual environment and install:
python -m venv .venv
.venv\\Scripts\\activate
pip install -e .
  1. Run a program:
sup examples/06_mixed.sup
  1. Run tests:
pip install pytest
pytest

Language Tour (MVP)

Program structure:

sup
  print add 2 and 3
bye

Assignments and expressions:

sup
  set x to add 10 and 5
  print the result
  print subtract 3 from x
bye

Conditionals and loops:

sup
  set a to 5
  set b to 3
  if a is greater than b then
    print a
  end if
  repeat 3 times
    print multiply a and b
  end repeat
bye

Input:

sup
  ask for name
  print name
bye

Comments: lines starting with note are ignored.

Errors are reported with line numbers and suggestions.

Phase 2: Functions, Strings, Transpiler

Functions:

sup
  define function called area with width and height
    set result to multiply width and height
    return result
  end function

  print call area with 5 and 6
bye

Strings:

sup
  set name to "Ada"
  print name
bye

Transpiler to Python:

sup --emit python examples/07_functions.sup

Phase 3: Collections and Stdlib

Lists and Maps:

sup
  make list of 1, 2, 3
  push 4 to list
  print the list
  pop from list
  print the list

  make map
  set "name" to "Karthik" in map
  set "age" to 21 in map
  print get "name" from map
  delete "age" from map
  print the map
bye

Stdlib:

  • Math: power of A and B, sqrt of X, absolute of X
  • String: length of S, upper of S, lower of S, concat of A and B
  • List: push, pop, length of <list>

Indexing and access:

sup
  make list of 1, 2, 3
  print get 0 from list    # prints first element
  make map
  set "k" to 42 in map
  print get "k" from map
bye

Phase 4: Conditionals, Loops, Booleans

Conditionals with else:

sup
  if x is greater than 5
    print "big"
  else
    print "small"
  end if
bye

While and For Each:

sup
  set x to 0
  while x is less than 3
    print x
    set x to add x and 1
  end while

  make list of 1, 2, 3
  for each item in list
    print item
  end for
bye

Booleans:

  • Operators: and, or, not
  • Comparisons: is equal to, is not equal to, is greater than, is less than, is greater than or equal to, is less than or equal to

Phase 5: Errors and Imports

Errors:

sup
  try
    throw "oops"
  catch e
    print e
  finally
    print "done"
  end try
bye

Imports:

sup
  import mathlib
  print mathlib.pi
  from mathlib import square as sq
  print call sq with 3
bye

Notes:

  • Interpreter searches modules in SUP_PATH (os.pathsep-separated) then CWD.
  • Transpiler emits Python import/from statements; ensure modules exist as Python when executing transpiled code.

Additional built-ins

  • Math: min of A and B, max of A and B, floor of X, ceil of X
  • String: trim of S (strip whitespace), upper of S, lower of S, concat of A and B
  • Contains/join:
    • contains of L and X where L is a list (true if X in list)
    • contains of S and T where S,T are strings (substring check)
    • join of SEP and LIST (e.g., join of "," and list)

Error handling notes

  • throw <expr> raises a runtime error carrying the raw value of <expr>; in catch e, the variable e receives that raw value.
  • finally always runs whether the try body throws or not; if there is no catch, the error is re-raised after finally.

Circular imports

  • The interpreter detects circular imports and raises a friendly error identifying the module involved.

Test runner

  • To run tests reliably in terminals that buffer output, use:
\.venv\Scripts\python sup-lang\tools\run_tests.py

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

sup_lang-0.2.2.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

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

sup_lang-0.2.2-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file sup_lang-0.2.2.tar.gz.

File metadata

  • Download URL: sup_lang-0.2.2.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sup_lang-0.2.2.tar.gz
Algorithm Hash digest
SHA256 49a4add3ed0dedc8430aa341da2e42252b0b9766f306ccbda6f10ac5aaac5c10
MD5 389d06b1aded8b29a1e2a8146ce7e39c
BLAKE2b-256 f46ae6ec8f761a592982214b79ee7cd7c7d4a33437980295294462ce95022600

See more details on using hashes here.

File details

Details for the file sup_lang-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: sup_lang-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for sup_lang-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2bb781ec02bc6c0a6dedd27da60eff2df7f9a56002591bb62bcc03e2d7d22303
MD5 1c8f252aee2a121d4105e297eb97e3d7
BLAKE2b-256 2feb5672f0aa169deafd6baef984db5dc918dd50dc02fa3efa2e2d9212fc3dba

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