├── src ├── favicon.ico ├── package.json ├── muffin.grammar.in ├── editor.js ├── muffin.css ├── index.html ├── frontend.js ├── package-lock.json └── muffin.js ├── .gitignore ├── LICENSE └── README.md /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CBerJun/Muffin/HEAD/src/favicon.ico -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | node_modules/ 3 | 4 | # My secret notes 5 | /BRAINSTORM.txt 6 | 7 | # Generated contents 8 | /build 9 | /dist 10 | /src/parser.js 11 | /src/autocomplete.js 12 | -------------------------------------------------------------------------------- /src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "dependencies": { 4 | "@codemirror/autocomplete": "^6.18.3", 5 | "@codemirror/commands": "^6.1.2", 6 | "@codemirror/search": "^6.2.3", 7 | "@codemirror/theme-one-dark": "^6.1.0", 8 | "@codemirror/view": "^6.6.0", 9 | "@lezer/common": "^1.2.3", 10 | "@lezer/generator": "^1.7.1", 11 | "@lezer/highlight": "^1.2.1", 12 | "@lezer/lr": "^1.4.2", 13 | "@rollup/plugin-node-resolve": "^15.0.1", 14 | "minify": "^9.1.0", 15 | "rollup": "^3.5.1" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/muffin.grammar.in: -------------------------------------------------------------------------------- 1 | @top Program { 2 | Newline? recipe* 3 | } 4 | 5 | @skip { 6 | WS 7 | } 8 | 9 | known_keyword[@name=MiscKeyword] { 10 | %misc_keywords% 11 | } 12 | 13 | kw { @specialize[@name=SpecialKeyword] } 14 | 15 | known_identifier[@name=KnownIdentifier] { 16 | %identifiers% 17 | } 18 | 19 | step_content { 20 | String 21 | | Number 22 | | Operators 23 | | known_keyword 24 | | known_identifier 25 | | Keyword 26 | | Identifier 27 | } 28 | 29 | recipe_name[@name=RecipeName] { 30 | (Identifier | known_identifier)+ 31 | } 32 | 33 | ingredient_body[@name=IngredientBody] { 34 | kw<"ingredients"> Newline ingredient* 35 | } 36 | 37 | step_body[@name=StepBody] { 38 | kw<"method"> Newline step* 39 | } 40 | 41 | recipe[@name=RecipeDef] { 42 | recipe_name kw<"recipe"> Newline 43 | ingredient_body 44 | step_body 45 | } 46 | 47 | ingredient_name[@name=IngredientName] { 48 | (Identifier | known_identifier)+ 49 | } 50 | 51 | ingredient { 52 | (Number | String) (known_keyword | Keyword)* ingredient_name Newline 53 | } 54 | 55 | step { 56 | Number step_content* Newline 57 | } 58 | 59 | @tokens { 60 | WS { 61 | $[ \t]+ 62 | } 63 | Newline { 64 | $[\n]+ | @eof 65 | } 66 | String { 67 | '"' !["\n]* '"' 68 | } 69 | Number { 70 | @digit+ ($[CF.] | %ordinal%)? 71 | } 72 | Operators { 73 | %operators% 74 | } 75 | Keyword { 76 | @asciiLowercase $[a-zA-Z0-9_]* 77 | } 78 | Identifier { 79 | @asciiUppercase $[a-zA-Z0-9_]* 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/editor.js: -------------------------------------------------------------------------------- 1 | import { EditorState } from '@codemirror/state'; 2 | import { openSearchPanel, highlightSelectionMatches } from '@codemirror/search'; 3 | import { indentWithTab, history, defaultKeymap, historyKeymap } from '@codemirror/commands'; 4 | import { foldGutter, indentUnit, foldKeymap, LanguageSupport, LRLanguage, indentNodeProp } from '@codemirror/language'; 5 | import { autocompletion, completionKeymap, acceptCompletion, closeBrackets } from '@codemirror/autocomplete'; 6 | import { 7 | lineNumbers, highlightActiveLineGutter, drawSelection, 8 | rectangularSelection, crosshairCursor, highlightActiveLine, keymap, 9 | EditorView 10 | } from '@codemirror/view'; 11 | import { oneDark } from "@codemirror/theme-one-dark"; 12 | import { parser } from "./parser.js"; 13 | import { styleTags, tags as t } from "@lezer/highlight"; 14 | import * as autocompleteData from "./autocomplete.js"; 15 | 16 | const muffinParser = parser.configure({ 17 | props: [ 18 | styleTags({ 19 | "String": t.string, 20 | "Number": t.integer, 21 | "Operators": t.punctuation, 22 | "MiscKeyword": t.operatorKeyword, 23 | "SpecialKeyword": t.controlKeyword, 24 | "RecipeName/...": t.className, 25 | "IngredientName/...": t.atom, 26 | "KnownIdentifier": t.variableName, 27 | }), 28 | indentNodeProp.add({ 29 | "IngredientBody StepBody": (context) => 30 | context.baseIndent + context.unit, 31 | }), 32 | ] 33 | // TODO folding 34 | }); 35 | 36 | const muffinLanguage = LRLanguage.define({ 37 | parser: muffinParser, 38 | languageData: { 39 | closeBrackets: { 40 | brackets: ['"'], 41 | }, 42 | }, 43 | }); 44 | 45 | const kwRegexp = /\b([a-z]\w* )*\b[a-z]\w*/; 46 | const idRegexp = /\b([A-Z]\w* )*\b[A-Z]\w*/; 47 | 48 | const muffinCompletion = muffinLanguage.data.of({ 49 | autocomplete: (context) => { 50 | // Determine if the user is trying to type a keyword (lowercase) 51 | // or an identifier (Title Case) 52 | const kwMatch = context.matchBefore(kwRegexp); 53 | let data; 54 | let from; 55 | let validFor; 56 | if (kwMatch) { 57 | data = autocompleteData.keywords; 58 | from = kwMatch.from; 59 | validFor = kwMatch; 60 | } 61 | else { 62 | const idMatch = context.matchBefore(idRegexp); 63 | if (idMatch) { 64 | data = autocompleteData.identifiers; 65 | from = idMatch.from; 66 | validFor = idMatch; 67 | } 68 | else if (context.explicit) { 69 | data = autocompleteData.allNames; 70 | from = context.pos; 71 | } 72 | else { 73 | // If completion wasn't explicitly started and there 74 | // is no word before the cursor, don't open completions. 75 | return null; 76 | } 77 | } 78 | return { 79 | from, 80 | options: data, 81 | validFor: validFor ? new RegExp(`^${validFor.source}$`) 82 | : undefined, 83 | }; 84 | }, 85 | }); 86 | 87 | function muffin() { 88 | return new LanguageSupport(muffinLanguage, [muffinCompletion]); 89 | } 90 | 91 | export function createEditorState(initialContents) { 92 | const extensions = [ 93 | lineNumbers(), 94 | highlightActiveLineGutter(), 95 | history(), 96 | foldGutter(), 97 | drawSelection(), 98 | indentUnit.of(" "), 99 | autocompletion(), 100 | closeBrackets(), 101 | EditorState.allowMultipleSelections.of(true), 102 | rectangularSelection(), 103 | crosshairCursor(), 104 | highlightActiveLine(), 105 | highlightSelectionMatches(), 106 | keymap.of([ 107 | { 108 | key: "Tab", 109 | run: acceptCompletion, 110 | }, 111 | { 112 | key: "Mod-f", 113 | run: openSearchPanel, 114 | }, 115 | indentWithTab, 116 | ...defaultKeymap, 117 | ...historyKeymap, 118 | ...foldKeymap, 119 | ...completionKeymap, 120 | ]), 121 | muffin(), 122 | EditorView.theme({".cm-scroller": {fontFamily: "inherit"}}), 123 | oneDark, 124 | ]; 125 | 126 | return EditorState.create({ 127 | doc: initialContents, 128 | extensions 129 | }); 130 | } 131 | 132 | export { EditorView }; 133 | -------------------------------------------------------------------------------- /src/muffin.css: -------------------------------------------------------------------------------- 1 | body { 2 | --body-margin-y: 4px; 3 | background-color: black; 4 | font-family: Consolas, monaco, monospace; 5 | color: white; 6 | margin: var(--body-margin-y) 0.75em; 7 | padding: 0; 8 | } 9 | 10 | div#body-wrapper { 11 | display: flex; 12 | flex-direction: column; 13 | height: calc(100vh - 2 * var(--body-margin-y)); 14 | } 15 | 16 | div#demo-body { 17 | flex-grow: 1; 18 | display: flex; 19 | } 20 | 21 | div#body-left, 22 | div#body-right { 23 | width: 50%; 24 | display: flex; 25 | flex-direction: column; 26 | padding: 0 0.5em; 27 | } 28 | 29 | h1#title { 30 | font-size: 24px; 31 | text-align: center; 32 | margin-top: 0.2em; 33 | margin-bottom: 0; 34 | } 35 | 36 | p#description { 37 | text-align: center; 38 | margin-top: 0.2em; 39 | } 40 | 41 | div#code-wrapper { 42 | position: relative; 43 | height: 100%; 44 | } 45 | 46 | div#code { 47 | position: absolute; 48 | overflow-y: auto; 49 | top: 0; 50 | bottom: 0; 51 | left: 0; 52 | right: 0; 53 | border: solid 1px rgb(84, 87, 89); 54 | font-size: 14px; 55 | } 56 | 57 | .cm-editor { 58 | height: 100%; 59 | } 60 | 61 | .cm-search button[name="close"] { 62 | color: white; 63 | } 64 | 65 | div#toolbar { 66 | display: flex; 67 | gap: 4px; 68 | } 69 | 70 | button#run, 71 | button#compile-to-node, 72 | button#load-example, 73 | button#open-docs { 74 | display: flex; 75 | align-items: center; 76 | gap: 0.3em; 77 | font-family: inherit; 78 | font-size: 20px; 79 | color: white; 80 | border: 1px solid; 81 | border-radius: 2px; 82 | cursor: pointer; 83 | } 84 | 85 | button#run svg, 86 | button#load-example svg { 87 | fill: white; 88 | } 89 | 90 | button#run.can-run { 91 | background-color: #008024; 92 | border-color: #01b328; 93 | } 94 | button#run.can-run:hover { 95 | background-color: #019927; 96 | } 97 | button#run.can-run svg#stop-icon { 98 | display: none; 99 | } 100 | 101 | button#run.can-stop { 102 | background-color: #b30000; 103 | border-color: #ff0000; 104 | } 105 | button#run.can-stop:hover { 106 | background-color: #db0000; 107 | } 108 | button#run.can-stop svg#run-icon { 109 | display: none; 110 | } 111 | 112 | button#compile-to-node { 113 | background-color: #1f69d1; 114 | border-color: #3e8fff; 115 | } 116 | button#compile-to-node:hover { 117 | background-color: #2580ff; 118 | } 119 | 120 | button#compile-to-node svg, 121 | button#open-docs svg { 122 | stroke: white; 123 | } 124 | 125 | div#example-dropdown { 126 | display: inline-block; 127 | position: relative; 128 | } 129 | 130 | div#examples { 131 | display: none; 132 | position: absolute; 133 | box-shadow: 0px 1px 2px 1px #ffffff66; 134 | } 135 | div#example-dropdown:hover div#examples { 136 | display: block; 137 | z-index: 1; 138 | } 139 | 140 | div#examples span { 141 | display: block; 142 | background-color: #282c34; 143 | color: white; 144 | cursor: pointer; 145 | font-size: 14px; 146 | padding: 0.15em 0.3em; 147 | } 148 | div#examples span:hover { 149 | background-color: #6bacff; 150 | color: black; 151 | } 152 | 153 | button#load-example { 154 | cursor: auto; 155 | background-color: #8a00a3; 156 | border-color: #b623d0; 157 | } 158 | 159 | button#open-docs { 160 | background-color: #178ca0; 161 | border-color: #25b3cb; 162 | } 163 | button#open-docs:hover { 164 | background-color: #1aaac2; 165 | } 166 | 167 | div#execution-wrapper { 168 | position: relative; 169 | height: 100%; 170 | } 171 | p#execution { 172 | position: absolute; 173 | overflow-y: auto; 174 | top: 0; 175 | bottom: 0; 176 | left: 0; 177 | right: 0; 178 | background-color: #282c34; 179 | border: solid 1px rgb(84, 87, 89); 180 | padding: 0.4em 0.7em; 181 | font-size: 14px; 182 | } 183 | 184 | span.exec-error { 185 | color: #f55663; 186 | } 187 | span.exec-info { 188 | color: rgb(164, 164, 164); 189 | } 190 | span.exec-normal { 191 | color: white; 192 | } 193 | span.exec-input { 194 | color: #6bacff; 195 | } 196 | 197 | div#input-bar { 198 | display: flex; 199 | margin: 0.45em 0; 200 | } 201 | 202 | input#input-line { 203 | flex-grow: 1; 204 | outline: none; 205 | padding: 0.25em 0.5em; 206 | font-family: inherit; 207 | font-size: 14px; 208 | background-color: #282c34; 209 | color: white; 210 | border: 1px solid rgb(84, 87, 89); 211 | border-radius: 2px 0 0 2px; 212 | } 213 | input#input-line:disabled { 214 | border-color: #949aa9; 215 | background-color: #4a515f; 216 | cursor: not-allowed; 217 | } 218 | input#input-line::placeholder { 219 | color: #afafaf; 220 | } 221 | 222 | button#send { 223 | font-family: inherit; 224 | font-size: 16px; 225 | color: white; 226 | border: 1px solid; 227 | border-radius: 0 2px 2px 0; 228 | } 229 | button#send:enabled { 230 | background-color: #ad5700; 231 | border-color: #ff8000; 232 | cursor: pointer; 233 | } 234 | button#send:enabled:hover { 235 | background-color: #d76c00; 236 | } 237 | 238 | button#send:disabled, 239 | button#compile-to-node:disabled { 240 | background-color: #808080; 241 | border-color: #afafaf; 242 | cursor: not-allowed; 243 | } 244 | 245 | p { 246 | margin-top: 0.5em; 247 | margin-bottom: 0.5em; 248 | } 249 | 250 | a { 251 | color: rgb(35, 182, 255); 252 | /* 253 | These are usually defined in UA style sheet but links that does 254 | not actually "link" anywhere (no href) may not have them: 255 | */ 256 | text-decoration: underline; 257 | cursor: pointer; 258 | } 259 | a:visited { 260 | color: rgb(140, 140, 237); 261 | } 262 | a:hover { 263 | color: rgb(0, 200, 255); 264 | } 265 | 266 | p.fine-print { 267 | font-size: 14px; 268 | } 269 | -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Muffin! 7 | 8 | 9 | 10 | 11 |
12 |

The Muffin Programming Language

13 |

14 | A programming language I made that allows you to write programs 15 | that look like cooking recipes. Check out the 16 | README file for details! 20 |

21 |
22 |
23 |
24 |
25 |
26 | 39 |
40 |
41 |
42 | 59 | 75 |
76 | 84 |
85 |
86 | 104 |
105 |
106 |

107 | 108 | Welcome to Muffin's online compiler! 109 |
110 |
111 | Write your code (recipe) using the editor on 112 | the left, and click the Run button to run it! 113 |
114 | A Hello, world! example has been loaded in the 115 | editor. 116 |
117 |

118 |
119 |
120 | 123 | 129 |
130 |
131 |
132 |
133 | 134 | 135 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The Muffin Programming Language 2 | 3 | **Muffin** is a brand new **programming language** designed and implemented by 4 | me in order to participate in [High Seas hold by Hack Club][high-seas]. 5 | 6 | Muffin allows you to write programs that look like **cooking recipes**. 7 | 8 | Here is "Hello, world!" in Muffin: 9 | 10 | ``` 11 | Muffin recipe 12 | ingredients 13 | "Hello, world!" brand Flour 14 | method 15 | 1. set up a Muffin Cup 16 | 2. add Flour into Muffin Cup 17 | 3. microwave Muffin Cup 18 | 4. serves 1 19 | ``` 20 | 21 | I know this is definitely *not* how you make muffins, but it *is* a program 22 | that will print out "Hello, world!". 23 | 24 | This program prints out the first 20 Fibonacci numbers: 25 | 26 | ``` 27 | Muffin recipe 28 | ingredients 29 | 1 Blueberry 30 | 19 grams of Butter 31 | method 32 | 1. set up 4 Bowls 33 | 2. add Blueberry into 3rd Bowl 34 | 3. add water to 1st Bowl at a 1:1 ratio 35 | 4. pour half of contents of 1st Bowl into 4th Bowl 36 | 5. remove Butter from 4th Bowl 37 | 6. if 4th Bowl is not empty, proceed to step 15 38 | 7. place 3rd Bowl in the oven and bake at 190C 39 | 8. clean 4th Bowl 40 | 9. pour contents of 2nd Bowl into 4th Bowl 41 | 10. add water to 3rd Bowl at a 1:1 ratio 42 | 11. pour half of contents of 3rd Bowl into 2nd Bowl 43 | 12. pour contents of 4th Bowl into 3rd Bowl 44 | 13. add Blueberry into 1st Bowl 45 | 14. go back to step 3 46 | 15. serves 1 47 | ``` 48 | 49 | [high-seas]: https://highseas.hackclub.com/ 50 | 51 | # Visit Muffin's [demo website][muffin-demo]! 52 | 53 | I built a web page so that you can play around a bit with Muffin! You can run 54 | Muffin programs in the browser, see more example Muffin programs, and write 55 | your recipe in an editor with syntax highlighting, autocompletion and other 56 | features in your favorite IDE! (Thanks to [Cloudflare Pages][cloudflare-pages] 57 | for hosting this!) 58 | 59 | [muffin-demo]: https://muffinlang.pages.dev/ 60 | [cloudflare-pages]: https://pages.cloudflare.com/ 61 | 62 | # Language Specification 63 | 64 | Here are a few important concepts of Muffin: 65 | 66 | * *Recipes* are equivalent to functions/procedures in many programming 67 | languages. A recipe is made up of a name, ingredients and a method. The 68 | function's name is what this tasty recipe produces (e.g. `Raisin Scone`). The 69 | `Muffin` recipe is the entry recipe of the whole program (similar to `main` 70 | in C/C++, Java, Go, etc.), i.e. when you execute a Muffin code the `Muffin` 71 | recipe will be invoked. 72 | * *Bowls* are equivalent to variables in many programming languages. The data 73 | hold by bowls are always *unsigned integers*, i.e. nonnegative integers. 74 | *You can't have -10 grams of butter in a bowl!* A bowl has a 75 | *bowl kind* and a *bowl number*. You can declare how many bowls there are 76 | for a specific bowl kind, and each bowl can be referred to using their 77 | number. 78 | 79 | For example, if you set up four `Glass Bowls`, then the four bowls can be 80 | referred to as `1st Glass Bowl`, `2nd Glass Bowl`, etc. If there is only one 81 | bowl of a kind, then just use the bowl kind to refer to that bowl (e.g. 82 | `Glass Bowl`). 83 | 84 | Bowls are "local" to the recipe they are in. That is, two bowls, even if they 85 | have the same kind and number, aren't the same if they are in two different 86 | recipes. 87 | * *Ingredients* are used for writing constants in Muffin. The way you write 88 | `x + 10` in Muffin is to declare an ingredient with value 10 and "add" that 89 | ingredient into a bowl. An ingredient can also take a string value, and in 90 | that case you can't add it to a bowl. 91 | * A *method* is the body of a recipe. It consists of a series of *steps*, which 92 | are equivalent to statements in other languages. 93 | * *Molds* are Muffin's implementation of stack -- it is a list of values, but 94 | you only have access to the last element. Similar to how bowls work, molds 95 | have a *mold kind* and a *mold number*, and you refer to them using ordinals 96 | if there are multiple molds of the same kind. 97 | 98 | The difference between molds and bowls is that molds may contain both string 99 | and unsigned integers (just like ingredients), while bowls can only contain 100 | unsigned integers. Another difference is that molds are "global". That is, 101 | all the recipes share the same molds. 102 | 103 | Regarding the syntax: 104 | 105 | * All `lowercase phrases` are *keywords*. That means, all these phrases are 106 | reserved. 107 | * All `Title Case Phrases` are *identifiers* and you may use these names 108 | freely. 109 | * There is no comment. *Why do you expect a "comment" in a cooking recipe?* 110 | * New lines are significant. However, blank lines are ignored. 111 | * Indentation is not significant. 112 | 113 | A Muffin program consists of many recipes, separated by new lines. 114 | *I guess you could call a Muffin program a "recipe book".* 115 | 116 | A recipe takes this form: 117 | 118 | ``` 119 | recipe 120 | ingredients 121 | 122 | method 123 | 124 | ``` 125 | 126 | `` should be an identifier (Title Case). That's the name of this 127 | recipe. 128 | 129 | `` is a list of ingredient declarations separated by new 130 | lines. An ingredient declaration takes any of these forms: 131 | 132 | ``` 133 | brand 134 | 135 | grams of 136 | ``` 137 | 138 | `` must be an identifier. `` must be a double quoted 139 | string literal. There is no escape. *What brand name has a double quote in it?* 140 | The first form declares `` to be a string ``. The 141 | latter two forms are the same and declare `` to be an integer 142 | constant ``. 143 | 144 | `` is a list of steps separated by new lines. When a recipe is 145 | executed, the steps in this `` will be executed, from the first step 146 | to the last step. A step takes either of these forms: 147 | 148 | ``` 149 |