Stu
Stu is an esoteric programming language created by User:PythonshellDebugwindow.
Syntax
Stu is designed to look like the desires of a young boy named Stu. Each command starts with "Stu wants to". Commands are separated by newlines, and there must be at most one command per line. Invalid commands do nothing. Variable names must match the regex [A-Za-z0-9]+
. Strings are sequences of non-newline characters delimited by double quotes.
An Extended Backus-Naur Form (EBNF) description of the language shall now be presented:
program := { innerEmptyLine } , { innerCommandLine | innerEmptyLine } , ( lastCommandLine | lastEmptyLine ) ; innerCommandLine := optionalSpaces , command , optionalSpaces , newline ; lastCommandLine := optionalSpaces , command , optionalSpaces ; innerEmptyLine := optionalSpaces , newline ; lastEmptyLine := optionalSpaces ; command := input | output | quit | jump ; prelude := "Stu wants to " , input := prelude , inputStart , inputStore , ( "!" | ( inputNew , "." ) | ( inputNew , condition ) | condition ) ; inputStart := ( "know something " , [ ", " ] ) | ( "ask you something " , [ ", "] ) ; inputStore := "and put it in " , variable ; inputNew := " unless he already knows it" ; output := prelude , "tell you something:" , outputExpressions , [ condition ] ; outputExpressions := { " " , expression } ; quit := prelude , "leave now" , ( "." | condition ) ; jump := prelude , "go home now" , ( "." | condition ) ; condition := " if " , expression , " and " , expression , " are " , [ "not " ] , "similar." ; newline := "\n" ; optionalSpaces := { space } ; space := " " | "\t" ; expression := string | variable ; string := '"' , { character - '"' } , '"' ; variable := nameCharacter , { nameCharacter } ; nameCharacter := letter | digit ; letter := "A" | ... | "Z" | "a" | ... | "z" ; digit := "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
Commands
I/O
- Input
Stu wants to know something and put it in <var>!
reads a string into the variable <var> from STDIN. The word "know" can be replaced with "ask you", and a comma is optional after "something", so the following two lines:
Stu wants to ask you something and put it in text! Stu wants to know something, and put it in text!
are equivalent.
Optionally, the text " unless he already knows it." can replace the exclamation mark:
Stu wants to know something and put it in text unless he already knows it.
If this check is used, input will only be read if the variable to read into has not yet been read into. A comma is optional after the variable name ("text" in the above program) when using this check. Therefore, the program:
Stu wants to know something and put it in text! Stu wants to know something and put it in text unless he already knows it.
will read just one input.
- Output
Stu wants to tell you something: <expr>
prints out the result of <expr>, which must be a series of variable names and strings separated by exactly one space (ASCII/Unicode 0x20). When printing the values of variables and strings will be concatenated together with no delimiter.
Control flow
- Quitting
The command
Stu wants to leave now.
halts the program immediately; it is not required at the end of programs.
- Jumping
Stu wants to go home now.
jumps back to the start of the program.
- Conditional
The text
if <x> and <y> are similar.
can be appended to any line to evoke a conditional: the line will be executed iff <x> and <y> are the same. <x> and <y> can both be either variable names or strings. The word "not" can be written before "similar" to negate the conditional.
Examples
Hello, World!
Stu wants to tell you something: "Hello, World!"
Infinite loop
Stu wants to go home now.
Cat program
Stu wants to know something and put it in input! Stu wants to tell you something: input Stu wants to go home now if input and "" are not similar.
Truth-machine
Stu wants to know something and put it in input unless he already knows it. Stu wants to tell you something: input Stu wants to go home now if input and "0" are not similar.
Interpreter
- Common Lisp implementation of the Stu programming language.