|
1 | 1 | # NURU✨PROGRAMMING✨LANGUAGE
|
2 |
| -Lugha enye Nuru 😂 |
| 2 | +<p align="center"> |
| 3 | + <a href="https://github.com/AvicennaJr/Nuru"><img alt="Nuru Programming Language" src="https://img.shields.io/badge/Nuru-Programming%20Language-yellow"></a> |
| 4 | + <a href="https://github.com/AvicennaJr/Nuru"><img alt="Nuru Programming Language" src="https://img.shields.io/badge/platform-Linux | Windows | Android-green.svg"></a> |
| 5 | + <a href="https://github.com/AvicennaJr/Nuru"><img alt="Nuru Programming Language" src="https://img.shields.io/github/last-commit/AvicennaJr/Nuru"></a> |
| 6 | + <a href="https://github.com/AvicennaJr/Nuru"><img alt="Nuru Programming Language" src="https://img.shields.io/github/v/release/AvicennaJr/Nuru"></a> |
| 7 | +<br> |
| 8 | + <a href="https://github.com/AvicennaJr/Nuru"><img alt="Nuru Programming Language" src="https://img.shields.io/github/stars/AvicennaJr/Nuru?style=social"></a> |
| 9 | +</p> |
| 10 | +A Swahili Programming Language of its kind built from the ground up. |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +To get started download the executables from the release page or follow the |
| 15 | +instructions for your device below: |
| 16 | + |
| 17 | +### Linux |
| 18 | + |
| 19 | + - Download the binary: |
| 20 | +``` |
| 21 | +curl //download URL |
| 22 | +``` |
| 23 | + - Add it to your $PATH |
| 24 | +``` |
| 25 | +cp nuru $HOME/bin |
| 26 | +``` |
| 27 | + - Confirm installation with: |
| 28 | +``` |
| 29 | +nuru -v |
| 30 | +``` |
| 31 | + |
| 32 | +### Android (Termux) |
| 33 | + |
| 34 | + - Make sure you have [Termux](https://f-droid.org/repo/com.termux_118.apk) installed. |
| 35 | + - Download the binary with this command: |
| 36 | + |
| 37 | +``` |
| 38 | +curl //download link |
| 39 | +``` |
| 40 | + - Add it to path: |
| 41 | + |
| 42 | +``` |
| 43 | +echo "alias nuru='~/nuru'" >> .bashrc |
| 44 | +``` |
| 45 | + - Confirm installation with: |
| 46 | + |
| 47 | +``` |
| 48 | +nuru -v |
| 49 | +``` |
| 50 | + |
| 51 | +### Windows |
| 52 | + |
| 53 | + - Make a bin directory if it doesn't exist: |
| 54 | + |
| 55 | +``` |
| 56 | +mkdir C:\bin |
| 57 | +``` |
| 58 | + - Move the downloaded binary `nuru.exe` to the folder `C:\bin` |
| 59 | + - Add the bin folder to Path with this command: |
| 60 | + |
| 61 | +``` |
| 62 | +setx PATH "C:\bin;%PATH%" |
| 63 | +``` |
| 64 | + - Confirm installation with: |
| 65 | + |
| 66 | +``` |
| 67 | +nuru -v |
| 68 | +``` |
| 69 | + |
| 70 | +### Building From Source |
| 71 | + |
| 72 | + - Make sure you have golang installed |
| 73 | + - Run the following command: |
| 74 | + |
| 75 | +``` |
| 76 | +go build -o nuru main.go |
| 77 | +``` |
| 78 | + - You can optionally add the binary to $PATH as shown above |
| 79 | + - Confirm installtion with: |
| 80 | + |
| 81 | +``` |
| 82 | +nuru -v |
| 83 | +``` |
| 84 | + |
| 85 | +## Syntax |
| 86 | + |
| 87 | +Nuru, although still in its early stage, intends to be a fully functional programming language, and thus it has been baked with many features. |
| 88 | + |
| 89 | +### Defining A Variable |
| 90 | + |
| 91 | +To initiliaze a variable use the `acha` keyword: |
| 92 | + |
| 93 | +``` |
| 94 | +acha x = 2; |
| 95 | +acha y = 3; |
| 96 | +
|
| 97 | +andika(x*y) // output is 6 |
| 98 | +``` |
| 99 | +You can reassign values to the variable after it has been initiliazed: |
| 100 | + |
| 101 | +``` |
| 102 | +x = 10 |
| 103 | +
|
| 104 | +andika(x*y) // output is 30 |
| 105 | +``` |
| 106 | +**Note that Semicolons ";" are OPTIONAL** |
| 107 | + |
| 108 | +### Comments |
| 109 | + |
| 110 | +Nuru supports both single line and multiple line comments as shown below: |
| 111 | + |
| 112 | +``` |
| 113 | +// Single line comment |
| 114 | +
|
| 115 | +/* |
| 116 | +
|
| 117 | +Multiple |
| 118 | +Line |
| 119 | +Comment |
| 120 | +*/ |
| 121 | +``` |
| 122 | + |
| 123 | +### Arithmetic Operations |
| 124 | + |
| 125 | +For now Nuru supports `+`, `-`, `/` and `*`. More will be added. The `/` operation will truncate (round to a whole number) as Floating points are not supported yet. |
| 126 | + |
| 127 | +Nuru also provides precedence of operations using the BODMAS rule: |
| 128 | + |
| 129 | +``` |
| 130 | +2 + 2 * 3 // output = 8 |
| 131 | +
|
| 132 | +2 * (2 + 3) // output = 10 |
| 133 | +``` |
| 134 | + |
| 135 | +### Types |
| 136 | + |
| 137 | +Nuru has the following types: |
| 138 | + |
| 139 | +Type | Syntax | Comments |
| 140 | +--------- | ----------------------------------------- | ----------------------- |
| 141 | +BOOL | `kweli sikweli` | kweli == true, sikweli false |
| 142 | +INT | `1, 100, 342, -4 | These are signed 64 bit integers |
| 143 | +STRING | `"" "mambo" "habari yako"` | They MUST be in DOUBLE QUOTES `"` |
| 144 | +ARRAY | `[] [1, 2, 3] [1, "moja", kweli, ]` | Arrays can hold any types |
| 145 | +DICT | `{} {"a": 3, 1: "moja", kweli: 2}` | Keys can be int, string or bool |
| 146 | + |
| 147 | +### Functions |
| 148 | + |
| 149 | +This is how you define a function in Nuru: |
| 150 | + |
| 151 | +``` |
| 152 | +acha jumlisha = fn(x, y) { |
| 153 | + rudisha x + y |
| 154 | + } |
| 155 | +
|
| 156 | +andika(jumlisha(3,4)) |
| 157 | +``` |
| 158 | + |
| 159 | +Nuru also supports recursion: |
| 160 | + |
| 161 | +``` |
| 162 | +acha fibo = fn(x) { |
| 163 | + kama (x == 0) { |
| 164 | + rudisha 0; |
| 165 | + } au kama (x == 1) { |
| 166 | + rudisha 1; |
| 167 | + } sivyo { |
| 168 | + rudisha fibo(x - 1) + fibo(x - 2); |
| 169 | + } |
| 170 | +} |
| 171 | +``` |
| 172 | + |
| 173 | +### If Statements |
| 174 | + |
| 175 | +Nuru supports if, elif and else statements with keywords `kama`, `au kama` and `sivyo` respectively: |
| 176 | + |
| 177 | +``` |
| 178 | +kama (2<1) { |
| 179 | + andika("Mbili ni ndogo kuliko moja") |
| 180 | +} au kama (3 < 1) { |
| 181 | + andika ("Tatu ni ndogo kuliko moja") |
| 182 | +} sivyo { |
| 183 | + andika("Moja ni ndogo") |
| 184 | +} |
| 185 | +``` |
| 186 | + |
| 187 | +### While Loops |
| 188 | + |
| 189 | +Nuru's while loop syntax is as follows: |
| 190 | + |
| 191 | +``` |
| 192 | +acha i = 10 |
| 193 | +
|
| 194 | +wakati (i > 0) { |
| 195 | + andika(i) |
| 196 | + i = i - 1 |
| 197 | +} |
| 198 | +``` |
| 199 | + |
| 200 | +### Arrays |
| 201 | + |
| 202 | +This is how you initiliaze and perform other array operations in Nuru: |
| 203 | +``` |
| 204 | +acha arr = [] |
| 205 | +
|
| 206 | +// To add elements |
| 207 | +
|
| 208 | +sukuma(arr, 2) |
| 209 | +andika(arr) // output = [2] |
| 210 | +// Add two Arrays |
| 211 | +
|
| 212 | +acha arr2 = [1,2,3,4] |
| 213 | +
|
| 214 | +acha arr3 = arr1 + arr2 |
| 215 | +
|
| 216 | +andika(arr3) // output = [2,1,2,3,4] |
| 217 | +
|
| 218 | +// reassign value |
| 219 | +
|
| 220 | +arr3[0] = 0 |
| 221 | +
|
| 222 | +andika[arr3] // output = [0,1,2,3,4] |
| 223 | +
|
| 224 | +// get specific item |
| 225 | +
|
| 226 | +andika(arr[3]) // output = 3 |
| 227 | +``` |
| 228 | + |
| 229 | +### Dictionaries |
| 230 | + |
| 231 | +Nuru also supports dictionaris and you can do a lot with them as follows: |
| 232 | +``` |
| 233 | +acha mtu = {"jina": "Mojo", "kabila": "Mnyakusa"} |
| 234 | +
|
| 235 | +// get value from key |
| 236 | +andika(mtu["jina"]) // output = Mojo |
| 237 | +
|
| 238 | +andika(mtu["kabila"]); // output = Mnyakusa |
| 239 | +
|
| 240 | +// You can reassign values |
| 241 | +
|
| 242 | +mtu["jina"] = "Avicenna" |
| 243 | +
|
| 244 | +andika(mtu["jina"]) // output = Avicenna |
| 245 | +
|
| 246 | +// You can also add new values like this: |
| 247 | +
|
| 248 | +mtu["anapoishi"] = "Dar Es Salaam" |
| 249 | +
|
| 250 | +andika(mtu) // output = {"jina": "Avicenna", "kabila": "Mnyakusa", "anapoishi": "Dar Es Salaam"} |
| 251 | +
|
| 252 | +// You can also add two Dictionaries |
| 253 | +
|
| 254 | +acha kazi = {"kazi": "jambazi"} |
| 255 | +
|
| 256 | +mtu = mtu + kazi |
| 257 | +
|
| 258 | +andika(mtu) // output = {"jina": "Avicenna", "kabila": "Mnyakusa", "anapoishi": "Dar Es Salaam", "kazi": "jambazi"} |
| 259 | +``` |
| 260 | + |
| 261 | +### Getting Input From User |
| 262 | + |
| 263 | +In Nuru you can get input from users using the `jaza()` keyword as follows: |
| 264 | +``` |
| 265 | +acha jina = jaza("Unaitwa nani? ") // will prompt for input |
| 266 | +
|
| 267 | +andika("Habari yako " + jina) |
| 268 | +``` |
| 269 | + |
| 270 | +## How To Run |
| 271 | + |
| 272 | +### Using The Intepreter: |
| 273 | + |
| 274 | +You can enter the intepreter by simply running the `nuru` command: |
| 275 | +``` |
| 276 | +nuru |
| 277 | +>>> andika("karibu") |
| 278 | +karibu |
| 279 | +>>> 2 + 2 |
| 280 | +4 |
| 281 | +``` |
| 282 | +**Kindly Note that everything should be placed in a single line, separated by a semicolon.** |
| 283 | + |
| 284 | +### Running From File |
| 285 | + |
| 286 | +To run a Nuru script, write the `nuru` command followed by the name of the file with a `.nr` extension: |
| 287 | + |
| 288 | +``` |
| 289 | +nuru myFile.nr |
| 290 | +``` |
| 291 | + |
| 292 | +## Contributions |
| 293 | + |
| 294 | +All contributions are welcomed. Clone the repo, hack it, make sure all tests are passing then submit a pull request. |
| 295 | + |
| 296 | +## License |
| 297 | + |
| 298 | +[MIT](http://opensource.org/licenses/MIT) |
| 299 | + |
| 300 | +## Authors |
| 301 | + |
| 302 | +Nuru Programming Language has been authored and being actively maintained by [Avicenna](https://github.com/AvicennaJr) |
0 commit comments