Giter Site home page Giter Site logo

nickybu / tabloid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thesephist/tabloid

0.0 0.0 0.0 133 KB

A minimal programming language inspired by clickbait headlines

Home Page: https://tabloid.vercel.app

License: MIT License

JavaScript 86.68% CSS 9.41% HTML 3.91%

tabloid's Introduction

The Tabloid Programming Language ๐Ÿ’ฃ

Tabloid is a minimal but Turing complete programming language inspired, nay, supercharged by clickbait headlines that rule the Internet today. You can try Tabloid on the Tabloid website. Thanks to @otherjoel, there's also a Racket implementation of Tabloid that's very nearly compatible. A small library of math and other helper functions is also available from @MarcelloTheArcane's tabloid-samples project.

Tabloid website screenshot

Tabloid is quite small -- it only supports number, string, and boolean values at the moment, and have semantics that match JavaScript since JavaScript is used to implement the language backend. But it's good enough for a joke language made in six hours, so I'm rollin' with it.

Language overview

You can find the complete list of special Tabloid keywords on the Tabloid website.

Tabloid has an expression-based grammar, and lacks any distinction between expressions and statements. If there isn't an explicit return from a function, the last expression's value will be returned.

Here are some primitive values in Tabloid: numbers, strings, booleans

100
3.141592
.718
'Hello, World!'
TOTALLY RIGHT
COMPLETELY WRONG

The last two -- TOTALLY RIGHT and COMPLETELY WRONG -- are how we write true and false in Tabloid.

Tabloid supports binary infix operators for arithmetic and logic.

(3 TIMES 5) PLUS (20 DIVIDED BY 7)
(x IS ACTUALLY 3.1415) OR COMPLETELY WRONG

IS ACTUALLY is a way to test equality, like == in most other languages. We can also make comparisons with X BEATS Y (x > y) and X SMALLER THAN Y (x < y).

We can print the result of any expression with YOU WON'T WANT TO MISS. You won't want to miss what you're printing, and now you never will!

YOU WON'T WANT TO MISS 'Hello, World!'

Conversely, we can take (string) input from the user with LATEST NEWS ON. This creates a prompt to ask the user of your incredible program about the latest news.

EXPERTS CLAIM age TO BE
    LATEST NEWS ON 'What is your age?'

We define functions with DISCOVER HOW TO functionName WITH arguments, like, this. We can call them with the OF keyword.

DISCOVER HOW TO speak WITH message
RUMOR HAS IT
    YOU WON'T WANT TO MISS message
END OF STORY

speak OF 'Hello!'

Lastly, Tabloid has conditional expressions in the form of an if-else, which is written like...

WHAT IF condition
    doIfThing
LIES!
    doElseThing

We can have multi-line bodies in the doIfThing and doElseThing sections by creating a new scope, delimited by RUMOR HAS IT and END OF STORY. LIES! is optional.

WHAT IF condition RUMOR HAS IT
    do
    many
    things
END OF STORY

In Tabloid, newlines are not significant. If you want, you can squeeze your entire damn program in a single line of source code! How wonderful! I see exactly zero ways that could possibly go wrong.

The entire interpreter is contained in a single file, static/js/lang.js, and pretty straightforward. Due to the, ahem, unusual syntax of Tabloid, there are four layers, which includes a double-pass tokenizer that first produces a stream of word tokens (a string literal is a single word, punctuations are treated separately), and then a second tokenizer that tokenizes multi-word keywords like DISCOVER HOW TO (which is 3 words).

The interpreter uses a tree-walk evaluator on the syntax tree to execute a program.

How to use

Please don't.

Limitations

Tabloid's syntax has some (soft) limitations for now, because I had ~8 hours to finish it. Here are some of them:

  • The parser doesn't know about operator precedence. To chain infix operators together like 3 PLUS 2 TIMES 10, use parentheses, like 3 PLUS (2 TIMES 10).
  • There isn't a built-in looping construct, like a while loop. This could be viewed as a feature, but is a little annoying. I left it out because it was less trivial than the other features to implement.
  • There isn't very good error reporting. If there is an error during parsing or at runtime, the interpreter will currently report an error and what went wrong, but won't tell you where it messed up and will reveal interpreter implementation details.

Tabloid also doesn't have comments, because... I honestly forgot about them when I made this and only remembered like 7 hours in, and I got lazy. If this bothers you for some insane reason, feel free to make a pull request... I guess.

tabloid's People

Contributors

thesephist avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.