Skip to content

leowhitehead/x

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 

x

X: A programming language that only accepts identifiers that look like the letter 'x'.

xkcd 2309

Based on the idea from xkcd 2309.

About

In the X language, only characters that closely resemble the letter 'x' can be used to define variables or functions. Any attempt to use a character that does not closely enough resemble an 'x' will result in a syntax error.

X currently provides the following 40 possible identifiers which may be used to define variables or functions:

ฮง, ฯ‡, าณ, ๐”ต, ๐–, ๐”, ๐•ฉ, ๐šก, ไน‚, ๏พ’, โœ•, โœ–, โœ—, โœ˜, ๐Ÿ—™, ๐Ÿ—ด, แšท, ๐Ÿ…‡, ๐—‘, ๐–ท, ๐ฑ, ๐—, ๐•, ๐˜…, ๐—ซ, ๐‘ฅ, ๐‘‹, ๐š‡, ๐’™, ๐‘ฟ, ๐Ÿ†‡, ๐”›, ๐˜น, ๐˜Ÿ, ๐“, ๐’ณ, ๐–ƒ, ๐™ญ, ๐™“, ๐“ง

Additionally, X has four further identifiers which have a reserved or built-in use:

  • x, which is the entry point of the program. All X programs should have at least one func x(){}.
  • X, which is used to print to stdout.
  • ั…, which takes integer inputs from stdin.
  • ำฝ, which takes string inputs from stdin.

The X compiler only supports ASCII characters in the source code, with the only exception being that identifiers may be a Unicode character, as long as it closely resembles the appearance of the letter 'x'. Any attempts to use a non-ASCII character that does not resemble an 'x' will result in a compilation error.

Usage

X programs can be compiled with the following command:

./x file.x [-h] [-s] [-o outfile=x.out] [-c compiler=clang]

X source code is first transcompiled into C, before being compiled to an executable.

  • -h displays these options and exits.
  • -o specifies the output file, which is x.out by default.
  • -s outputs the file as C source code and does not compile to an executable.
  • -c specifies the compiler which is used to compile the C source code into an executable. The compiler is clang by default, but this can be changed to another compiler such as gcc.

Installing

The X compiler can be downloaded and built into a standalone binary using Pyinstaller as follows:

$ git clone https://github.com/lduck11007/x.git
$ cd x/src
$ pyinstaller --onefile main.py -n x
$ cd dist
$ mv x ../..
$ cd ..
$ rm -rf dist build x.spec __pycache__ 

Examples

helloworld.x

func x(){
    X("hello world!\n",);
}

greet.x

func x(){
    let ฮง = "Hello, " + ำฝ("What is your name? ",);
    X(ฮง,);
    X("\n",);
}

randomNumber.x

func แšท(){
    return 4;   /* chosen by fair dice roll. */
}               /* guaranteed to be random */

func x(){
    X(แšท(),);
    X("\n",);
}

fibonacci.x

func ๐•ฉ(โœ—){
    if(โœ—<=1)
        return โœ—;
    return ๐•ฉ(โœ—-1,)+๐•ฉ(โœ—-2,);
}
func x(){
    let ๐Ÿ—™ = ั…("Enter a number: ",);
    X(๐•ฉ(๐Ÿ—™,),);
    X("\n",);
}

fizzbuzz.x

func x(){
    let ฮง = 1;
    while(ฮง<101){
        if(ฮง%15==0)
            X("FizzBuzz",);
        if((ฮง%3==0)&&(ฮง%5!=0))
            X("Fizz",);
        if((ฮง%3!=0)&&(ฮง%5==0))
            X("Buzz",);
        if((ฮง%3!=0)&&(ฮง%5!=0))
            X(ฮง,);
        X("\n",);
        ฮง = ฮง+1;
    }
}

FAQ

Why?

Good question.

About

X: A programming language that only accepts identifiers that look like the letter 'x'. Inspired by https://xkcd.com/2309/

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages