Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =MacroBeep Documentation v 1.1.5=
- Thank you for using MacroBeep! A language by @PixelatedStarfish on esolangs.org (Andrew Vella)
- This documentation provides a reference for use, and fully defines an interpreter for the language.
- File Extension .mcbe
- Comments and and Questions can be left on this page:
- https://esolangs.org/wiki/Talk:MacroBeep
- ==Contents==
- Acknowledgements
- Introduction to MacroBeep
- Language Paradigm and Memory
- Instruction Set
- The Preprocessor
- Program Examples
- Error Codes
- Turing Machines and the MacroBeep Tape
- Proof of Turing Completeness
- Grammar in EBNF
- Interpreter Test Cases in Java
- ASCII Table Reference
- Change LogSources
- ==Acknowledgements==
- I certainly would like to thank family, friends, and of course, mademoiselle for their support and care.
- Thank you to the Skidmore College faculty, O'Connell, Dufour, Eckmann, Read, Reiley, and Prasad. I am
- so glad to have my degree in computer science!
- I would also like to thank Bringas, Kravsky, and Lee for their tutelage, patience, and inspiration.
- MacroBeep would not exist without the esolangs wiki and the work of youtuber Truttle1.
- ==Introduction to MacroBeep==
- Macrobeep is designed in response to common problems people face when learning to code in more conventional
- programming languages. The syntax is designed to communicate what the computer is doing in a clear and
- concise manner. For every MacroBeep program, there is an equivalent MacroBeep program that can described
- as a sequence of native instructions in a specific order.
- A MacroBeep programmer does not have to search for the missing punctuation. They do not need to find
- the unmatched parenthesis, or count their braces. They do not need to deal with the particularities of
- data types or the difference between objects, classes, structs, and interfaces.
- This language is not without cons. A programmer needs to manage program memory themselves. Data cannot
- be protected. It is up to the programmer to make sure that something is not overwritten before it should
- be. A MacroBeep programmer should also be familiar with Turing machines and the ASCII table.
- This document covers everything you need to program in MacroBeep.
- ==Language Paradigm and Memory==
- MacroBeep is an assembly style language with an instruction set, such that the programmer can define
- macros in order to describe and implement more complex operations.
- MacroBeep is not a language in the functional language paradigm. There is no part of a MacroBeep program
- that can be considered stateless, and there are no functions in MacroBeep. Instead, a program modifies
- bytes on a tape using a pointer in a manner similar to bf, such that each cell on the tape can store
- a value between 0 and 255 inclusive.
- A program in MacroBeep will always run the main macro before any other macro. This language has a call
- stack, and the main macro is the first item on that call stack.
- ==Instruction Set==
- Each operation can take an identifier or an integer value as an argument.
- A macro cannot be a reserved word or operation name.
- Operations are separated by a newline, and arguments by a space.
- macro (define macro; takes an identifier)
- do (do macro identified in arg, call macro)
- rt (return to macro call an execute next instruction)
- null (set cell to 0)
- str (store value of current cell in next cell; store value of cell in right adjacent cell)
- rand (set cell a random from 0 to arg or 0 to 255)
- add (add to cell; 1 if no arg)
- sub (take from cell; 1 if no arg)
- right (move pointer to the right; by 1 if no arg is given)
- left (move pointer to the left; by 1 if no arg is given)
- head (go to head of tape)
- pos (get position of cell pointer on tape and print it)
- inp (get input; char int or string)
- out (print cell or arg)
- cout (print char on cell or arg as char)
- pr (print any value given as a string with a newline, newline if nothing. Use '[]' to print a space
- and '{}'' to print a tab)
- beep (it goes beep, use an argument to specify frequency in hertz. Default is 1000)
- solar (jump the specified number of instructions if cell is greater than 0)
- lunar (jump the specified number of instructions if cell is 0)
- halt (end program)
- wait (adds a delay of 100ms, or as specified by an argument)
- include (include file at path identified)
- # (comment)
- ==The Preprocessor==
- The Preprocessor formats source code so that it can run appropriately. All leading whitespace before
- an instruction is removed. All blank lines are removed. If needed, all null lines are replaced with empty
- comments. (Comments are ignored at runtime and do not need to be removed.) Additionally, all include
- statements are processed. The contents of each included file are concatinated into a single set of source.
- While 'include' is listed as an instruction in the instruction set, it is not technically correct to
- call them include instructions. Include statements are processed by the preprocessor but not executed.
- This is because they are not executable instructions, but placeholders. Comments are also listed in the
- instruction set, even though they are also not technically executable instructions. This is so a programmer
- can read the set and understand everything that the language can do. It is not particularily wise to
- have some edge case somewhere else. This would not be an effective reference document if a programmer
- could not find information about how to write comments or include files in their programs. Knick-knacks
- are not books, but they sit on the bookshelf anyway, where they can be seen and appreciated. The bookshelf
- does not mind, and the books like the company.
- ==Program Examples==
- It is good practice to indicate the scope of an instruction with tabs or spaces. This can be useful to
- indicate which instructions are part of a macro. Leading white space is not required. New lines are the
- only significant white space characters.
- ===Hello World===
- macro main
- pr Hello[]World
- # Note that the [] is printed as a space
- ===Truth Machine===
- macro main
- pr Type[]a[]0[]or[]1[]into[]the[]truth[]machine.
- inp 1
- solar 3
- pr 0
- halt
- pr 1
- wait
- solar -3
- ===False Machine===
- macro main
- pr Type[]a[]0[]or[]1[]into[]the[]false[]machine.
- inp 1
- lunar 3
- pr 1
- halt
- pr 0
- wait
- lunar -3
- ===Cat===
- macro main
- pr Give[]me[]a[]word[]and[]I[]will[]say[]it[]back!
- inp 2
- head
- cout
- right
- solar -3
- ===C scale===
- macro main
- beep 262
- beep 294
- beep 330
- beep 349
- beep 392
- beep 440
- beep 494
- beep 523
- Note that the main macros do not include a return statement 'rt'. This is becuase the program ends when
- the macro does. A 'rt' can be added to the main macro but it is not required. A macro without an 'rt'
- will continue to execute until it reaches an 'rt' somewhere or gets to an End Of File. So...
- macro main
- beep
- macro sub
- beep 555
- rt
- ...will execute. 'do sub' will execute the macro 'sub'. 'do main' will execute from the top to the 'rt'.
- However, any statements after the 'rt' would not execute, since macro 'main' has finished.
- ==Error Codes==
- Error (0)
- The Generic Error Message, for errors not described below.
- Undefined Instruction (1)
- Thrown when the interpreter encounters an instruction that is not defined in the instruction set.
- File Not Found (2)
- Either the file does not exist, or it is in the wrong directory.
- Undefined Macro (3)
- The macro called by "do" has no matching definition, or "macro" instruction
- Missing Main Macro (4)
- "macro main" is missing, the program cannot start.
- Stack Overflow (5)
- This error is most commonly caused by an infinite recursion. Too many macro calls on the call stack.
- Not a Cell Error (6)
- Occurs when a program tries to modify a cell that does not exist, such as cell -1 or cell infinity.
- Include Statement in Macro (7)
- An include statement cannot be written into a macro definition.
- Preproccesor Error (8)
- A preproccesor error that is not caught by any other error code. Check include statements carefully.
- Duplicate Macro Definition (9)
- A macro is defined more than once in the program. Calls to macro ambiguous.
- Argument Error. Integer Expected (10)
- An instruction that only takes an integer argument was not given an integer argument.
- Bad Argument (11)
- This is the error thrown when the interpreter reads statements that are syntactically correct, but incomputable
- in this language, such as "wait -100". Esoteric models of time notwithstanding, instructions that require
- negative time to compute would throw this error.
- Astrological Error (12)
- This error occurs when the next instruction to execute is located outside source entirely. It can only
- be thrown by the "solar" and "lunar" operators, which allow the instruction pointer to jump around (an
- ability critical for logical operators and conditional statements, or branching). It is as if you gave
- the interpreter a To-Do list of 10 or so items in an order, and then said "Hey, no need to do that fifth
- thing, go do item 24, or -5 instead." Confusion would be understandable, and nothing would get done!
- ==Turing Machines and the MacroBeep Tape==
- ===What is a Turing Machine?===
- The Turing Machine is a theoretical machine first described by Alan Turing. It consists of a tape divided
- into cells and a pointer that can modify cells on the tape. The tape extends without bound, so the machine
- never runs out of cells. (In practice, this is not possible, but such a limitation is usually ignored).
- A Turing machine can do the following:
- Shift the pointer left or right
- Read the value on the cell
- Write a value to a cell
- The pointer can point to one cell at any given time, and it can only act on the cell at which it points.
- To act on another cell the pointer has to move to that cell. The pointer of a Turing Machine is programmable.
- It can be given instructions like: "Set the current cell to 0", or "If the current cell is one, go one
- cell to the right". These instructions describe something called a Finite State Machine, which a machine
- that knows its current state, and decides what to do next according to its instructions.
- In the case of "If the current cell is one, go one cell to the right", the pointer can read the current
- cell, and decide whether or not it should go to next cell on the right. If the current cell is one, the
- pointer goes right (which changes its state), and if not, it stays put.
- The typical Turing machine has cells that can be set to 0 or 1 (sometimes 'blank' or 'null' is included,
- meaning no data is on this cell). Here is a crude, plain text visual, with the pointer pointing to the
- second cell on the tape:
- 1 | 1 | 0 | 1 | 0 | 0 | 1
- ^
- The first cell of the tape is called the head of the tape, all other cells are positioned right of the
- head.
- The Turing Machine can compute anything that is computable, and anything that can simulate a Turing Machine
- can compute anything that is computable. To put it another way, such a machine can decide any decidable
- problem, or solve any solvable math problem if it is programmed to do so. Something that can simulate
- a Turing Machine is Turing Complete, and any Turing Complete system can simulate any other Turing Complete
- system.
- ===The MacroBeep Tape===
- MacroBeep makes use of a Turing Machine for computation, but cells on this machine can store any integer
- value from 0 to 255 inclusive. In other words, each cell stores a byte of information, equivalent to
- 8 cells in the tape above. Many esoteric programming languages use a tape like this one. The most notable
- example is none other than one of the earliest, a language by Urban M??¼ller with a swear word in the
- name,
- which will be referred to as bf. Here is a visual of the byte tape used in bf and MacroBeep:
- 000 | 255 | 023 | 150 | 045 | 213 | 010
- ^
- Note that, as with a Turing machine, the tape extends to the right without bound. Also note that the
- pointer can do all of the things a pointer on a Turing machine can. Furthermore this pointer can modify
- bytes, adding or subtracting from them such that they can be at any integer value from 0 to 255.
- The initial state of the tape is such that every cell is set to 0.
- In MacroBeep, 'pos' gives the pointer postion, 'out' gives the current cell value; 'left' and 'right'
- move the pointer, 'add' and 'sub' modify cell values. Note that 'pos' and 'out' are excellent debugging
- operations. See the Instruction Set for more information.
- ==Proof of Turing Completeness==
- bf is Turing complete, and consists of only eight instructions.
- Given the above, by translating each bf command to MacroBeep, it can be shown that MacroBeep is also
- Turing complete.
- This table provides a means to translate between MacroBeep and bf.
- MacroBeep bf Description
- right > increment
- left < decrement
- add + add 1 to cell
- sub - take 1 from cell
- cout . Output ASCII value at cell
- inp , Take input at cell
- lunar (by some positive number of instructions) [ jump past ' ] ' if cell is 0
- solar (by some negative number of instructions) ] goto ' [ ' if cell is greater than 0
- ==Grammar in EBNF==
- Extended Backus-Naur Form is a metasyntax that can describe the syntax of a programming language.
- It is useful for understanding how the language is parsed for interpretation.
- Key:
- ::= assignment, equivalence
- | or
- (group)
- {repeated at least one time}
- [optional]
- 'string literal'
- symbol
- , symbol concatination
- ; symbol terminator
- (*comment*)
- Program ::= {statement}
- statement ::= macro | command
- macro ::= 'macro', s, alnum, n, {command}, ['rt']; (*be careful when leaving out 'rt'*)
- command ::= word, s, [arg], n;
- arg ::= alnum | inte
- alnum ::= {(lett | digit)};
- word ::= {lett};
- inte ::= {digit};
- s ::= ' ';
- n ::= '\n';
- digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
- lett ::= 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' |
- 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' |
- 'y' | 'z';
- ==Interpreter Test Cases in Java==
- public class Tests {
- //Note that each instruct needs to be tested with and without parameters
- //Input and Output Tests
- //macro main is tested in every test in this category
- //Tests pr, comment, space, newline, then tab
- public static String HelloWorld = "macro main\n"
- + "pr Hello[]Worlds!\n # include SUDDENLY A COMMENT WOAH!!\n\npr\npr Hello{}World";
- //Tests pr, solar, halt, wait, inp 1
- public static String TruthMachine = "macro main\n"
- + "pr Type[]a[]0[]or[]1[]into[]the[]truth[]machine.\n"
- + "inp 1\n"
- + "solar 3\n"
- + "pr 0\n"
- + "halt\n"
- + "pr 1\n"
- + "wait\n"
- + "solar -3";
- public static String FalseMachine = "macro main\n"
- + " pr Type[]a[]0[]or[]1[]into[]the[]false[]machine.\n"
- + " inp 1\n"
- + " lunar 3\n"
- + " pr 1\n"
- + " halt\n"
- + " pr 0\n"
- + " wait\n"
- + " lunar -3\n";
- //Tests inp 2, head, cout, right, solar
- public static String Cat = "macro main\n"
- + "pr Give[]me[]a[]word[]and[]I[]will[]say[]it[]back!\ninp 2\nhead\n"
- + "cout\nright\nsolar -3";
- //Tests beep //should beep at 1000, 3300 mod 2501, and 500 hertz
- public static String Beep = "macro main\n beep\n beep 3300\n beep 500";
- //Should print the integer value of the given ASCII char
- public static String StdIO = "macro main\n inp \n out";
- //Should print the integer value of the given ASCII char
- public static String WhyIO = "macro main\n inp 7 \n out";
- public static String Outs = "macro main\nout\n out 75\n add 72\n cout\n sub 10\n cout 72\n";
- //Should output 3
- public static String posTest = "macro main\n right 5\n left 2\n right\n left\n pos";
- //Error Tests
- Should throw Err 1
- public static String BadInst = "macro main\n foo";
- Should throw Err 2
- public static String FNF = "include foo\n macro main";
- Err 2, get content of non-existant dir
- public static String PrepErr = "include this_directory_does_not_exist\*";
- Should throw Err 3
- public static String UndefMacro = "macro main\n do foo";
- Should throw Err 4
- public static String Null = "";
- . Throws 5. print stack length for this test, it throws an OutOfMemoryError
- public static String StackOverflow = "macro store\n do store\n \nmacro main\n do store";
- Should throw Err 6, tests left
- public static String NegCel = "macro main\nleft\nadd 50";
- Should throw Err 6, tests right
- public static String EndTape = "macro main\nright\nadd 2\n solar -3";
- Err 7 test
- public static String IncMac = "macro main\ninclude foo";
- Err 8 test
- public static String PrepErr = "include\n\nmacro main\n";
- Err 8, get content of empty dir
- public static String PrepErr = "include this_directory_is_empty\*";
- Err 9 test
- public static String DupM = "macro main\n macro foo\n macro foo";
- Throws 10
- public static String NonIntArg = "macro main\n wait foo";
- , tests wait, throws 11
- public static String BadArg = "macro main\n wait -100";
- err12
- public static String e12 = "macro main
- lunar -10";
- //Remaining Instruction Tests
- //The Solar and Lunar tests should output 0, PASSED
- public static String Solar = "macro main\n add 1\n pos\nsolar";
- public static String Lunar = "macro main\n pos\nlunar";
- Expected Output:
- //23
- //0
- public static String twthze = "macro thing\n"
- + " add\n"
- + " add 25\n"
- + " sub\n"
- + " sub 2\n"
- + " rt\n"
- + "macro main\n"
- + " do thing\n"
- + " out\n"
- + " pr\n"
- + " null\n"
- + " out\n"
- + " rt";
- outputs HH
- public static String Store = "macro main\n add 72\n str\n right\n cout\n str 5\n right 5\n cout";
- . Not a cell Error.
- public static String noStore = "macro main\n str -10";
- //Note each rand test should be done a few times
- outputs a random number from 0 - 255
- public static String Rand1 = "macro main\n rand\n out";
- rand from 0 - 10
- public static String Rand2 = "macro main\n rand 10\n out";
- output between 245 to 255
- public static String Rand3 = "macro main\n rand -10\n out";
- //Include Tests
- //There are four such tests, each test uses 3 files: MAIN, A, and B respectively.
- //Each test should produce the same output, a beep at 1000 and a beep at 500;
- //excluding the first test, which should only output a beep.
- //Test 1
- //MAIN
- //include a.mcbe
- //macro main
- //do b
- //A
- //macro b
- //beep
- //rt
- //Test 2
- //MAIN
- //include a.mcbe
- //include b.mcbe
- //macro main
- //do b
- //do c
- //A
- //macro b
- //beep
- //rt
- //B
- //macro c
- //beep 500
- //rt
- //Test 3
- //MAIN
- //include dir/a.mcbe
- //include dir/b.mcbe
- //macro main
- //do b
- //do c
- //A
- //macro b
- //beep
- //rt
- //B
- //macro c
- //beep 500
- //rt
- //Test 4
- //MAIN
- //include a.mcbe
- //macro main
- //do b
- //do c
- //A
- //include b.mcbe
- //macro b
- //beep
- //rt
- //B
- //macro c
- //beep 500
- //rt
- //Test 5
- //MAIN
- //include run\foo\*
- //macro main
- //do that
- //do this
- //A (in run/foo)
- //macro that
- //beep
- //rt
- //B (in run/foo/bar)
- //macro this
- //beep 500
- //rt
- }
- ==ASCII Table Reference==
- Characters on the ASCII table correspond to integer values. For example, "H" is equal to 72. In MacroBeep
- "cout 72" prints an H.
- Null 0
- Beep 7
- Tab 9
- New Line 10
- Space 32
- ! 33
- " 34
- # 35
- $ 36
- % 37
- & 38
- ' 39
- ( 40
- ) 41
- * 42
- + 43
- , 44
- - 45
- . 46
- / 47
- 0 48
- 1 49
- 2 50
- 3 51
- 4 52
- 5 53
- 6 54
- 7 55
- 8 56
- 9 57
- : 58
- ; 59
- < 60
- = 61
- > 62
- ? 63
- @ 64
- A 65
- B 66
- C 67
- D 68
- E 69
- F 70
- G 71
- H 72
- I 73
- J 74
- K 75
- L 76
- M 77
- N 78
- O 79
- P 80
- Q 81
- R 82
- S 83
- T 84
- U 85
- V 86
- W 87
- X 88
- Y 89
- Z 90
- [ 91
- \ 92
- ] 93
- ^ 94
- _ 95
- ` 96
- a 97
- b 98
- c 99
- d 100
- e 101
- f 102
- g 103
- h 104
- i 105
- j 106
- k 107
- l 108
- m 109
- n 110
- o 111
- p 112
- q 113
- r 114
- s 115
- t 116
- u 117
- v 118
- w 119
- x 120
- y 121
- z 122
- { 123
- | 124
- } 125
- ~ 126
- ==Change Log==
- - Added "run" directory.
- - Expanded criteria for errors 0 and 2 (Runtime Error 0 and Directory Error 2).
- - Added recursive file search.
- - Added option to list runnable files.
- - Added ability to add an asterisk to include statements to signify the inclusion of a directories entire contents.
- - Added new test cases for the feature above.
- - Updated Help and Tests classes.
- - Updated documentation.
- - Added this change log, as this is the first revision.
- ==Sources==
- ASCII table. ASCII Table - ASCII Character Codes, HTML, Octal, Hex, Decimal. (n.d.). Retrieved January 16, 2022, from https://www.asciitable.com/
- Bf. Esolang. (n.d.). Retrieved January 16, 2022, from https://esolangs.org/wiki/Bf (Swear word removed.)
- Macrobeep. Esolang. (n.d.). Retrieved January 16, 2022, from https://esolangs.org/wiki/MacroBeep
- Wikimedia Foundation. (2021, December 25). Extended backus-naur form. Wikipedia. Retrieved January 17, 2022, from https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form#Table_of_Symbols
- Wikimedia Foundation. (2022, January 4). Turing completeness. Wikipedia. Retrieved January 16, 2022, from https://en.wikipedia.org/wiki/Turing_completeness
- Wikimedia Foundation. (2022, January 14). Turing machine. Wikipedia. Retrieved January 16, 2022, from https://en.wikipedia.org/wiki/Turing_machine
- ==Contents==
- Acknowledgements
- Introduction to MacroBeep
- Language Paradigm and Memory
- Instruction Set
- The Preprocessor
- Program Examples
- Error Codes
- Turing Machines and the MacroBeep Tape
- Proof of Turing Completeness
- Grammar in EBNF
- Interpreter Test Cases in Java
- ASCII Table Reference
- Change Log
- Sources
- =End of Documentation (Scroll Up)=
Add Comment
Please, Sign In to add comment