├── .gitignore ├── LICENSE ├── README.md ├── scripts ├── .gitignore ├── cat.rekt └── hello.rekt └── src ├── .gitigore └── interpreter.go /.gitignore: -------------------------------------------------------------------------------- 1 | *.rekt 2 | *.go 3 | 4 | interpreter 5 | prepare.sh 6 | 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 PieMan2201 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation 5 | the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, 6 | and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions 9 | of the Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 12 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 13 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 14 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 15 | DEALINGS IN THE SOFTWARE. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rocketlang 2 | A programming language based on Rocket League quick chat. 3 | ## Why? 4 | Why not? 5 | ## How to 6 | 1. Download the source 7 | 2. Download and install Go 8 | 3. `$ go build interpreter.go` 9 | 4. Write your rocketlang program (*.rekt) 10 | 5. `$ interpreter [path to file]` 11 | 12 | ## Overview 13 | rocketlang consists of 2 variables and a stack. These variables can be pushed to the stack and the stack can pop to them. Only one of the variables is modified at a time. To modify the other variable, one must switch which variable is in use. 14 | ### Statements 15 | 16 | `Wow!` increments the current variable by 1 17 | 18 | `Close one!` decrements the current variable by 1 19 | 20 | `OMG!` switches between the current variables 21 | 22 | `Noooo!` pushes 0 to the stack 23 | 24 | `Centering...` pops from the stack to the current variable 25 | 26 | `Defending...` pushes from the current variable to the stack 27 | 28 | `I got it!` outputs the ASCII value of the current variable 29 | 30 | `Take the shot!` reads one byte from input and sets the current variable to it 31 | 32 | `Nice shot!` begins an if statement which runs if the 2 variables are equal 33 | 34 | `What a save!` ends an if statement 35 | 36 | `Great pass!` begins a loop which runs if the current variable is `>` 0 37 | 38 | `Thanks!` goes back to the top of the loop if the current variable is `>` 0 39 | 40 | `Whoops...` sets the variable not in use to the current variable (equivalent to `Defending...\nOMG!\nCentering...\nOMG!`) 41 | 42 | `Sorry!` outputs debug information between two newlines (stack, var0, var1, current) 43 | 44 | `No Problem.` toggles error recognition 45 | 46 | `$#@%!` is outputted along with a line number when you messed up if error recognition is on 47 | 48 | ## hello world 49 | See `scripts/hello.rekt` 50 | -------------------------------------------------------------------------------- /scripts/.gitignore: -------------------------------------------------------------------------------- 1 | !*.rekt 2 | -------------------------------------------------------------------------------- /scripts/cat.rekt: -------------------------------------------------------------------------------- 1 | Wow! 2 | Great pass! 3 | 4 | Noooo! 5 | Centering... 6 | Take the shot! 7 | I got it! 8 | 9 | Thanks! 10 | -------------------------------------------------------------------------------- /scripts/hello.rekt: -------------------------------------------------------------------------------- 1 | Wow! 2 | Wow! 3 | Wow! 4 | Wow! 5 | Wow! 6 | Wow! 7 | Wow! 8 | Wow! 9 | Wow! 10 | Wow! 11 | Great pass! 12 | OMG! 13 | Wow! 14 | Wow! 15 | Wow! 16 | Wow! 17 | Wow! 18 | Wow! 19 | Wow! 20 | Wow! 21 | Wow! 22 | Wow! 23 | OMG! 24 | Close one! 25 | Thanks! 26 | 27 | OMG! 28 | Defending... 29 | 30 | OMG! 31 | Noooo! 32 | Centering... 33 | Wow! 34 | Wow! 35 | 36 | Great pass! 37 | OMG! 38 | Wow! 39 | Wow! 40 | Wow! 41 | Wow! 42 | OMG! 43 | Close one! 44 | Thanks! 45 | 46 | OMG! 47 | Defending... 48 | 49 | Wow! 50 | Wow! 51 | Wow! 52 | Wow! 53 | Wow! 54 | Wow! 55 | 56 | Defending... 57 | 58 | Close one! 59 | Close one! 60 | Close one! 61 | 62 | Defending... 63 | 64 | OMG! 65 | Noooo! 66 | Centering... 67 | Wow! 68 | Wow! 69 | 70 | Great pass! 71 | OMG! 72 | Wow! 73 | Wow! 74 | Wow! 75 | Wow! 76 | OMG! 77 | Close one! 78 | Thanks! 79 | 80 | OMG! 81 | Defending... 82 | 83 | Noooo! 84 | Centering... 85 | 86 | OMG! 87 | Noooo! 88 | Centering... 89 | Wow! 90 | Wow! 91 | Wow! 92 | Wow! 93 | 94 | Great pass! 95 | OMG! 96 | Wow! 97 | Wow! 98 | Wow! 99 | Wow! 100 | Wow! 101 | Wow! 102 | Wow! 103 | Wow! 104 | OMG! 105 | Close one! 106 | Thanks! 107 | 108 | OMG! 109 | Defending... 110 | 111 | Noooo! 112 | Centering... 113 | 114 | OMG! 115 | Noooo! 116 | Centering... 117 | Wow! 118 | Wow! 119 | Wow! 120 | Wow! 121 | Wow! 122 | Wow! 123 | Wow! 124 | Wow! 125 | Wow! 126 | Wow! 127 | Wow! 128 | 129 | Great pass! 130 | OMG! 131 | Wow! 132 | Wow! 133 | Wow! 134 | Wow! 135 | Wow! 136 | Wow! 137 | Wow! 138 | Wow! 139 | Wow! 140 | Wow! 141 | OMG! 142 | Close one! 143 | Thanks! 144 | 145 | OMG! 146 | Wow! 147 | Defending... 148 | 149 | Close one! 150 | Close one! 151 | Close one! 152 | 153 | Defending... 154 | Defending... 155 | 156 | Close one! 157 | Close one! 158 | Close one! 159 | Close one! 160 | Close one! 161 | Close one! 162 | Close one! 163 | Defending... 164 | 165 | Wow! 166 | Wow! 167 | Wow! 168 | Defending... 169 | 170 | Centering... 171 | 172 | Great pass! 173 | 174 | I got it! 175 | Centering... 176 | 177 | Thanks! 178 | 179 | Nice shot! 180 | 181 | OMG! 182 | Wow! 183 | Wow! 184 | Wow! 185 | 186 | Great pass! 187 | OMG! 188 | Wow! 189 | Wow! 190 | Wow! 191 | OMG! 192 | Close one! 193 | Thanks! 194 | OMG! 195 | Wow! 196 | 197 | What a save! 198 | 199 | I got it! -------------------------------------------------------------------------------- /src/.gitigore: -------------------------------------------------------------------------------- 1 | !*.go 2 | -------------------------------------------------------------------------------- /src/interpreter.go: -------------------------------------------------------------------------------- 1 | //Build and run to use rocketlang 2 | package main 3 | 4 | import( 5 | "fmt" 6 | "bufio" 7 | "os" 8 | "strings" 9 | "strconv" 10 | "io/ioutil" 11 | ) 12 | 13 | var stk = make([]int, 1) 14 | var cr1 = 0 15 | var cr2 = 0 16 | var crc = 0 17 | 18 | var cms = make([]string, 0) 19 | var inp string 20 | var ind = 0 21 | 22 | var err = true 23 | 24 | func input(prompt string) string { 25 | reader := bufio.NewReader(os.Stdin) 26 | fmt.Print(prompt) 27 | text, _ := reader.ReadString('\n') 28 | return text[:len(text) - 1] 29 | } 30 | 31 | func inform() { 32 | erl := "S#@" + string(37) + "!\nChat disabled for " + strconv.Itoa(ind + 1) + " seconds." 33 | if err { 34 | fmt.Println("\n" + erl) 35 | os.Exit(1) 36 | } 37 | } 38 | 39 | func push(toPush int) { 40 | tempStk := make([]int, len(stk) + 1) 41 | for i, val := range stk { 42 | tempStk[i + 1] = val 43 | } 44 | tempStk[0] = toPush 45 | stk = tempStk 46 | } 47 | 48 | func pop() int { 49 | toPop := 0 50 | if len(stk) > 0 { 51 | toPop = stk[0] 52 | stk = stk[1:] 53 | } else { 54 | inform() 55 | } 56 | return toPop 57 | } 58 | 59 | func interpret(line string) { 60 | cur := 0 61 | if crc == 0 { 62 | cur = cr1 63 | } else if crc == 1 { 64 | cur = cr2 65 | } 66 | 67 | switch line { 68 | case "Wow!": 69 | cur++ 70 | case "Close one!": 71 | cur-- 72 | case "OMG!": 73 | crc = (crc + 1) % 2 74 | if crc == 0 { 75 | cur = cr1 76 | } else if crc == 1 { 77 | cur = cr2 78 | } 79 | case "Noooo!": 80 | push(0) 81 | case "Centering...": 82 | cur = pop() 83 | case "Defending...": 84 | push(cur) 85 | case "I got it!": 86 | fmt.Print(string(byte(cur))) 87 | case "Take the shot!": 88 | if len(inp) > 0 { 89 | cur = int(byte(inp[0])) 90 | inp = inp[1:] 91 | } 92 | case "Nice shot!": 93 | if cr1 != cr2 { ind++ 94 | for starts := 1; starts > 0; ind++ { 95 | if cms[ind] == "Nice shot!" { 96 | starts++ 97 | } else if cms[ind] == "What a save!" { 98 | starts-- 99 | } 100 | }; ind-- 101 | } 102 | case "Great pass!": 103 | if cur <= 0 { ind++ 104 | for starts := 1; starts > 0; ind++ { 105 | if cms[ind] == "Great pass!" { 106 | starts++ 107 | } else if cms[ind] == "Thanks!" { 108 | starts-- 109 | } 110 | }; ind-- 111 | } 112 | case "Thanks!": 113 | if cur > 0 { ind-- 114 | for stops := 1; stops > 0; ind-- { 115 | if cms[ind] == "Thanks!" { 116 | stops++ 117 | } else if cms[ind] == "Great pass!" { 118 | stops-- 119 | } 120 | }; ind++ 121 | } 122 | case "Sorry!": 123 | fmt.Println(stk, cr1, cr2, crc) 124 | case "No Problem.": 125 | err = !err 126 | case "Whoops...": 127 | if crc == 0 { 128 | cr2 = cr1 129 | } else if crc == 1 { 130 | cr1 = cr2 131 | } 132 | default: 133 | isBlank := true 134 | for _, char := range line { 135 | if char != ' ' { 136 | isBlank = false 137 | break 138 | } 139 | } 140 | if !isBlank { 141 | inform() 142 | } 143 | } 144 | 145 | if crc == 0 { 146 | cr1 = cur 147 | } else if crc == 1 { 148 | cr2 = cur 149 | } 150 | } 151 | 152 | func main() { 153 | path := "" 154 | if len(os.Args) > 1 { 155 | path = os.Args[1] 156 | } else { 157 | inform() 158 | } 159 | barray, _ := ioutil.ReadFile(path) 160 | cms = strings.Split(string(barray), "\n") 161 | for _, cm := range cms { 162 | if cm == "Take the shot!" { 163 | inp = input("Input: ") 164 | break 165 | } 166 | } 167 | for ind < len(cms) { 168 | interpret(cms[ind]) 169 | ind++ 170 | } 171 | } 172 | --------------------------------------------------------------------------------