Skip to main content

A programming language that only uses emojis as syntax.

Project description

๐Ÿ spamoji

A programming language that only uses emojis as syntax and encourages writing spaghetti code.

๐ŸŽ“ Example

๐Ÿ—’๏ธ A function to calculate factorial
โš™๏ธ ๐Ÿ”ขโ•๐Ÿซธ๐Ÿ”ฐ๐Ÿซท
    ๐Ÿ‘‹ ๐Ÿ ๐Ÿซด 1
    ๐Ÿ”ƒ ๐Ÿ”ฐ ๐Ÿคœ 1
        ๐Ÿ ๐Ÿซด ๐Ÿ โœ–๏ธ ๐Ÿ”ฐ
        ๐Ÿ”ฐ ๐Ÿซด ๐Ÿ”ฐ โž– 1
    โ†ฉ๏ธ ๐Ÿ

๐Ÿ’ญ๐Ÿซธ๐Ÿ”คEnter a number to calculate the factorial: ๐Ÿ”ค๐Ÿซท
๐Ÿ‘‹ ๐Ÿ˜€ ๐Ÿซด ๐Ÿ”ข๐ŸซธโŒจ๏ธโ—๐Ÿซท
๐Ÿค” ๐Ÿ˜€ ๐ŸŸฐ โš ๏ธ
๐Ÿ‘
    ๐Ÿ’ฌ๐Ÿซธ๐Ÿ”คInvalid input.๐Ÿ”ค๐Ÿซท
๐Ÿ‘Ž
    ๐Ÿ’ฌ๐Ÿซธ๐Ÿ”คThe factorial of ๐Ÿ”ค โž• ๐Ÿ˜€ โž• ๐Ÿ”ค is ๐Ÿ”ค โž• ๐Ÿ”ขโ•๐Ÿซธ๐Ÿ˜€๐Ÿซท๐Ÿซท

๐Ÿ’ญ What's this all about?

This language is a learning project. Since it lacks many features of a typical programming language, it is not recommended for production use. If this experiment is successful, I might move on and begin working on Esore, a more serious language I've been designing in the past 2 years.

๐Ÿ“ฆ Installation

To install the spamoji interpreter, you will need to have Python 3.10 or higher installed on your machine. You can download Python from the official website.

Once you have Python installed, you can install the spamoji interpreter using pip:

pip install spamoji

๐Ÿš€ Usage

To run a spamoji program, you will need to use the spamoji interpreter.

You can provide a spamoji file (with the .๐Ÿ extension) as input to run it. For example:

spamoji my_program.๐Ÿ

If no file is supplied, the interactive REPL will start, which allows to enter and evaluate expressions directly.

If the above command doesn't work, you can also run the interpreter using Python's -m flag:

python -m spamoji my_program.๐Ÿ

๐Ÿ“ Syntax

[!IMPORTANT] The emojis used in the syntax were entered on a Windows machine. While they should work on other platforms, some emojis might not render correctly or might be replaced with different emojis. If you encounter any issues, please try copying and pasting the emojis from this documentation into your code.

โ— Statements

Each line of code starts with an emoji that indicates the type of statement. Each statement is followed by the relevant information, separated by spaces. Statements include:

  • ๐Ÿ—’๏ธ Comment: Text in this line will be ignored
  • ๐Ÿ‘‹ Variable declaration: Followed by the variable assignment
  • ๐Ÿค” If statement: Followed by the condition
    • ๐Ÿ‘ If true block
    • ๐Ÿ‘Ž Else block
  • ๐Ÿ”ƒ Loop: Followed by the loop variable and condition
    • โ›” Break statement: Used to exit the loop
    • โคด๏ธ Continue statement: Used to skip to the next iteration of the loop
  • โš™๏ธ Function definition: Followed by the function name and parameters
    • โ†ฉ๏ธ Return statement: Followed by the value to return
  • ๐Ÿ“œ Class definition: Followed by the class name and members
  • ๐Ÿงฉ Import statement: Followed by a file name, it loads that file as a module

Statements starting with any other character are going to be considered as expressions and be evaluated directly.

Some statements can be nested, such as if statements and loops. Indentation is used to indicate the scope of these statements. Indented blocks are considered part of the previous statement until the indentation level decreases.

๐Ÿง  Expressions

An expression is a piece of code that produces a value and/or executes actions. Function calls, variables, and operations are all expressions and can be used on their own or inside of other expressions or statements.

๐Ÿซธ and ๐Ÿซท can be used to group expressions and control the order of evaluation.

๐Ÿ”ฃ Operators

The language supports basic operators for logical and arithmetic operations. These can be used between two values to perform calculations.

  • โž•: Addition
  • โž–: Subtraction or negation
  • โœ–๏ธ: Multiplication
  • โž—: Division
  • ๐ŸŸฐ: Equal
  • ๐Ÿ†š: Not equal
  • ๐Ÿคœ: Greater than
  • ๐Ÿค›: Less than
  • ๐Ÿคœ๐ŸŸฐ: Greater than or equal
  • ๐Ÿค›๐ŸŸฐ: Less than or equal
  • ๐Ÿค: Logical AND
  • ๐Ÿคฒ: Logical OR
  • ๐Ÿ™…: Logical NOT

Operators can also be combined with variable assignment to perform an operation and assign the result to the variable in one step. Supported compound forms are ๐Ÿซดโž•, ๐Ÿซดโž–, ๐Ÿซดโœ–๏ธ, and ๐Ÿซดโž—:

๐Ÿ‘‹ x ๐Ÿซด 5
x ๐Ÿซดโž• 3  ๐Ÿ—’๏ธ -> x is 8 now

๐Ÿ”ค Strings

Strings are sequences of characters enclosed in ๐Ÿ”ค on each side. They can contain any characters, including emojis. Strings can be used in variable assignments, printed to the console, and concatenated using the โž• operator.

To use the ๐Ÿ”ค character in a string, write ๐Ÿšง๐Ÿ”ค instead. To use the ๐Ÿšง character, write ๐Ÿšง๐Ÿšง instead.

๐Ÿค” Conditions

The ๐Ÿค” statement allows to run different code depending on a certain condition:

๐Ÿค” condition
๐Ÿ‘
    this line runs if condition is true
๐Ÿ‘Ž
    this line runs if condition is false

Both the ๐Ÿ‘ and ๐Ÿ‘Ž branches are optional. If a branch has only 1 statement, it can be written in the same line as the ๐Ÿ‘/๐Ÿ‘Ž. Conditions can also be nested inside of other conditions:

๐Ÿค” condition 1
๐Ÿ‘
    this line runs if condition 1 is true
๐Ÿ‘Ž ๐Ÿค” condition 2
    ๐Ÿ‘ this line runs if condition 1 is false and condition 2 is true

Conditions can also be used inside of other expressions:

๐Ÿซธ๐Ÿค” condition ๐Ÿ‘ a ๐Ÿ‘Ž b ๐Ÿซท

Here, if condition is true, a will be returned, otherwise b. It is important to note that inline conditions like this require both a ๐Ÿ‘ and a ๐Ÿ‘Ž, otherwise an error will be raised.

๐Ÿ”ƒ Loops

The ๐Ÿ”ƒ statement can be used to run code repeatedly while a certain condition is true.

๐Ÿ”ƒ condition
    this code runs while condition is true

Additionally, the โ›” and โคด๏ธ statements can be used to control the loop execution. โ›” stops the loop immediately, regardless of the condition. โคด๏ธ jumps back to the beginning of the loop.

๐Ÿ‘‹ Variables

Variables are declared using the ๐Ÿ‘‹ emoji, followed by the variable assignment expression. An assignment expression starts with the variable name, followed by ๐Ÿซด and a value. For example:

๐Ÿ‘‹ x ๐Ÿซด 1

The declaration and assignment can also be on separate lines. Any unassigned variables will start with value ๐Ÿซฅ.

Variable names can be any combination of letters, numbers, and emojis, but must start with a letter or emoji and cannot contain statement characters.

Variables declared inside of a block are only accessible inside of that block and any nested blocks.

โš™๏ธ Functions

Functions are defined using the โš™๏ธ emoji, followed by the function name and parameters. The function body is indented and can contain any valid statements. The function can return a value using the โ†ฉ๏ธ emoji.

Functions can be called by using their name followed by the arguments, separated by ๐Ÿ”ธ, between ๐Ÿซธ and ๐Ÿซท. Functions with no arguments can also be called with the โ— emoji.

Here's an example of a function definition and call:

โš™๏ธ greetAndAsk ๐ŸซธfirstName ๐Ÿ”ธ lastName๐Ÿซท
    ๐Ÿ’ฌ๐Ÿซธ๐Ÿ”คHello, ๐Ÿ”ค โž• firstName โž• ๐Ÿ”ค ๐Ÿ”ค โž• lastName โž• ๐Ÿ”ค ! Please enter a number...๐Ÿ”ค๐Ÿซท
    โ†ฉ๏ธ โŒจ๏ธโ—  ๐Ÿ—’๏ธ Return the user input

๐Ÿ‘‹ x ๐Ÿซด greetAndAsk๐Ÿซธ๐Ÿ”คJohn๐Ÿ”ค๐Ÿ”ธ๐Ÿ”คDoe๐Ÿ”ค๐Ÿซท
๐Ÿ’ฌ๐Ÿซธ๐Ÿ”คYou entered: ๐Ÿ”ค โž• x๐Ÿซท

In some cases, functions can be called without parentheses:

๐Ÿ’ฌ ๐Ÿ”คHello!๐Ÿ”ค
๐Ÿ’ฌ 1 โž• 2

๐Ÿ“œ Classes

Classes are defined using the ๐Ÿ“œ emoji. The class body is indented and can contain any valid statements. Any function statements directly in the class body will be added to the class as methods.

Class instances are created by calling the class name, like a function. When an instance is created, the special method โœจ will be called.

Inside of methods, the ๐Ÿค– emoji can be used to refer to the current instance.

๐Ÿ“œ MyClass
    โš™๏ธ โœจ๐Ÿซธname๐Ÿซท
        ๐Ÿค–๐Ÿ‘‰name ๐Ÿซด name

    โš™๏ธ greetโ—
        ๐Ÿ’ฌ๐Ÿซธ๐Ÿ”คHello, I am ๐Ÿ”ค โž• ๐Ÿค–๐Ÿ‘‰name โž• ๐Ÿ”ค!๐Ÿ”ค๐Ÿซท

Classes can inherit methods from other classes (superclasses). Superclass names can be written between ๐Ÿซธ and ๐Ÿซท, separated by ๐Ÿ”ธ, after the class name in the definition. The first superclass can be accessed with the ๐Ÿ‘† emoji in methods.

๐Ÿ“œ MyClass ๐Ÿซธsuperclass1๐Ÿ”ธsuperclass2๐Ÿซท
    โš™๏ธ superclassNameโ—
        โ†ฉ๏ธ ๐Ÿ‘†๐Ÿ‘‰name

๐Ÿงฉ Imports

The ๐Ÿงฉ emoji can be used to include code from another file in the current code:

๐Ÿงฉ robots.๐Ÿ
๐Ÿ‘‹ bot ๐Ÿซด robots๐Ÿ‘‰Robot๐Ÿซธname๐Ÿซท

๐ŸŽ Built-ins

The language includes several built-in functions and values for common operations.

๐Ÿ’ฌ Built-in functions

  • ๐Ÿ’ฌ๐Ÿซธstring๐Ÿซท: Print string to a new line in the console
  • ๐Ÿ’ญ๐Ÿซธstring๐Ÿซท: Print string to the console without creating a new line
  • โŒจ๏ธโ—: Get user input from the console
  • โณ๐Ÿซธtime๐Ÿซท: Wait for a specified number of seconds
  • ๐Ÿ”ข๐Ÿซธvalue๐Ÿซท: Convert value to a number, return โš ๏ธ if the conversion fails
  • ๐ŸŽฒ๐Ÿซธmin๐Ÿ”ธmax๐Ÿซท: Get a random integer from min to max
  • ๐Ÿ•ฐ๏ธโ—: Get time since epoch in seconds
  • ๐Ÿ›‘โ—: Stop the program

โœ… Built-in values

  • โœ…: true
  • โŒ: false
  • ๐Ÿซฅ: unassigned/null/no value
  • โš ๏ธ: error/invalid value

๐Ÿ Python interoperability

โžก๏ธ Inline evaluation

The ๐Ÿ function allows to directly evaluate Python expressions within Spamoji code. The results of these evaluations can be stored in variables and used in Spamoji. For example, the following code prints the modulo of x and y:

๐Ÿ‘‹ x ๐Ÿซด 10
๐Ÿ‘‹ y ๐Ÿซด 2
๐Ÿ‘‹ z ๐Ÿซด ๐Ÿ๐Ÿซธ๐Ÿ”ค๐Ÿ”ค โž• x โž• ๐Ÿ”ค%๐Ÿ”ค โž• y โž• ๐Ÿ”ค๐Ÿซท
๐Ÿ’ฌ๐Ÿซธz๐Ÿซท

๐Ÿ“ค Exporting functions from Python

To make a Python function available in Spamoji, you can use the spamoji_function decorator. This decorator takes an emoji as an argument, which will be used to call the function in Spamoji code. For example, the following Python function can be called in Spamoji using the ๐Ÿ˜Ž emoji:

import math
from spamoji import spamoji_function

@spamoji_function("๐ŸŒŠ")
def sine(x):
    return math.sin(x)

๐Ÿ“ฅ Importing Python functions

The ๐Ÿ๐Ÿงฉ function can be used to import functions from Python files into a Spamoji program. For example:

๐Ÿ๐Ÿงฉ๐Ÿซธ๐Ÿ”คexamples/sine.py๐Ÿ”ค๐Ÿซท
๐Ÿ’ฌ๐Ÿซธ๐Ÿ”คThe sine of 3 is: ๐Ÿ”ค โž• ๐ŸŒŠ๐Ÿซธ3๐Ÿซท๐Ÿซท

๐Ÿซ‚ Credits

Thanks to Robert Nystrom for his book "Crafting Interpreters" which inspired the design of this language and provided guidance on how to implement it.

Also thanks to Hack Club for providing a supportive community and motivating me to work on this project.

This documentation was entirely written by hand. AI tools were used for assistance while writing the interpreter.

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

spamoji-0.4.0.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

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

spamoji-0.4.0-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file spamoji-0.4.0.tar.gz.

File metadata

  • Download URL: spamoji-0.4.0.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spamoji-0.4.0.tar.gz
Algorithm Hash digest
SHA256 f3e02fe47fdf49a48bfb92ac965ca405ab37d26265a62aed8a1fd343707ad9b7
MD5 ab2289bc905fe717123410f0447f5c3f
BLAKE2b-256 25117424a5369186d59b5c90e4afb8ae3233a5edefa8a8624a724ca6c3f8bda7

See more details on using hashes here.

Provenance

The following attestation bundles were made for spamoji-0.4.0.tar.gz:

Publisher: publish.yml on iqnite/spamoji

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spamoji-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: spamoji-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 27.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spamoji-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4610e1dc601893a819248b97613daf8ec6f5c23bbfc9285e2d4a53247b8b23f7
MD5 019be7dc038061c65af5ee55ce2c42b6
BLAKE2b-256 e44d0b7f3dea66078ee411985ed05bb313e32ea19e2ea3bdc3d25244bb25ac48

See more details on using hashes here.

Provenance

The following attestation bundles were made for spamoji-0.4.0-py3-none-any.whl:

Publisher: publish.yml on iqnite/spamoji

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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