Morse programming language
Project description
Morse Lang
A tiny programming language written entirely in Morse code.
Built with:
Table of Contents
- What You Can Do
- Overview
- Getting Started
- How It Works
- Language Basics
- Web Frontend (Text โ Morse Translator)
- Development
What You Can Do
Morse Lang lets you write full Python programs using only dots (.) and dashes (-). Here's what you can build:
๐ข Variables
Create and store values in variables:
Python:
var x = 10
var y = 20
var name = "morse"
Morse:
...- .- .-. -..- -...- .---- -----
...- .- .-. -.-- -...- ..--- -----
...- .- .-. -.. .- -- . -...- .----. -- --- .-. ... . .----.
โ Math Operations
Perform arithmetic with addition, subtraction, multiplication, and division:
Python:
var result = 5 + 3
var product = 10 * 2
var difference = 100 - 25
var quotient = 20 / 4
Morse:
...- .- .-. .-. . ... ..- .-.. - -...- ..... .-.-. ...--
...- .- .-. .--. .-. --- -.. ..- -.-. - -...- .---- ----- -.-.- ..---
...- .- .-. -.. .. ..-. ..-. . .-. . -. -.-. . -...- .---- ----- ----- -....- ..--- .....
...- .- .-. --.- ..- --- - .. . -. - -...- ..--- ----- -..-. ....-
๐ Print Statements
Display output to the console:
Python:
print("Hello, World!")
print(42)
print(x + y)
Morse:
.--. .-. .. -. - -.--. .----. .... . .-.. .-.. --- --..-- .-- --- .-. .-.. -.. .----. -.--.-
.--. .-. .. -. - -.--. ....- ..--- -.--.-
.--. .-. .. -. - -.--. -..- .-.-. -.-- -.--.-
๐ For Loops
Iterate over a range of numbers:
Python:
for i in range(5):
print i
Morse:
..-. --- .-. .. .. -. .-. .- -. --. . -.--. ..... -.--.- --- --..--
.--. .-. .. -. - ..
Output:
0
1
2
3
4
๐ While Loops
Repeat code while a condition is true:
Python:
var count = 0
while count < 3:
print count
var count = count + 1
Morse:
...- .- .-. -.-. --- ..- -. - -...- -----
.-- .... .. .-.. . -.-. --- ..- -. - -....- ...--
.--. .-. .. -. - -.-. --- ..- -. -
...- .- .-. -.-. --- ..- -. - -...- -.-. --- ..- -. - .-.-. .----
Output:
0
1
2
โ๏ธ Functions
Define reusable functions with parameters and return values:
Python:
func greet():
print hello
print world
greet()
func add(a b):
return a + b
var result = add(3 5)
print result
Morse:
..-. ..- -. -.-. --. .-. . . - -.--. -.--.- --- --..--
.--. .-. .. -. - .... . .-.. .-.. ---
.--. .-. .. -. - .-- --- .-. .-.. -..
--. .-. . . - -.--. -.--.-
..-. ..- -. -.-. .- -.. -.. -.--. .- -... -.--.- --- --..--
.-. . - ..- .-. -. .- .-.-. -...
...- .- .-. .-. . ... ..- .-.. - -...- .- -.. -.. -.--. ...-- ..... -.--.-
.--. .-. .. -. - .-. . ... ..- .-.. -
Output:
hello
world
8
๐ฏ Complete Example
Here's a full program that combines all features:
Python:
func calculate_sum(a b):
return a + b
var x = 5
var y = 10
var total = calculate_sum(x y)
print total
for i in range(3):
print i
Morse:
..-. ..- -. -.-. -.-. .- .-.. -.-. ..- .-.. .- - . ... ..- -- -.--. .- -... -.--.- --- --..--
.-. . - ..- .-. -. .- .-.-. -...
...- .- .-. -..- -...- .....
...- .- .-. -.-- -...- .---- -----
...- .- .-. - --- - .- .-.. -...- -.-. .- .-.. -.-. ..- .-.. .- - . ... ..- -- -.--. -..- -.-- -.--.-
.--. .-. .. -. - - --- - .- .-..
..-. --- .-. .. .. -. .-. .- -. --. . -.--. ...-- -.--.- --- --..--
.--. .-. .. -. - ..
Output:
15
0
1
2
๐ก Note: Morse Lang supports all these features and more! You can combine variables, math, loops, and functions to build complex programs entirely in Morse code.
Overview
Morse Lang is a programming language where your source code is written entirely in Morse code. You write a .mc file using dots (.) and dashes (-), the morse CLI decodes it into Python, and then executes it.
It works the same way on macOS, Windows, and Linux as long as you have Python installed.
Use cases
- Learning / teaching Morse code with a fun programming twist
- Code golf / esolangs and experimentation
- Novel demos where the source file looks like radio traffic but runs like Python
How It Works
-
Step 1 โ Morse source (
.mc):
You create a file filled with Morse symbols (e.g..-,--..--) separated by spaces. -
Step 2 โ Decode to Python:
The CLI usesmorse_lang.morse_to_textandMORSE_MAPto translate each Morse token into a character, building a normal Python source file line by line. -
Step 3 โ Execute:
The decoded Python string is executed withexec(...)in a fresh namespace, just like running a regular.pyscript.
Because of this, Morse Lang programs can do anything Python can. Only run .mc files you trust, just as you would with untrusted Python code.
Getting Started
Prerequisites
- Python: 3.8 or newer (3.10+ recommended)
- Works on:
- macOS (tested on recent versions)
- Windows 10/11
- Linux (any modern distro)
You can check your Python version with:
python --version
On Windows, you may need:
py --version
Installation (from PyPI)
The simplest way is to install the package directly from PyPI.
- macOS / Linux (bash, zsh, etc.):
python -m pip install --upgrade pip
python -m pip install morse-lang
- Windows (PowerShell or Command Prompt):
py -m pip install --upgrade pip
py -m pip install morse-lang
After installation, the morse command should be available on your PATH.
Installation (from source)
If you are working directly with this repository:
git clone https://github.com/sharky-3/morse-programming-language.git
cd morse-programming-language
# (Optional but recommended) create a virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install --upgrade pip
python -m pip install -e .
This installs morse-lang in editable mode so changes to the source are reflected immediately.
Running Your First Morse Program
1. Try the included example
If you cloned this repository, you can immediately run the included example:
-
macOS / Linux:
morse examples/hello.mc -
Windows:
morse examples\hello.mc
You should see:
hello, world
2. Create your own program
Create a new file, for example my_program.mc, and add some Morse code:
Example: Simple math program
Create math.mc:
...- .- .-. -..- -...- .---- -----
...- .- .-. -.-- -...- .....
...- .- .-. ... ..- -- -...- -..- .-.-. -.--
.--. .-. .. -. - ... ..- --
Run it:
-
macOS / Linux:
morse math.mc -
Windows:
morse math.mc
Output:
15
Example: Try loops and functions
You can also run the included example with loops and functions:
-
macOS / Linux:
morse examples/loops_and_functions.mc -
Windows:
morse examples\loops_and_functions.mc
๐ก Tip: Use the Web Frontend to help translate your Python code to Morse code!
3. Troubleshooting: Command not found
If the morse command is not found after installation:
Windows:
# Try using Python module directly
py -m morse_lang.cli math.mc
# Or with full path
python -m morse_lang.cli math.mc
macOS / Linux:
# Try using Python module directly
python -m morse_lang.cli math.mc
# Or check if morse is in your PATH
which morse
If it's still not working, make sure:
- Python is installed and in your PATH
- You've activated your virtual environment (if using one)
- The package was installed successfully (
pip list | grep morse-lang)
Language Basics
At its core, Morse Lang is "Python in Morse". Each Morse token is mapped to a character using standard Morse code conventions:
๐ Syntax Rules
- Single space (
" ") between Morse codes โ separates letters within a word - Triple space (
" ") between sequences โ separates words - Each line in your
.mcfile โ one line of decoded Python
๐ค Morse Code Mapping
The mapping is defined in MORSE_MAP and includes:
Letters (A-Z)
.- โ a -... โ b -.-. โ c -.. โ d . โ e
..-. โ f --. โ g .... โ h .. โ i .--- โ j
-.- โ k .-.. โ l -- โ m -. โ n --- โ o
.--. โ p --.- โ q .-. โ r ... โ s - โ t
..- โ u ...- โ v .-- โ w -..- โ x -.-- โ y
--.. โ z
Digits (0-9)
----- โ 0 .---- โ 1 ..--- โ 2 ...-- โ 3 ....- โ 4
..... โ 5 -.... โ 6 --... โ 7 ---.. โ 8 ----. โ 9
Math Operators
.-.-. โ + (addition)
-....- โ - (subtraction)
-.-.- โ * (multiplication)
-..-. โ / (division)
-...- โ = (assignment/equality)
Punctuation & Symbols
--..-- โ , (comma)
...... โ . (period)
.----. โ ' (apostrophe)
-.--. โ ( (left parenthesis)
-.--.- โ ) (right parenthesis)
๐ก Writing Morse Code Programs
When writing your .mc files, remember:
- Separate letters with single spaces:
.... . .-.. .-.. ---=hello - Separate words with triple spaces:
.... . .-.. .-.. --- .-- --- .-. .-.. -..=hello world - Each line becomes one Python line: Line breaks in
.mcbecome line breaks in Python
๐ Example Programs
Simple Print
Python:
print("Hello, World!")
Morse:
.--. .-. .. -. - -.--. .----. .... . .-.. .-.. --- --..-- .-- --- .-. .-.. -.. .----. -.--.-
Variables and Math
Python:
var x = 10
var y = 5
var result = x + y
print result
Morse:
...- .- .-. -..- -...- .---- -----
...- .- .-. -.-- -...- .....
...- .- .-. .-. . ... ..- .-.. - -...- -..- .-.-. -.--
.--. .-. .. -. - .-. . ... ..- .-.. -
Output:
15
For Loops
Python:
for i in range(5):
print i
Morse:
..-. --- .-. .. .. -. .-. .- -. --. . -.--. ..... -.--.- --- --..--
.--. .-. .. -. - ..
Output:
0
1
2
3
4
While Loops
Python:
var count = 0
while count < 3:
print count
var count = count + 1
Morse:
...- .- .-. -.-. --- ..- -. - -...- -----
.-- .... .. .-.. . -.-. --- ..- -. - -....- ...-- --- --..--
.--. .-. .. -. - -.-. --- ..- -. -
...- .- .-. -.-. --- ..- -. - -...- -.-. --- ..- -. - .-.-. .----
Output:
0
1
2
Functions
Python:
func add(a b):
return a + b
var result = add(3 5)
print result
Morse:
..-. ..- -. -.-. .- -.. -.. -.--. .- -... -.--.- --- --..--
.-. . - ..- .-. -. .- .-.-. -...
...- .- .-. .-. . ... ..- .-.. - -...- .- -.. -.. -.--. ...-- ..... -.--.-
.--. .-. .. -. - .-. . ... ..- .-.. -
Output:
8
๐ Pro Tip: Morse Lang supports variables (
var), math operations, print statements, for loops (for i in range(n):), while loops (while condition:), and functions (func name(args):withreturn). Use indentation (spaces) to define code blocks, just like Python!
Web Frontend (Text โ Morse Translator)
This repository also includes a small Flask web app that lets you convert between text and Morse interactively.
Run the web UI (macOS & Windows)
From the project root:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python app.py
Then open http://localhost:5000 in your browser.
The page lets you:
- Type text โ get Morse code
- Paste Morse โ get decoded text
The web app uses the same MORSE_MAP as the CLI, so behavior is consistent.
Development
If you want to hack on Morse Lang itself:
- Clone and install in editable mode:
git clone https://github.com/sharky-3/morse-programming-language.git
cd morse-programming-language
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install --upgrade pip
python -m pip install -e .
python -m pip install -r requirements.txt
- Run tests:
python -m pip install pytest
pytest
- Play with the internals:
morse_lang/lexer.pyโ Morse โ text decodingmorse_lang/morse_map.pyโ core Morse symbol mapmorse_lang/cli.pyโmorsecommand-line entrypoint
You can now iterate on the language, extend the Morse mapping, or experiment with new features.
Enjoy writing code in dots and dashes!
If you build something cool with Morse Lang, feel free to share it or open an issue/PR on the GitHub repo.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file morse_lang-1.1.0.tar.gz.
File metadata
- Download URL: morse_lang-1.1.0.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b9519031ea87e449df77a9100871e975caafdb605e84958785f1a93027f76d6
|
|
| MD5 |
6f1d73ad55245cca42b259793bf8033d
|
|
| BLAKE2b-256 |
015fef55cf1f9acaddbbf1d405221b2b873dd96369b4fbb2e03e6886554f4e8d
|
File details
Details for the file morse_lang-1.1.0-py3-none-any.whl.
File metadata
- Download URL: morse_lang-1.1.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d65808fee35c1338b23c448d05fd4969614257257e317c26167b6b0fd274d40
|
|
| MD5 |
e1dd523cedbc6702569efe549bb0b1bb
|
|
| BLAKE2b-256 |
bb113ed4434a9e446a134a23d78b1622106616dd80f2865706e45e70f2004bc2
|