Bedtime
Bedtime is a language by User:PixelatedStarfish where source files are bedtime stories. It is influenced by languages that use English words to describe a program, like Beatnik, Shakespeare, A.R.T.I.C.L.E. and Rockstar. Bedtime is distinguished from languages of a similar premise by a simple rule: If the source code is too repetitive, the bedtime story is boring and objectionable. The interpreter is a small child, and it will only respond to code sufficiently entertaining. The same word cannot be used more than three times in a sentence, unless it is less than three letters, or the definite article “the”.
Syntax
- A word before a period, comma, exclamation point, or semicolon is an opcode.
- Arguments apply to the next opcode in sequence, not last
- The question mark '?' runs as a period or comma would, but it inverts the parameter value.
- Quotations are string literals to print.
"Hello World!"
This is not true of single quotes. - To print a quotation mark, use two single quotes.
- Comments are in parentheses.
- Hyphens concatenate words, and count as a letter. Not required but nice for readability.
- All tabs and newlines are ignored
- All other characters that are not whitespace or the punctuation above are assumed to be letters.
Values
- A value is stored in a fragment, which is a sequence of words followed by an operation.
Words form values via this scheme:
Hi sweet doggy
is 255
Note that values range between -255 and 255 inclusive; a value with an absolute value larger than 255 is equivalent to itself mod 256. This allows for longer, thematically appropriate sentences to be written into a program for use.
Grammar
Program ::= {Fragment | Printable} Fragment ::= Value, Op Value ::= {Word} Op ::= Word, Terminator Word ::= {Letter} Space Printable ' " ' {Letter | Space} ' " ' Space ::= ' ' Terminator ::= '.' | ';' | '?' | '!' | ',' Letter ::= All printable letters and symbols that are not whitespace or listed above.
Note that a terminator is not included in the length of a word. So dog
has a value equal to that of dog!
.
The Ellipsis
An ellipsis (...
) indicates that a word should have a value of 0. It can be applied to operation codes and arguments for operations. A word that is followed by, or preceded with an ellipsis will be interpreted as 0, regardless of the length of the word. ..?
and ..!
are also valid ellipses, equivalent to ...?
and ...!
respectively.
Operation Codes
see Nondescript
0 - Print top of stack 1 - Print ASCII value 2 - Print top of stack as ASCII 3 - Pop 4 - Push [0 if no argument] 5 - ADD V to value at top of stack [or 1] 6 - Label L 7 - GOTO L (Label) [or start] 8 - GOTO L if 0 [or start] 9 - Input. Singer char is default. Use argument 1 for an integer and 2 for a string. 10 - Duplicate top and push [or push 0 if empty] 11 - Shuffle Stack [unless empty] 12 - Halt All other op codes correspond to a No Operation
Program Examples
Hello World
"Hello World!"
Truth Machine
Charlie's! What could've ended? Forgives, a forget. Love spiritual O! A teacher. Bowser, four ghosties E.
Random Number (1 - 7)
A ball. My ball. The ball. That ball. Shiny ball. Dragon ball! Shenron rise! Immortality, mine...!
Error Messages
(Boring) Your young listener critiques: "This story is boring. Tell me another one!"
(Generic) Your young listener critiques: "I don't get it! What's going on? I want another story! Please?"
(Empty Stack) Your young listener critiques: "Can I have some water? My bottle is empty. Please?"
(EOF) Your young listener critiques: "Aw, the story can't be over yet! More please?"
(Stack Overflow) Your young listener is distracted: "Oops!" Their water bottle overflows on to the floor.
Interpreter
The Interpreter consists of the following:
- A preprocessor
- A Bedtime to Nondescript parser
- A Nondescript interpreter
Preprocessor
The preprocessor prepares code for parsing. It deletes comments, extraneous whitespace, and processes printables for proper parsing. Printables that contain newlines produce erroneous parses, so the newlines are replaced with a ACK (ASCII value 6). The tabs are replaced with ENQ (ASCII value 5). This allows for appropriate parsing.
Parser
The parser converts Bedtime to Nondescript, it can print the resulting source in debug mode.
Nondescript Interpreter
see Nondescript
Interpreter Test Cases
//Test cases for a Bedtime interpreter in Java. Each String is a test. public class Test {
//
//Test with the debugger on. Some results in compilation.
//
//General
String HelloWorld = "\"Hello World!\"";
String TruthMachine = "Charlie's! What could've ended? Forgives, a forget. Love spiritual O! A teacher. Bowser, four ghosties A.";
String RandomNumber = "A ball. My ball. The ball. That ball. Shiny ball. Dragon ball! Shenron rise! Immortality! ...Mine!";
String Comment = "(I AM A COMMENT) Mi(WOW)ne!";
String tabInFrag = "\tFo\tur."; //Should compile to 4 in the debug console, ignoring the tabs.
//
//Print Tests
String FragmentAndPrint = "Not a Fake! \"Print this!\" How mysterious!";
String BadFragment = "This fragment \"is incomplete.\"";
String doubleQuotePrint = "\"''\""; //prints a double quote
String Qprint = "\"?\""; //prints a question mark
String printTabandNewline = "\"\taaa\nssss\"";
String notComment = "\"(NOT A COMMENT)\"";
//
//noOp tests
String noOp = "This is a no op test, prestidigitation.";
String noOp2 = "...";
//
//Zero op tests (Should produce Empty stack error)
String z1 = ".";
String z2 = "!";
String z3 = "..!";
//
//"Negative" zero (should also produce 0 or -0)
String nz1 = "?";
String nz2 = "..?";
//
//Error Tests
String EOF = "\"End of file error should be thrown here.";
String Boring = "Gosh, this is very very very very boring.";
String notBoring = "\"this is very very very boring.\"";
String notBoring2 = "ab ab ab ab the the the the";
String Generic = "Gnric.";
String Overflow = "One Hundred Eighty. Thirty Four. One Hundred Seventy.";
//
//Mod Tests
String _0_255 = "Hi sweet doggy ."; //Debug: 0 255
String _0_0 = "Hi sweet doggie ."; //Debug: 0 0
String n0_255 = "Hi sweet doggy ?"; //Debug: 0 -255
String n0_0 = "Hi sweet doggie ?"; //Debug: 0 0
//
}
Word Generator
This is a program that generates one or more words equivalent to the value given at input. It will generate up to five outputs for each input by selecting them from a dictionary. A non-integer input will close the word generator.