emoji

Emoji-based programming language inspired by Forth.

๐Ÿ“š Stack-Based Emoji Programming Language

A Forth-inspired stack language where everything is emoji.

Quick Example

๐Ÿ’ญ Hello World
๐Ÿ”คHello, World!๐Ÿ”ค ๐Ÿ˜€

๐Ÿ’ญ Math with keycap digits
5๏ธโƒฃ 3๏ธโƒฃ โž• 2๏ธโƒฃ โœ–๏ธ ๐Ÿ˜€  ๐Ÿ’ญ (5 + 3) * 2 = 16

๐Ÿ’ญ Define square function
๐Ÿ“– ๐ŸŸช ๐Ÿ“š โœ–๏ธ ๐Ÿ“•
7๏ธโƒฃ ๐ŸŸช ๐Ÿ˜€  ๐Ÿ’ญ prints 49

๐Ÿ’ญ Factorial with recursion
๐Ÿ“– โ—
  ๐Ÿ“š 2๏ธโƒฃ โฌ‡๏ธ ๐Ÿ‘
    ๐Ÿ—‘๏ธ 1๏ธโƒฃ
  ๐Ÿ‘Ž
    ๐Ÿ“š 1๏ธโƒฃ โž– โ— โœ–๏ธ
  ๐Ÿ”š
๐Ÿ“•
5๏ธโƒฃ โ— ๐Ÿ˜€  ๐Ÿ’ญ prints 120

Getting Started

Requirements:

  • Crystal - required to run the transpiler
  • Python 3 - optional, only needed if using the Python backend

Quick Start:

  1. Install Crystal.
  2. Run an example: crystal src/cli.cr examples/hello.emoji

Installation & Usage

# Run a program with Crystal backend (default - transpiles, compiles, and executes)
crystal src/cli.cr examples/hello.emoji

# Run a program with Python backend (transpiles and executes)
crystal src/cli.cr examples/hello.emoji --backend python

# Show generated code with Crystal backend
crystal src/cli.cr examples/hello.emoji --show-code

# Use Python backend and show generated code
crystal src/cli.cr examples/hello.emoji --backend python --show-code

# Save generated code to file
crystal src/cli.cr examples/hello.emoji -o output.cr
crystal src/cli.cr examples/hello.emoji --backend python -o output.py

Language Reference

Literals

Numbers:

  • ๐Ÿ”ข42 - number literal (for any number)
  • 3๏ธโƒฃ - keycap digit (0๏ธโƒฃ-9๏ธโƒฃ for single digits)

Strings:

  • ๐Ÿ”คtext๐Ÿ”ค - string literal

Booleans:

  • โœ… - true
  • โŒ - false

Basic Stack Operations

  • ๐Ÿ“š - dup (duplicate top)
  • ๐Ÿ—‘๏ธ - drop (remove top)
  • ๐Ÿ”„ - swap (swap top two)
  • ๐Ÿ“‹ - over (copy second to top)

Advanced Stack Operations (Tier 2)

  • ๐Ÿ”ƒ - rot (rotate 3 forward: a b c โ†’ b c a)
  • ๐Ÿ”‚ - -rot (rotate 3 backward: a b c โ†’ c a b)
  • ๐Ÿชž - 2dup (duplicate top 2: a b โ†’ a b a b)
  • ๐Ÿšฎ - 2drop (drop top 2)
  • ๐ŸŽฏ - pick (copy nth item)

Arithmetic

  • โž• - add
  • โž– - subtract
  • โœ–๏ธ - multiply
  • โž— - divide
  • ๐Ÿ”€ - modulo

Comparison

  • ๐ŸŸฐ - equal
  • โฌ†๏ธ - greater than
  • โฌ‡๏ธ - less than

Boolean Operations

  • โšก - or (logical OR)
  • ๐Ÿ”— - and (logical AND)
  • ๐Ÿšซ - not (logical NOT)

I/O

  • ๐Ÿ˜€ - print (with newline)
  • ๐Ÿ’ฌ - emit (without newline)
  • ๐ŸŽค - input (read from stdin)

Control Flow

  • ๐Ÿ” - loop (repeat while true on stack)
  • ๐Ÿ‘ - starts a conditional (then branch first)
  • ๐Ÿ‘Ž - starts a conditional (else branch first)
  • ๐Ÿ”š - ends a conditional

Conditional Syntax:

๐Ÿ‘ <then> ๐Ÿ”š                 ๐Ÿ’ญ If true, execute then
๐Ÿ‘ <then> ๐Ÿ‘Ž <else> ๐Ÿ”š       ๐Ÿ’ญ Then/else (traditional order)
๐Ÿ‘Ž <else> ๐Ÿ”š                 ๐Ÿ’ญ If false, execute else
๐Ÿ‘Ž <else> ๐Ÿ‘ <then> ๐Ÿ”š       ๐Ÿ’ญ Else/then (reversed source order)

Word Definition

  • ๐Ÿ“– <emoji> - start word definition
  • ๐Ÿ“• - end word definition

Variables

  • ๐Ÿ“ฆ <emoji> - declare variable
  • ๐Ÿ’พ <emoji> - store to variable (pops value from stack)
  • ๐Ÿ“ค <emoji> - fetch from variable (pushes value to stack)

Return Stack

  • โฌ…๏ธ - push to return stack
  • โžก๏ธ - pop from return stack
  • ๐Ÿ‘๏ธ - peek return stack (non-destructive)

Comments

  • ๐Ÿ’ญ - comment to end of line

How It Works

.emoji source โ†’ Tokenizer โ†’ Parser โ†’ AST โ†’ Backend โ†’ Compile โ†’ Run
  1. Tokenizer - Converts emoji to tokens
  2. Parser - Builds Abstract Syntax Tree
  3. Backend - Code generation (pluggable: Crystal, Python, etc.)
  4. Transpiler - Ties it together
  5. Execution - Compiles and runs generated code

Backend Implementations

Crystal Backend:

  • Generates Crystal code
  • Uses module with class variables for state
  • Macros for stack operations
  • Fast execution (compiled)

Python Backend:

  • Generates Python 3 code
  • Uses module-level variables for state
  • Helper functions for stack operations
  • Emoji names are hex-encoded for Python compatibility
  • Interpreted execution

Pluggable Architecture

  • Easy to add new backends (Rust, JavaScript, etc.)
  • Shared AST representation
  • Backend-agnostic tokenizer and parser

Stack-Based Execution:

5๏ธโƒฃ 3๏ธโƒฃ โž•
โ†’ push 5, push 3, add
โ†’ stack: [8]

Word Definitions:

๐Ÿ“– ๐ŸŸช ๐Ÿ“š โœ–๏ธ ๐Ÿ“•  ๐Ÿ’ญ Define ๐ŸŸช (square) as: dup multiply
5๏ธโƒฃ ๐ŸŸช            ๐Ÿ’ญ Call it: push 5, call square
โ†’ stack: [25]

Recursion:

๐Ÿ“– โ—
  ๐Ÿ“š 2๏ธโƒฃ โฌ‡๏ธ ๐Ÿ‘
    ๐Ÿ—‘๏ธ 1๏ธโƒฃ
  ๐Ÿ‘Ž
    ๐Ÿ“š 1๏ธโƒฃ โž– โ— โœ–๏ธ
  ๐Ÿ”š
๐Ÿ“•

Testing

  • Unit tests: crystal spec
  • Integration tests: crystal src/test_runner.cr tests/; single file: crystal src/test_runner.cr tests/boolean_ops.test.emoji

Design Philosophy

Inspired by Forth and Factor, this is a concatenative language where:

  1. Everything is a word (function)
  2. Words consume and produce stack values
  3. Composition is concatenation (๐ŸŸช ๐ŸŸช = square twice)
  4. Minimal primitives, maximum composition
  5. Optional variables (data flow can use stack or variables)

Credits

Inspired by:

  • Emojicode - The original emoji programming language
  • Forth - Stack-based concatenative language
  • Factor - Modern concatenative language
  • Crystal - The implementation language

License

This work is dedicated to the public domain by Todd Sundsted worldwide using the CC0 1.0 Universal Public Domain Dedication.

Repository

emoji

Owner
Statistic
  • 0
  • 0
  • 0
  • 0
  • 0
  • 2 months ago
  • December 8, 2025
License

Other

Links
Synced at

Wed, 28 Jan 2026 00:50:41 GMT

Languages