• Stars
    star
    140
  • Rank 261,473 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An OwO based, stack-oriented programming language

owoScript

owoScript is a stack based, imperative, and Turing complete programming language. owoScript works with a simple and descriptive language that is then compiled to the best bytecode to ever exist on this planet.

Why is owoScript bytecode the best on the planet? Because it's entirely made out of OwO faces! Why have the speed and portability of the JVM when you can have the most adorable code out of almost any language you can write in? And never fear, your owoScript bytecode can easily be turned back into the higher level form at any time.

Additionally, owoScript leaves its syntax and parsing files easily accessible to be inspected and verified by anyone. owoScript's grammar is written in ANTLR4, a parsing tool so out of this world reliable and efficient that you'll wonder why your favorite programming language isn't using it yet.

Examples

See the /examples directory for a hello world, truth machine, and a proof of turing completeness via brainfuck equivalents (does your fancy OOP language prove that it is capable of universal computation? Can you trust it if it doesn't?)

Usage

Stack

owoScript is written in a descriptive language consisting of stack operations, number literals, while loops, and if {} else {} statements. Whitespace is ignored.

owoScript is stack-based, with only integer types. For example, the following literal will push 6 onto the stack:

literal 6;

and the following command will take that number off the stack and print it:

printnum;

operations take their values off the stack in the order they came onto it:

literal 8;
literal 2;
div;

corresponds to 8 / 2, not 2 / 8. However, in addition to the stack, an optional "hashmap", mapping integer keys to integer values, is available through the store and get commands

Arithmetic

Because owoScript is stack-based, arithmetic is performed in postfix notation. This means that writing something like (2+3)*(5/7) is written by taking the operator out of the middle of the expression and adding it on to the end. So 2+3 is written as literal 2; literal 3; add; and 5/7 is written as literal 5; literal 7; div;

The final expression would thus be written as:

literal 2;
literal 3;
add;
literal 5;
literal 7;
div;
mult;
Flow control

Flow control is provided in while loops, functions, and if {} else {} statements

While loops simply repeat the operation inside them until the top of the stack is 0, or falsy. They do not pop values, and instead simply inspect the stack without changing it. While loops are skipped if the top of the stack is 0 when they are made.

Example:

// Truth machine
// When a truthy number is inputted, continue printing it forever
// Otherwise print once and stop
inputnum;
dupe;
printnum;
while {
    dupe;
    printnum;
}

Functions are defined at the top of the file and called like so, and can call other functions. Putting a function anywhere other than at the top of the file will result in very undefined behavior. Functions do not take argument, and simply operate off of the stack.

func square {
    dupe;
    mult;
}
literal 3;
square();

If statements have the syntax

if {
    // statements or nop;
}
else {
    // statements or nop;
}

and pop the top value of the stack. If it is truthy, the first block is executed. Otherwise, the second one is.

Commands

Commands are single word operations (except for number literals and bignumber literals, see below)

Keyword Pops Pushes
literal x None hex value of x, x must be single hex digit (0-9, a-f)
number x None int value of x, x is signed number [*]
add a, b a + b
sub a, b a - b
mult a, b a * b
div a, b a // b (floor division)
mod a, b a % b (modulus)
exp a, b a ^ b (exponent)
print a prints the character with code a
printnum a prints the number literally
printstack None prints entire stack
input None number of character read from stdin
inputnum None decimal number read from stdin
lt a, b 1 if a < b else 0
gt a, b 1 if a > b else 0
eq a, b 1 if a == b else 0
neq a, b 1 if a != b else 0
cmp a, b if a == b: 0, if a > b: 1, if a < b: -1
dupe a a, a (a repeated)
dupedeep a extend stack with last a values on stack
swap a, b b, a (top two values swapped)
push a, b puts a b layers deep in the stack
fetch a pulls the number a deep in the stack to the top
stacklength None length of stack
store a, b stores b in the a slot in the hashmap
get a pushes the value stored in a slot in the hashmap
stop a exits with return code a
fetchdupe a, b same as fetch but doesn't remove number from inside stack
pushdupe a same as push but doesn't remove number from top of stack
nop None no operation, used for code clarity in if/else statements
hexmult a, b a * 16 + b (hexadecimal digit appending)
printhash None prints entire hashmap

* these number literals will be less space efficient in OwO form, so if your number is representable by a single hex digit, that form is recommended.

CLI Usage

The python script owo.py is used for running owoScript bytecode or psuedocode, while the python script owoc.py is the compiler/decompiler used to transform code from pseudocode or bytecode.

The script bfowo.py is used to convert brainfuck programs into owoscript. This conversion is moderately optimized, but is still less efficient than really writing in owoscript would be.

A command line option can be used to specify whether you'd like the transpiler to "wrap" the brainfuck cells (like an 8-bit unsigned int) or whether you'd like python-style ints.

See sierpinski_bf.owop and mandelbrot_bf.owop for examples of these conversions.

Turing completeness

owoScript is provably Turing complete, via a simple reduction to brainfuck


Brainfuck equivalents for OwOScript

Stack is used to hold current pointer while hashmap is used for cells

*/


// > Move pointer right
literal 1;
add;

// < Move pointer left
literal 1;
sub;

// + Increment cell
dupe;
dupe;
get;
literal 1;
add;

/*
Mod 256 wrapping if desired
literal 1;
literal 0;
hexmult;
literal 0;
hexmult;
mod;
*/

store;

// - Decrement cell
dupe;
dupe;
get;
literal 1;
sub;

/*
Mod 256 wrapping if desired
literal 1;
literal 0;
hexmult;
literal 0;
hexmult;
mod;
*/

store;

// . Output char
dupe;
get;
print;

// , Input char
dupe;
input;
store;

// [ ] Begin and end while loop
dupe;
get;
while {
    discard;
    //statements
    dupe;
    get;
}
discard;

Why

"The only reason someone would do something like this if they could, which they can't, would be because they could, which they can't." - Rick Sanchez

I'm sure the question everyone is thinking is "why." Why make a programming language entirely in OwO faces? Why go out of my way to implement a formal grammar with a parser for a meme?

The simple answer, of course, is because I hate myself. The more accurate answer is because I wanted to try out writing a basic interpreter and grammar in ANTLR, in preparation for possibly writing an LLVM compiler for a few esoteric programming languages in the near future

Credits

I dedicate this project to all of my friends who answer the phone with "hewwo" so often I want to bash my head in.

Final Note

This project is mostly a joke I embarked on as a fun way of learning parsing and the basics of imperative language design. Any ridiculous statements inside this project are purely satire.

More Repositories

1

cdn.dlcordapp.com

A project to mimic the cdn.discordapp.com domain but serve rickrolls.
CSS
74
star
2

TXQR-Android

Based off of the principles in https://github.com/divan/txqr
Java
34
star
3

py-rolldice

A python module for parsing string representation of D&D dice and rolling said dice.
Python
29
star
4

DivisibilityRegexes

Generate regexes that test arbitrary numbers for divisibility by other numbers,
Python
25
star
5

ASTObfuscate

A Python Obfuscator through AST modification
Python
22
star
6

team-frotress-2

Controls smart sex toys based on kills, Uber, and more in Team Fortress 2
ReScript
15
star
7

malduino-scripts

My malduino scripts.
C++
11
star
8

QRStreamer

A Python program to break up a file into multiple QR codes to be scanned by TXQRAndroid
Python
10
star
9

Obfuscator

Obfuscates python code, compressing it and encoding it.
Python
9
star
10

DFTSerialize

The next-generation of data encoding and serialization.
Python
9
star
11

BeeOS

The Bee Movie operating system. IMO way better than CentOS or RHEL.
Assembly
8
star
12

tf2-configs

My TF2 configs and mods, uploaded here and hopefully updated on a fairly regular basis. Clone into your custom folder to install.
ReScript
3
star
13

FionaBot

A discord bot for RPGs and chess. Rolls dice, tracks initiative, plays chess using a rendered PNG chessboard.
Python
2
star
14

busy

Ralph Loader's "Loader's Number" program with a fun ascii-art twist! See github.com/rcls/busy for the original implementation
C++
2
star
15

WorstFish

Stockfish, but chooses the immediate worst move, along with a few blunder openings!
C++
1
star
16

SSLCompressionCracker

Models a simplified variant of the CRIME compression oracle attack
Python
1
star
17

BeklemishevWorms

A C implementation of Beklemishev's worms, a term-rewriting system that results in a fast-growing function
C
1
star
18

Particle-WoL

The device portion of a Particle Photon based Wake on Lan implementation. Allows you to wake and ping your WoL enabled devices from anywhere in the world by calling Particle cloud functions.
C++
1
star
19

Mandelbrot

A mandelbrot renderer, golfed to fit into a tweet.
C
1
star
20

py-worstsort

Python
1
star
21

AdventOfCode

Things
Python
1
star
22

noughts-and-crosses

Python bot that plays noughts and crosses perfectly using a MiniMax algorithm.
Python
1
star
23

CompressionComparison

Feed an input file and returns an SVG graphic of the different compression algorithms compared
Python
1
star
24

MandelbrotPython

Golfed, anti-aliased python Mandelbrot set
Python
1
star
25

RandomArt

SSH Random art visualization
Python
1
star
26

RedditConjectureRefuter

I actually don't remember what this was for so the title of the repo is my only info
Python
1
star
27

SniperPOV

Fixes third person rendering in POV demos for TF2 sniper gameplay
C++
1
star