From caa2a0df82e88af8e84d0436e36ba8745b8dd0c9 Mon Sep 17 00:00:00 2001 From: PartMan <47669599+PartMan7@users.noreply.github.com> Date: Sun, 9 Apr 2023 14:14:52 +0530 Subject: [PATCH 1/2] Add comments to the code --- static/js/lang.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/static/js/lang.js b/static/js/lang.js index 50fe098..fc57c8e 100644 --- a/static/js/lang.js +++ b/static/js/lang.js @@ -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() { From f6ccbebf83617e6bd243a70cd40b33a2ad020e17 Mon Sep 17 00:00:00 2001 From: PartMan Date: Sun, 9 Apr 2023 14:30:33 +0530 Subject: [PATCH 2/2] Add docs for comments --- README.md | 10 ++++++++-- static/js/main.js | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d8cecb..af259d5 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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. diff --git a/static/js/main.js b/static/js/main.js index e14b8a6..8cc38ee 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -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 @@ -315,6 +317,10 @@ class App extends Component { SHOCKING DEVELOPMENT return from a function +
  • + TAKE NOTE THAT...IN SOME SITUATIONS + comments +
  • PLEASE LIKE AND SUBSCRIBE end of program