Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ WHAT IF condition RUMOR HAS IT
END OF STORY
```

We insert comments by using `TAKE NOTE THAT ... IN SOME SITUATIONS`. The terminating `IN SOME SITUATIONS` is always required.

```
TAKE NOTE THAT comments can be
typed like so, even across
multiple lines IN SOME SITUATIONS
```

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).
Expand All @@ -94,5 +102,3 @@ Tabloid's syntax has some (soft) limitations for now, because I had ~8 hours to
- 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.
4 changes: 3 additions & 1 deletion static/js/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class Reader {
*/
class Wordifier {
constructor(str) {
this.reader = new Reader(str.trim());
const programStr = str.trim().replace(/\bTAKE NOTE THAT\b(?:.|\n)*?\bIN SOME SITUATIONS\b/gm, '');
// Somewhat-hacky implementation of comments, but it beats deserializing any and all invalid code within the brackets
this.reader = new Reader(programStr);
this.tokens = [];
}
wordify() {
Expand Down
6 changes: 6 additions & 0 deletions static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ RUMOR HAS IT
END OF STORY
END OF STORY

TAKE NOTE THAT Fibonacci numbers are dangerous IN SOME SITUATIONS

EXPERTS CLAIM limit TO BE 10
YOU WON'T WANT TO MISS 'First 10 Fibonacci numbers'
EXPERTS CLAIM nothing TO BE fibonacci OF 0, 1, limit
Expand Down Expand Up @@ -315,6 +317,10 @@ class App extends Component {
<code class="inline fixed block">SHOCKING DEVELOPMENT</code>
return from a function
</li>
<li>
<code class="inline fixed block">TAKE NOTE THAT...IN SOME SITUATIONS</code>
comments
</li>
<li>
<code class="inline fixed block">PLEASE LIKE AND SUBSCRIBE</code>
end of program
Expand Down