├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── ccpp.yml ├── .gitignore ├── .vscode ├── launch.json └── tasks.json ├── CMakeLists.txt ├── LICENSE ├── PULL_REQUEST_TEMPLATE.md ├── README.md ├── SECURITY.md ├── build-scripts ├── docs.sts ├── finished.sts ├── helloworld.sts ├── install.sh ├── installmac.sh └── uninstall.sh ├── build ├── build.sh ├── crossplatbuild.sh └── mingw32_toolchain.cmake ├── docs ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── building.md ├── changelogs │ ├── changelog-v0.2.0.md │ ├── changelog-v0.3.0.md │ ├── changelog-v0.4.0.md │ ├── changelog-v0.5.0.md │ ├── changelog-v0.6.0.md │ ├── changelog-v0.7.0.md │ ├── changelog-v1.0.0.md │ └── changelog-v1.1.0.md ├── development │ ├── style.md │ ├── testing.md │ └── the_parser.md └── readme.md ├── example └── example.sts ├── images └── logo.png ├── scripts ├── packagerelease.sh ├── runtests.sh └── writenewouts.sh ├── src ├── StormScriptconfig.h ├── errors.cc ├── errors.sts ├── interpreter │ ├── interpret.cc │ ├── loops.cc │ ├── newscope.cc │ └── sts_interpreter.h ├── networking │ ├── networking.h │ └── stsSocket.cc ├── operations.cc ├── parser │ ├── eval.cc │ ├── modules.cc │ ├── parse.cc │ ├── parseerrors.cc │ ├── read.cc │ └── sts_parser.h ├── scripts │ └── update.py ├── stormscript.cc ├── stormscript.h ├── stream │ ├── files.cc │ ├── io.cc │ └── sts_stream.h ├── sts_files.h ├── type │ ├── objectmember.cc │ ├── sts_type.h │ └── type.cc └── values │ ├── compare.cc │ ├── find.cc │ ├── getvals.cc │ ├── if.cc │ ├── random.cc │ ├── runfunc.cc │ ├── sts_values.h │ └── stsdec.cc └── tests ├── argtest.sts ├── classtest.sts ├── comptest.sts ├── comptest2.sts ├── concattest.sts ├── errortest.sts ├── etc ├── example.txt ├── readtest.txt └── testmod.sts ├── foreachtest.sts ├── forlooptest.sts ├── lengthtest.sts ├── littest.sts ├── mathtest.sts ├── modtest.sts ├── outputs ├── argtest.sts.txt ├── classtest.sts.txt ├── comptest.sts.txt ├── comptest2.sts.txt ├── concattest.sts.txt ├── errortest.sts.txt ├── foreachtest.sts.txt ├── forlooptest.sts.txt ├── lengthtest.sts.txt ├── littest.sts.txt ├── mathtest.sts.txt ├── modtest.sts.txt ├── printtest.sts.txt ├── privatemembers.sts.txt ├── readtest.sts.txt ├── returntest.sts.txt ├── whiletest.sts.txt └── writetest.sts.txt ├── printtest.sts ├── privatemembers.sts ├── readtest.sts ├── returntest.sts ├── whiletest.sts └── writetest.sts /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | Give OS name and version, StormScript version, where you installed it from, and your code and how you ran it. 13 | 14 | **Expected behavior** 15 | A clear and concise description of what you expected to happen. 16 | 17 | **Additional context** 18 | Add any other context about the problem here. 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. Give explanation of why this feature would be important. 15 | -------------------------------------------------------------------------------- /.github/workflows/ccpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | - 1.0 8 | pull_request: 9 | branches: 10 | - master 11 | - 1.0 12 | 13 | jobs: 14 | build_linux: 15 | 16 | runs-on: ubuntu-latest 17 | 18 | steps: 19 | - uses: actions/checkout@v1 20 | - name: Build 21 | run: | 22 | cd build; 23 | sudo ./build.sh --prefix /usr 24 | - name: Test 25 | run: | 26 | cd scripts; 27 | ./runtests.sh 28 | 29 | 30 | build_win: 31 | runs-on: windows-latest 32 | 33 | steps: 34 | - uses: actions/checkout@v1 35 | - name: Configure 36 | run: cmake . -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" -DCMAKE_CXX_COMPILER=g++ -DCMAKE_C_COMPILER=gcc 37 | - name: Make 38 | run: mingw32-make 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/settings.json 2 | .vscode/c_cpp_properties.json 3 | .vscode/ipch 4 | release/ 5 | CMakeFiles/ 6 | CMakeCache.txt 7 | cmake_install.cmake 8 | Makefile 9 | *.ninja 10 | .ninja_deps 11 | .ninja_log 12 | build/stormscript 13 | 14 | *.code-workspace 15 | 16 | compile_commands.json 17 | 18 | *.exe 19 | *.tar* 20 | *.zip 21 | *.log 22 | *.pyc 23 | 24 | snap/.snapcraft/ 25 | snap/parts/ 26 | snap/prime/ 27 | snap/stage/ 28 | snap/snap/ 29 | *.snap 30 | libraries/*/reader.cc 31 | *.xdelta3 -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "(gdb) Launch", 9 | "type": "cppdbg", 10 | "request": "launch", 11 | "program": "${command:cmake.launchTargetPath}", 12 | "args": [ 13 | "example.sts" 14 | ], 15 | "stopAtEntry": false, 16 | "cwd": "${workspaceFolder}/example", 17 | "externalConsole": false, 18 | "MIMode": "gdb", 19 | "setupCommands": [ 20 | { 21 | "description": "Enable pretty-printing for gdb", 22 | "text": "-enable-pretty-printing", 23 | "ignoreFailures": true 24 | } 25 | ] 26 | }, 27 | { 28 | "name": "(gdb) Attach", 29 | "type": "cppdbg", 30 | "request": "attach", 31 | "program": "${workspaceFolder}/build/stormscript", 32 | "processId": "${command:pickProcess}", 33 | "MIMode": "gdb", 34 | "setupCommands": [ 35 | { 36 | "description": "Enable pretty-printing for gdb", 37 | "text": "-enable-pretty-printing", 38 | "ignoreFailures": true 39 | } 40 | ] 41 | }, 42 | { 43 | "name": "No Commands", 44 | "type": "cppdbg", 45 | "request": "launch", 46 | "preLaunchTask": "Move Scripts", 47 | "program": "${command:cmake.launchTargetPath}", 48 | "args": [ 49 | "--help" 50 | ], 51 | "stopAtEntry": false, 52 | "cwd": "${workspaceFolder}", 53 | "externalConsole": false, 54 | "MIMode": "gdb", 55 | "setupCommands": [ 56 | { 57 | "description": "Enable pretty-printing for gdb", 58 | "text": "-enable-pretty-printing", 59 | "ignoreFailures": true 60 | } 61 | ] 62 | }, 63 | { 64 | "name": "(gdb) Launch on Windows", 65 | "type": "cppdbg", 66 | "request": "launch", 67 | "program": "${command:cmake.launchTargetPath}", 68 | "args": [ 69 | "example.sts", 70 | ], 71 | "stopAtEntry": false, 72 | "cwd": "${workspaceFolder}/example", 73 | "externalConsole": false, 74 | "MIMode": "gdb", 75 | "miDebuggerPath": "gdb.exe", 76 | "setupCommands": [ 77 | { 78 | "description": "Enable pretty-printing for gdb", 79 | "text": "-enable-pretty-printing", 80 | "ignoreFailures": true 81 | } 82 | ] 83 | } 84 | ] 85 | } 86 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=733558 3 | // for the documentation about the tasks.json format 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "label": "Move Scripts", 8 | "type": "shell", 9 | "command": "sudo cp src/errors.sts /usr/share/stormscript; sudo cp src/scripts/update.py /usr/share/stormscript", 10 | "problemMatcher": [] 11 | } 12 | ] 13 | } -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.6) 2 | project (StormScript) 3 | set (CMAKE_CXX_STANDARD 17) 4 | set (CMAKE_CXX_STANDARD_REQUIRED on) 5 | set (CMAKE_CXX_EXTENSIONS off) 6 | 7 | if (MINGW) 8 | set (CMAKE_CXX_FLAGS "-static -static-libgcc -static-libstdc++") 9 | else() 10 | set (CMAKE_CXX_COMPILER "g++") 11 | endif (MINGW) 12 | 13 | add_executable(stormscript 14 | src/stormscript.cc 15 | src/operations.cc 16 | src/errors.cc 17 | src/interpreter/interpret.cc 18 | src/interpreter/newscope.cc 19 | src/interpreter/loops.cc 20 | src/networking/stsSocket.cc 21 | src/parser/parse.cc 22 | src/parser/read.cc 23 | src/parser/eval.cc 24 | src/parser/parseerrors.cc 25 | src/parser/modules.cc 26 | src/stream/io.cc 27 | src/stream/files.cc 28 | src/type/type.cc 29 | src/type/objectmember.cc 30 | src/values/stsdec.cc 31 | src/values/if.cc 32 | src/values/find.cc 33 | src/values/getvals.cc 34 | src/values/runfunc.cc 35 | src/values/compare.cc 36 | src/values/random.cc 37 | ) 38 | 39 | if (MINGW) 40 | target_link_libraries(stormscript wsock32 ws2_32) 41 | endif (MINGW) 42 | 43 | set (StormScript_VERSION_MAJOR 1) 44 | set (StormScript_VERSION_MINOR 0) 45 | install(TARGETS stormscript RUNTIME DESTINATION bin/) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Provide the feature name, what it does, why you added it and why it is important. 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](images/logo.png) 2 | 3 | ![GitHub (pre-)release](https://img.shields.io/github/release-pre/stormprograms/stormscript.svg) 4 | ![GitHub All Releases](https://img.shields.io/github/downloads/stormprograms/stormscript/total.svg) 5 | 6 | ![Visual Studio Marketplace Installs - Azure DevOps Extension](https://img.shields.io/visual-studio-marketplace/azure-devops/installs/total/stormprograms.stormscript.svg) 7 | 8 | ![GitHub repo size in bytes](https://img.shields.io/github/repo-size/stormprograms/stormscript.svg) 9 | 10 | [![Total alerts](https://img.shields.io/lgtm/alerts/g/stormprograms/StormScript.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/stormprograms/StormScript/alerts/) 11 | [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/stormprograms/StormScript.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/stormprograms/StormScript/context:cpp) 12 | 13 | StormScript is a programming language made in C++ 14 | 15 | Read [building.md](docs/building.md) for info on how to build 16 | 17 | [View StormScript Website](https://stormscript.dev) 18 | 19 | [Documentation](https://stormprograms.com/stormscript) 20 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | | Version | Supported | 6 | | ------- | ------------------ | 7 | | 1.0.x | :white_check_mark: | 8 | | 0.x.0 | :x: | 9 | 10 | Beta versions are always supported. Any version below 1.0.0 is out of date. 11 | 12 | ## Reporting a Vulnerability 13 | 14 | Report a vulnerability in the issues tab. Depening on the severity of the vulnerability, it will either be patched in the next update, or as soon as possible. 15 | -------------------------------------------------------------------------------- /build-scripts/docs.sts: -------------------------------------------------------------------------------- 1 | sys "sensible-browser https://stormprograms.com/stormscript"; -------------------------------------------------------------------------------- /build-scripts/finished.sts: -------------------------------------------------------------------------------- 1 | printl; 2 | printl "Successfully installed."; 3 | printl; 4 | printl; 5 | printl "Read the docs at https://stormprograms.com/stormscript/docs."; 6 | printl "On Debian-based OSes, type 'stormscript docs.sts' to open this page in you default browser"; 7 | printl; 8 | printl "Type 'stormscript helloworld.sts' to run the hello world program."; -------------------------------------------------------------------------------- /build-scripts/helloworld.sts: -------------------------------------------------------------------------------- 1 | printl "Hello, World!"; -------------------------------------------------------------------------------- /build-scripts/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cmake CMakeLists.txt -DCMAKE_CXX_COMPILER:STRING="g++" 3 | make -j $(nproc) 4 | 5 | 6 | # build only arg does not install 7 | if [ ! "$1" = "--prefix" ]; then 8 | echo "Expected prefix argument." 9 | exit 1; 10 | else 11 | if [ ! -e "/usr/share/stormscript" ]; then 12 | mkdir $2/share/stormscript 13 | fi 14 | 15 | cp stormscript $2/bin 16 | cp src/errors.sts $2/share/stormscript 17 | cp src/scripts/update.py $2/share/stormscript 18 | fi 19 | 20 | $2/stormscript finished.sts -------------------------------------------------------------------------------- /build-scripts/installmac.sh: -------------------------------------------------------------------------------- 1 | brew install cmake 2 | cmake . 3 | make -j $(nproc) 4 | cp src/errors.sts . 5 | touch ~/.profile 6 | echo "export PATH="`pwd`":\$PATH" >> ~/.profile 7 | source ~/.profile 8 | -------------------------------------------------------------------------------- /build-scripts/uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo rm /usr/bin/stormscript 3 | sudo rm -rf /usr/share/stormscript 4 | echo StormScript Removed -------------------------------------------------------------------------------- /build/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! "$1" = "--prefix" ]; then 4 | echo "Expected prefix argument." 5 | exit 1; 6 | else 7 | rm -rf ./CMakeFiles 8 | rm -rf CMakeCache.txt 9 | rm Makefile 10 | 11 | cmake .. 12 | make -j $(nproc) 13 | 14 | if [ ! -e "$2/bin" ]; then 15 | mkdir $2/bin 16 | fi 17 | 18 | if [ ! -e "$2/share/stormscript" ]; then 19 | mkdir -p $2/share/stormscript 20 | fi 21 | 22 | cp stormscript $2/bin 23 | sudo cp ../src/errors.sts $2/share/stormscript 24 | sudo cp ../src/scripts/update.py $2/share/stormscript 25 | fi -------------------------------------------------------------------------------- /build/crossplatbuild.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | # This is to build and run example.sts on linux using wine 3 | # in order to run this file, you must have your system's 4 | # wine and mingw-w64 packages 5 | 6 | rm -rf ./CMakeFiles 7 | rm -rf CMakeCache.txt 8 | rm Makefile 9 | 10 | if [ ! -e /usr/share/stormscript ]; then 11 | sudo mkdir /usr/share/stormscript 12 | fi 13 | 14 | sudo cp ../src/errors.sts /usr/share/stormscript 15 | 16 | cmake -DCMAKE_TOOLCHAIN_FILE=mingw32_toolchain.cmake .. 17 | make -j $(nproc) 18 | 19 | if [ "$1" = "test" ]; then 20 | wine stormscript.exe ../example/example.sts 21 | fi -------------------------------------------------------------------------------- /build/mingw32_toolchain.cmake: -------------------------------------------------------------------------------- 1 | set (CMAKE_SYSTEM_NAME Windows) 2 | 3 | set (COMPILER_PREFIX "x86_64-w64-mingw32") 4 | 5 | set (CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc) 6 | set (CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-g++) 7 | set (CMAKE_RC_COMPILER ${COMPILER_PREFIX}-windres) -------------------------------------------------------------------------------- /docs/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | * Insulting the formatting of other's code. 25 | 26 | ## Our Responsibilities 27 | 28 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 29 | 30 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 31 | 32 | ## Scope 33 | 34 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 35 | 36 | ## Enforcement 37 | 38 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at storm@stormprograms.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 39 | 40 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 41 | 42 | ## Attribution 43 | 44 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 45 | 46 | [homepage]: http://contributor-covenant.org 47 | [version]: http://contributor-covenant.org/version/1/4/ 48 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidlines 2 | 3 | ## FORMATTING RULES 4 | 5 | For now I am not too concerned about how pretty code is as long as it is functional. That said, it is prefered that you don't make it a nightmare to read. Create a new branch with the name of the feature to add new features, and be sure to check that someone isn't already working on said feature. Create new files to add new commands, with the only exceptions being global commands (such as `lib`, `glob`, and `func`). Also, when you test your new feature use the provided `example.sts` file. This will make it easier to make sure you actually tested thoroughly. 6 | 7 | ## Behavior 8 | 9 | ### What you should do 10 | 11 | * provide constructive feedback 12 | * write original code 13 | * report issues 14 | 15 | ### What you should not do 16 | 17 | * Insult others' work 18 | * Insult others in general 19 | 20 | ## tldr 21 | 22 | ### Formatting: 23 | 24 | 1. Write functional code 25 | 2. create new branches to add features. 26 | 3. Create new files for new non-global namespace commands 27 | 4. Test your features using `example.sts`. 28 | 29 | ### Behavior 30 | 31 | * Don't be a jerk 32 | -------------------------------------------------------------------------------- /docs/building.md: -------------------------------------------------------------------------------- 1 | # Building StormScript 2 | 3 | Make a directory called build 4 | 5 | **You must have gcc-8/g++-8 installed (MinGW for Windows) and CMake** 6 | 7 | GDB is also highly recommended for debugging 8 | 9 | ## Linux 10 | 11 | Terminal: 12 | ```sh 13 | cd build 14 | ./build.sh --prefix /DIRECTORY 15 | ``` 16 | 17 | Set prefix to /usr to add to PATH 18 | 19 | ## Windows 20 | 21 | Make sure you have MinGW and CMake installed (in PATH) 22 | run `cmake -G "MinGW Makefiles"` 23 | then run `mingw32-make` 24 | 25 | also make sure that you have src/core in PATH for errors to work 26 | 27 | ## Visual Studio Code 28 | 29 | Press `Build:` in the bottom left or press `f5` to start debugging (if GDB is installed). 30 | 31 | When it builds, it should be put into a `build/` directory. 32 | 33 | if you are on windows, use the debug profile "(gdb) launch on windows" -------------------------------------------------------------------------------- /docs/changelogs/changelog-v0.2.0.md: -------------------------------------------------------------------------------- 1 | # StormScript v0.2.0 "Banana" 2 | 3 | ## What's New: 4 | * You can change items in lists with `list[item]: "value";` 5 | * Changelog 6 | * Parser and interpreter split up into more files 7 | * Installer now uses the regular cmake file for the project which is located in the release's src directory 8 | * StormScript library written in StormScript 9 | * [runtests.sh](runtests.sh) now only shows which tests failed 10 | * Outputs folder for expected test results 11 | * [writenewouts.sh](writenewouts.sh) generates results to be put in the outputs folder 12 | * class methods can now be declared. [C++ file](/classes/decmethod.cpp) 13 | * Removed `end;` from being used at the end of scopes 14 | * Function arguments are declared with `func foo => int arg {` instead of `@args: int arg;` 15 | 16 | ## What's Fixed 17 | * Global variables no longer reset for every iteration of a loop 18 | * Fixed issue where installer could find `src/libraries/system/stormscript` 19 | * Fixed issue where library function couldn't be run in print without args. 20 | 21 | ## Other 22 | * Renamed sts.cpp to [stormscript.cpp](/core/stormscript.cpp) 23 | * Made [interpreter](/interpreter/exec/cpp) easier to use 24 | * Moved reader from [stormscript.cpp](/core/stormscript.cpp) to [read.cpp](/parser/read.cpp) -------------------------------------------------------------------------------- /docs/changelogs/changelog-v0.3.0.md: -------------------------------------------------------------------------------- 1 | # StormScript v0.3.0 "Cantaloupe" 2 | 3 | ## What's New 4 | * Modules allow users to run functions from other files. For example, use module `filename.sts` with `mod filename` 5 | * Made `src` dir 6 | * `less`, `greater`, `lesseq`, and `greatereq` operators 7 | * get length of string with `string|length` 8 | * Get index of string with `string[n]` 9 | * Change list with `mylist: ["these", "are", "new", "items"]` 10 | * Remove required `glob` in front of global variable declarations 11 | * Users are now warned about errors in the global scope 12 | * String values can be used as ints. 13 | * math operations for adding, subtracting, multiplying, and dividing. 14 | * comments can be added with `#comment` 15 | 16 | ## What's Fixed 17 | * Returns could only return variables, changed it to use new getvars function. 18 | * `pop_back()` was run on `prs` causing the vector of the parsed version of the program to lose characters on each loop iteration 19 | * Negative integers were saved as strings 20 | * `sys` command would quit if any variables that are not strings were declared before. -------------------------------------------------------------------------------- /docs/changelogs/changelog-v0.4.0.md: -------------------------------------------------------------------------------- 1 | # StormScript v0.4.0 "Dragon Fruit" 2 | 3 | ## What's New: 4 | * Ternary Operation for assigning values based on booleans 5 | * Moved comparison operations to new function 6 | * Booleans can be set to comparisons. 7 | * [packagerelease.sh](/packagerelease.sh) now requires all tests to pass successfully in order to package for release 8 | * Split stsclasses.h into multiple files in an include dir 9 | * Started using azure pipelines for build automation 10 | * Switched to dynamic typing 11 | * Switched to c++17 12 | 13 | ## What's Fixed: 14 | * Switched to `.cc` file extension rather than `.cpp` -------------------------------------------------------------------------------- /docs/changelogs/changelog-v0.5.0.md: -------------------------------------------------------------------------------- 1 | # StormScript v0.5.0 "Eggplant" 2 | 3 | ## What's New 4 | * `while` can be used to make while loops 5 | * New Escape Characters, `\t` and `\\` 6 | * Windows version 7 | * Modules have been removed due to compatibility issues 8 | * Libraries have been removed due to compatibility issues 9 | * New scripts folder for build scripts 10 | 11 | ## What's Fixed 12 | * `runtests.sh` will now exit with code 1 on failure -------------------------------------------------------------------------------- /docs/changelogs/changelog-v0.6.0.md: -------------------------------------------------------------------------------- 1 | # StormScript v0.6.0 "Fig" 2 | 3 | ## What's new 4 | * StormScript can now read and write to files 5 | * StormScript now has modules, which allow you to run functions from other StormScript files. 6 | * use `random` to generate a random bool 7 | * use `randomrange => min, max;` to generate a random integer in range min, max 8 | * use `wait INT` to sleep for `INT` seconds 9 | 10 | ## What's Fixed 11 | * else and else if statements were broken 12 | * length didn't work when used in function inside args 13 | * while loops would cause the parser to increase the current line to the point where it was outside of the scope. 14 | * Functions run at the end of other functions caused segmentation faults due to failing to parse a semicolon 15 | * Global variables couldn't be declared 16 | * comparisons using subscripts were broken 17 | * length did not change on modification 18 | * `stsvars::glob` was considered to be true by some compilers, causing crash 19 | -------------------------------------------------------------------------------- /docs/changelogs/changelog-v0.7.0.md: -------------------------------------------------------------------------------- 1 | # StormScript v0.7.0 "Grape" 2 | 3 | ## What's New 4 | * Mac install script 5 | * Class constructors with the `def` keyword 6 | * errors moved to `errors.sts` from `core/errors.cc` 7 | * you can now modify specific characters in a string or specific characters in a list using subscripts 8 | * use `stormscript install modname` to install official module by name of modname 9 | * define a function and declare it later with forward declaration 10 | 11 | ## What's Fixed 12 | * Version would only show at top if StormScript was running from PATH 13 | * Print function would crash when printing lists with subscripts 14 | * fixed issue with chains of else if blocks causing the parser to go over the number of objects in program vector 15 | * Parser no longer keeps whitespace -------------------------------------------------------------------------------- /docs/changelogs/changelog-v1.0.0.md: -------------------------------------------------------------------------------- 1 | # StormScript v1.0.0 2 | 3 | ## What's New 4 | * Use the `$` symbol followed by a variable name inside of a string literal to concatenate that variable into the string 5 | * `for INT` runs a for loop starting at 0 and ending on INT 6 | * `do` is no longer required 7 | * rewrote interpreter to use switch statements 8 | * using enumerations to determine statements rather than string literal 9 | * functions can be declared in any scope 10 | * moved errors.sts from /usr/bin to /usr/share/stormscript 11 | * Function arguments no longer require you to specify the name 12 | * `for PLACEHOLDER in LIST/STR` creates a foreach loop 13 | * `randomrange and rand` now uses Mersenne Twister generation rather than cpp `rand()` function 14 | * added `break` for loops 15 | * errors are now parsed before runtime 16 | * modules are added to the file before runtime 17 | * modules are now scoped 18 | * `def` has been changed to a scope called `init` 19 | * sockets can be created with `socket name => "FAMILY", "127.0.0.1", 9999` 20 | 21 | ## What's Fixed 22 | * Removed snapcraft files 23 | * Variables can be used in the filenames in the `read` and `write` commands 24 | * StormScript doesn't mess up when if statements are nested 25 | * boolean variables and literals now work in `if` statements 26 | * Comparisons always work out to booleans, meaning that they are now interchangeable 27 | * Random no longer generates integers outside of range 28 | * Scoped variable inheritance now works, so variables defined inside of a scope are accessible to the scope and any child scopes 29 | * Install script now uses all available processor cores 30 | * packagerelease.sh now installs stormscript to run tests 31 | * Better development documentation 32 | * The `|` operator is now `.` 33 | * scopes now work as a class, making development around scopes easier 34 | * constructors now use the arrow operator (`=>`) to declare constructors 35 | * using tabs instead of spaces 36 | * moved contents out of src/core and into root of src directory 37 | * fixed class member comparisons -------------------------------------------------------------------------------- /docs/changelogs/changelog-v1.1.0.md: -------------------------------------------------------------------------------- 1 | # StormScript v1.1.0 2 | 3 | ## What's New 4 | * run `$ stormscript update` on linux to download the latest version. 5 | * Switched to using value for stsvars class rather than char. 6 | * Add `private` before member declaration to make a member private 7 | * Allow installation anywhere 8 | 9 | ## What's fixed 10 | * Removed unneeded functions from `src/parser/eval.cc` to make evaluation faster -------------------------------------------------------------------------------- /docs/development/style.md: -------------------------------------------------------------------------------- 1 | # Style 2 | 3 | ## Table of Contents 4 | 5 | * [Info](#info) 6 | * [Commenting](#commenting) 7 | * [C++ Style](#c++-style) 8 | * [StormScript Style](#stormscript-style) 9 | 10 | # Info 11 | I mainly created this code as a guide and less of a "law" because I feel that it is important to have readable code, but not to stress it so much as to deter newcomers. I sometimes will forget to follow this style guide, and if you do as long as your code is readable I will accept it. That said, I want you to try to use this style guide as much as you can for the sake of time. If I forget to follow this somewhere, feel free to create a PR that cleans up my code. 12 | 13 | # Commenting 14 | 15 | This should go without saying, but please comment on your code. I love reading code, but I also want to know what it does. ;) 16 | 17 | # C++ Style 18 | C++ has the strictest rules when it comes to styling as it makes up the majority of the project. 19 | 20 | ## Indention 21 | Use the `\t` character 22 | 23 | ## Includes 24 | **YOU MUST FOLLOW THIS** 25 | 26 | All includes must go at the top of [includes.h](/src/include/includes.h). 27 | 28 | All C++ source files must include src/include/stormscript.h 29 | 30 | ## Scopes 31 | 32 | If a scope only contains 1 line of code, put it on the same line as the condition that creates it without curly brackets 33 | 34 | For example: 35 | 36 | ```cpp 37 | if (expressions[*y].t == ENDEXPR) *y += 1; 38 | ``` 39 | or 40 | ```cpp 41 | if (expressions[*y].t == ENDEXPR) 42 | *y += 1; 43 | ``` 44 | 45 | Otherwise, curly braces go 1 space in front of scope defining statement. 46 | 47 | ```cpp 48 | switch (expressions[*y].t) { 49 | ... 50 | } 51 | ``` 52 | 53 | 54 | ## If statements and Switches 55 | 56 | If you are dealing with enumerations, integers, or characters, you should use switch statements otherwise use if statements. 57 | 58 | # StormScript Style 59 | 60 | ## Parentheses 61 | 62 | Parentheses in StormScript are completely optional. However, in this project, please use parentheses around conditional operators -------------------------------------------------------------------------------- /docs/development/testing.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | 3 | ## How often should new tests be added? 4 | When you are adding new features (not patches) tests should be added. 5 | 6 | ## How can I generate outputs? 7 | Run `scripts/writenewouts.sh` 8 | 9 | ## How can I run tests? 10 | Run `scripts/runtests.sh` -------------------------------------------------------------------------------- /docs/development/the_parser.md: -------------------------------------------------------------------------------- 1 | # The Parser 2 | 3 | ## Evaluation 4 | 5 | One of the main files in stormscript is the file [eval.cc](/src/interpreter/eval.cc). `eval.cc` is run directly after the file [parse.cc](/src/parser/parse.cc). 6 | 7 | Expressions are "sorted" into 5 different enumerations: 8 | 9 | `BUILTIN`: Built in functions 10 | 11 | `VALUE`: Any literal 12 | 13 | `UNKNOWN`: Could be an error, or user defined variables, functions, or classes 14 | 15 | `TOKEN`: Any symbol that isn't a semicolon 16 | 17 | `ENDEXPR`: A semicolon 18 | 19 | ## Characters that are left out 20 | 21 | Needless to say, whitespace, comments, and empty newlines are left out of the parsed program as they serve no purpose to the actual execution of the program. 22 | 23 | Less obviously, parentheses are completely left out of the program (for now) because they currently would only change the look of the program -------------------------------------------------------------------------------- /docs/readme.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | StormScript is a lightweight, object oriented, fully interpreted programming language for every platform. 4 | 5 | The primary goal of stormscript is to allow fast execution of small programs. 6 | 7 | ## Syntax 8 | 9 | ## Keywords 10 | 11 | StormScript keywords are designed to be easily understandable, for example: 12 | 13 | `printl` and `print` print to the console with and without a newline respectively 14 | 15 | `in` takes input from stdin 16 | 17 | `read` reads files 18 | 19 | `func` declares a function 20 | 21 | ## Symbols 22 | 23 | StormScript symbols are designed to be familier to any C family programmer while still easy to understand for new programmers. -------------------------------------------------------------------------------- /example/example.sts: -------------------------------------------------------------------------------- 1 | type test { 2 | private int x; 3 | int y; 4 | 5 | init => startingx { 6 | x: startingx; 7 | y: x + 10; 8 | } 9 | } 10 | 11 | test t => 10; 12 | 13 | printl t.y; 14 | printl t.x; -------------------------------------------------------------------------------- /images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abbyonstott/StormScript/326ab0828f6011bfd82f3ce9454fd08729008802/images/logo.png -------------------------------------------------------------------------------- /scripts/packagerelease.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd .. 3 | rm -r release/* 4 | echo "What is the version number (Formatted M.m.p):" 5 | read vnum 6 | 7 | echo "Packaging stormscript v$vnum for release." 8 | 9 | cmake CMakeLists.txt -DCMAKE_CXX_COMPILER:STRING="g++" 10 | make -j $(nproc) 11 | sudo mv stormscript /usr/bin/stormscript 12 | 13 | if [ ! -e /usr/share/stormscript ]; then 14 | sudo mkdir /usr/share/stormscript 15 | fi; 16 | 17 | sudo cp src/core/errors.sts /usr/share/stormscript 18 | 19 | printf "\n" 20 | 21 | echo Running tests: 22 | cd tests 23 | printf "\n" 24 | 25 | B=0 26 | for i in $( ls | grep .sts ); do 27 | # put the expected output to test 28 | if [[ $(echo `cat outputs/$i.txt`) = "$(echo `stormscript $i`)" ]]; then 29 | echo $B: Test Successful 30 | else 31 | echo Test $B failed: 32 | echo expected$'\n'$(echo `cat outputs/$i.txt`)$'\n'got$'\n'$(echo `stormscript $i`) 33 | echo "Failed to package stormscript v$vnum" 34 | exit 1 35 | fi 36 | 37 | B=$(($B+1)) 38 | done 39 | 40 | cd .. 41 | 42 | echo "Moving files from src to release/stormscript_v$vnum" 43 | 44 | cd release 45 | 46 | mkdir stormscript_v$vnum 47 | cd stormscript_v$vnum 48 | 49 | cp ../../CMakeLists.txt . 50 | cp -r ../../src . 51 | cp ../../build-scripts/* . 52 | 53 | echo "Compressing folder stormscript_v$vnum." 54 | cd .. 55 | tar -cf stormscript_v$vnum.tar.xz stormscript_v$vnum 56 | 57 | echo "Successfully packaged stormscript_v$vnum.tar.xz" -------------------------------------------------------------------------------- /scripts/runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd .. 3 | cmake CMakeLists.txt 4 | make -j $(nproc) 5 | install stormscript build/stormscript 6 | rm stormscript 7 | printf "\n \n \n" 8 | 9 | printf "\n" 10 | 11 | echo Help: 12 | build/stormscript --help 13 | 14 | printf "\n" 15 | 16 | echo Version: 17 | build/stormscript --version 18 | 19 | printf "\n" 20 | 21 | echo Running tests: 22 | cd tests 23 | printf "\n" 24 | 25 | B=0 26 | for i in $( ls | grep .sts ); do 27 | # put the expected output to test 28 | if [[ $(echo `cat outputs/$i.txt`) = "$(echo `../build/stormscript $i`)" ]]; then 29 | echo $B: Test Successful 30 | else 31 | echo Test $B failed: 32 | echo expected$'\n'$(echo `cat outputs/$i.txt`)$'\n'got$'\n'$(echo `../build/stormscript $i`) 33 | exit 1 34 | fi 35 | 36 | B=$(($B+1)) 37 | done -------------------------------------------------------------------------------- /scripts/writenewouts.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd .. 3 | cmake CMakeLists.txt 4 | make -j $(nproc) 5 | install stormscript build/stormscript 6 | rm stormscript 7 | 8 | cd tests 9 | 10 | rm -r outputs/* 11 | 12 | for i in $(ls | grep .sts); do 13 | touch outputs/$i.txt 14 | echo $(../build/stormscript $i) > outputs/$i.txt 15 | done -------------------------------------------------------------------------------- /src/StormScriptconfig.h: -------------------------------------------------------------------------------- 1 | #define StormScript_VERSION_MAJOR @StormScript_VERSION_MAJOR@ 2 | #define StormScript_VERSION_MINOR @StormScript_VERSION_MAJOR@ -------------------------------------------------------------------------------- /src/errors.cc: -------------------------------------------------------------------------------- 1 | #include "stormscript.h" 2 | 3 | void error(int num, string issue) { 4 | // in order for errors to work stormscript has to be in PATH, but we can assume that it is installed to usr/bin 5 | string cmd; 6 | 7 | #if (PLATFORM) 8 | cmd = "stormscript errors.sts "; 9 | #else 10 | cmd = "stormscript /usr/share/stormscript/errors.sts "; 11 | #endif 12 | 13 | cmd += std::to_string(num); 14 | cmd += " "; 15 | cmd += issue; 16 | system(cmd.c_str()); 17 | exit(1); 18 | } -------------------------------------------------------------------------------- /src/errors.sts: -------------------------------------------------------------------------------- 1 | if arg[1] is "0" { 2 | printl "Error: failed to open ", arg[2], ". Couldn't find file"; 3 | } 4 | else if arg[1] is "1" { 5 | printl "Error: Missing expression ending token at end of line ", arg[2], "."; 6 | } 7 | else if arg[1] is "2" { 8 | printl "Error: ", arg[2], " is not the correct type"; 9 | } 10 | else if arg[1] is "3" { 11 | printl "Error: ", arg[2], " is not a recognized command"; 12 | } 13 | else if arg[1] is "4" { 14 | printl "Error: ", arg[2], " is out of range"; 15 | } 16 | else if arg[1] is "5" { 17 | printl "Error: Function ", arg[2], " requires arguments"; 18 | } 19 | else if arg[1] is "6" { 20 | printl "Error: break ouside loop"; 21 | } 22 | else if arg[1] is "7" { 23 | printl "Error: return outside function"; 24 | } 25 | else if arg[1] is "8" { 26 | printl "Error: Variable ", arg[2], " not found"; 27 | } 28 | else if arg[1] is "9" { 29 | printl "Error: Expected module name"; 30 | } 31 | else if arg[1] is "10" { 32 | printl "Error: Type ", arg[2], " has no constructor"; 33 | } 34 | else if arg[1] is "11" { 35 | printl "Error: Object requires name on line ", arg[2]; 36 | } 37 | else if arg[1] is "12" { 38 | printl "Error: In statement on line ", arg[2], "requires variable name"; 39 | } 40 | else if arg[1] is "13" { 41 | printl "Error: In statement expected variable name, got", arg[2], "instead"; 42 | } 43 | else if arg[1] is "14" { 44 | printl "Tried to access private member ", arg[2], " outside of type method"; 45 | } -------------------------------------------------------------------------------- /src/interpreter/interpret.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "../sts_files.h" 3 | #include "sts_interpreter.h" 4 | 5 | // specific headers 6 | #include "../parser/sts_parser.h" 7 | #include "../stream/sts_stream.h" 8 | #include "../values/sts_values.h" 9 | #include "../type/sts_type.h" 10 | #include "../networking/networking.h" 11 | 12 | void runBuiltin() { 13 | bool l; 14 | 15 | switch (program.expressions[program.loc].btn) { 16 | case PRINT: 17 | case PRINTL: 18 | l = (program.expressions[program.loc].btn == PRINTL); // if printl 19 | while (program.expressions[program.loc].t != ENDEXPR) { 20 | cout << print(); 21 | 22 | if (program.expressions[program.loc+1].tktype == COMMA) program.loc += 1; // we don't need to add 2 because print() automatically adds 1 to the line counter 23 | } 24 | 25 | if (l) cout << '\n'; 26 | break; 27 | case STSIN: 28 | program.thisScope.variables.push_back(in()); 29 | break; 30 | case IF: 31 | ifs(); 32 | break; 33 | case FUNCTION: 34 | declareFunc(); 35 | break; 36 | case RETURN: 37 | if (program.function > -1) { 38 | program.loc++; 39 | program.thisScope.functions.at(program.function).val = getval().val; 40 | program.thisScope.functions.at(program.function).type = getval().type; 41 | program.loc = program.expressions.size(); // return always exits scope 42 | program.loc--; 43 | } 44 | else error(7, ""); 45 | 46 | break; 47 | case WAIT: 48 | wait(); 49 | break; 50 | case WRITE: 51 | writefile(); 52 | break; 53 | case WHILE: 54 | whileloop(); 55 | break; 56 | case FOR: 57 | forloop(); 58 | break; 59 | case SYSTEM: 60 | sys(); 61 | break; 62 | case TYPE: 63 | declareType(); 64 | break; 65 | case BREAK: 66 | if (program.looping) { 67 | scopedown(); 68 | program.looping = false; 69 | } 70 | else error(6, ""); 71 | break; 72 | case MODULE: 73 | /* 74 | * modules are automatically imported during the error check before runtime 75 | * all we need to do here is to move on to the next expression 76 | */ 77 | while (program.expressions[program.loc].t != ENDEXPR) program.loc += 1; 78 | break; 79 | case EXIT: 80 | exit(0); 81 | } 82 | } 83 | 84 | void runUnknown() { 85 | int fnum; 86 | bool shouldbreak; 87 | 88 | switch (program.expressions[program.loc+1].t) { 89 | case TOKEN: 90 | shouldbreak = 0; 91 | 92 | switch (program.expressions[program.loc+1].tktype) { 93 | case COLON: // definition 94 | define(); 95 | shouldbreak = 1; 96 | break; 97 | case ARROW: break; 98 | case PLUS: 99 | if (program.expressions[program.loc+2].tktype == COLON) { 100 | program.loc += 3; 101 | int n = 0; 102 | 103 | const int loc_old = program.loc; 104 | 105 | if (find(program.thisScope.variables, program.expressions[program.loc-3].contents, &n)) { 106 | switch (program.thisScope.variables.at(n).type) { 107 | case INTEGER: 108 | program.thisScope.variables.at(n).val = std::to_string(std::stoi(program.thisScope.variables.at(n).val) + std::stoi(getval().val)); 109 | break; 110 | case LIST: 111 | program.thisScope.variables.at(n).vals.push_back(getval()); 112 | program.thisScope.variables.at(n).length = program.thisScope.variables.at(n).vals.size(); 113 | break; 114 | case STRING: 115 | program.thisScope.variables.at(n).val += getval().val; 116 | break; 117 | case STS_BOOL: error(4, program.thisScope.variables.at(n).name); 118 | } 119 | } 120 | else error(8, program.expressions[program.loc-3].contents); 121 | 122 | program.loc = loc_old; 123 | shouldbreak = 1; 124 | } 125 | break; 126 | case DOT: 127 | objectMember(); 128 | 129 | shouldbreak = true; 130 | 131 | break; 132 | } 133 | 134 | if (shouldbreak) break; 135 | case ENDEXPR: 136 | find(program.thisScope.functions, program.expressions[program.loc].contents, &fnum); // run isFunc to get function number 137 | runfunc(fnum); 138 | break; 139 | case UNKNOWN: 140 | declareObject(); 141 | break; 142 | } 143 | } 144 | 145 | void interp(int psize, char *argv[], int argc) { 146 | parse(); 147 | parseErrors(); 148 | 149 | program.thisScope.variables.push_back(stsvars()); 150 | for (int x = 1; x<=argc-1; x++) { 151 | program.thisScope.variables.back().type = LIST; 152 | program.thisScope.variables.back().vals.resize(program.thisScope.variables.back().vals.size()+1); 153 | program.thisScope.variables.back().vals.back().type = STRING; 154 | program.thisScope.variables.back().vals.back().val = argv[x]; 155 | program.thisScope.variables.back().name = "arg"; 156 | program.thisScope.variables.back().length = argc-1; 157 | } 158 | program.thisScope.types.push_back(socketClass()); 159 | 160 | 161 | newScope(); 162 | } 163 | -------------------------------------------------------------------------------- /src/interpreter/loops.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "../values/sts_values.h" 3 | #include "sts_interpreter.h" 4 | 5 | void whileloop() { 6 | program.loc += 1; 7 | program_t program_old = program; 8 | 9 | int n = program.loc; 10 | program.looping = true; 11 | 12 | while (toBool(getval().val)) { 13 | newScope(); 14 | 15 | if (!program.looping) break; // looping should only be false in the case of a break; 16 | 17 | program.loc = n; // set n back to y to repeat 18 | } 19 | 20 | while (program.expressions[program.loc].tktype != OPENCURL) program.loc++; 21 | 22 | program_old.loc = program.loc + 1; 23 | program_old.thisScope = program.thisScope; // get new versions of variables 24 | program = program_old; 25 | scopedown(); 26 | } 27 | 28 | 29 | void forloop() { 30 | program.loc += 1; 31 | program_t program_old = program; 32 | 33 | bool foreach = (program.expressions[program.loc+1].btn == STSIN); 34 | int _loc; // placeholder for original location at start of loop 35 | program.looping = true; 36 | 37 | if (foreach) { 38 | stsvars root; 39 | string name; 40 | int rootsize; 41 | name = program.expressions[program.loc].contents; 42 | 43 | program.loc += 2; 44 | 45 | // grab variable listed on 3rd argument of for loop 46 | int rootnum; 47 | find(program.thisScope.variables, program.expressions[program.loc].contents, &rootnum); 48 | root = program.thisScope.variables[rootnum]; 49 | 50 | program.loc += 1; 51 | 52 | switch (root.type) { 53 | case STRING: 54 | case LIST: rootsize = root.length; 55 | break; 56 | case INTEGER: 57 | case STS_BOOL: 58 | error(2, root.name); 59 | } 60 | 61 | _loc = program.loc; 62 | 63 | for (int i = 0; i < rootsize; i++) { 64 | stsvars placeholder; 65 | 66 | program.loc = _loc; 67 | 68 | if (root.type == LIST) 69 | placeholder = root.vals[i]; 70 | else { 71 | placeholder.val = std::to_string(root.val[i]); 72 | placeholder.length = 1; 73 | placeholder.type = STRING; 74 | } 75 | placeholder.name = name; 76 | 77 | program.thisScope.variables.push_back(placeholder); 78 | 79 | newScope(); 80 | 81 | program.thisScope.variables.pop_back(); 82 | 83 | if (!program.looping) break; 84 | } 85 | } 86 | else { 87 | int r = std::stoi(getval().val); 88 | program.loc += 1; 89 | 90 | _loc = program.loc; 91 | 92 | if (r <= 0) 93 | error(4, std::to_string(r)); 94 | 95 | for (int i = 0; i < r; i++) { 96 | program.loc = _loc; 97 | 98 | newScope(); 99 | 100 | if (!program.looping) break; 101 | } 102 | } 103 | 104 | program_old.loc = _loc+1; 105 | program_old.thisScope = program.thisScope; 106 | program = program_old; 107 | 108 | scopedown(); 109 | } 110 | -------------------------------------------------------------------------------- /src/interpreter/newscope.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "sts_interpreter.h" 3 | 4 | void newScope() { 5 | std::vector _functions = program.thisScope.functions; 6 | std::vector _variables = program.thisScope.variables; 7 | std::vector _types = program.thisScope.types; 8 | std::vector _objects = program.thisScope.objects; 9 | 10 | while ((program.expressions[program.loc].tktype != CLOSEDCURL) && (program.loc < program.expressions.size())) { 11 | 12 | switch(program.expressions[program.loc].t) { // don't need to worry about TOKEN and ENDEXPR because they will be handled inside of functions 13 | case BUILTIN: 14 | if (program.expressions[program.loc].btn != STSSOCKET) { 15 | runBuiltin(); 16 | break; 17 | } 18 | case UNKNOWN: 19 | runUnknown(); 20 | break; 21 | } 22 | 23 | program.loc++; 24 | } 25 | 26 | program.thisScope.variables.erase(program.thisScope.variables.begin() + _variables.size(), program.thisScope.variables.end()); 27 | program.thisScope.objects.erase(program.thisScope.objects.begin() + _objects.size(), program.thisScope.objects.end()); 28 | 29 | _functions = program.thisScope.functions; 30 | _variables = program.thisScope.variables; 31 | _objects = program.thisScope.objects; 32 | 33 | program.thisScope = scope(_functions, _variables, _types); // reset size back to original 34 | } -------------------------------------------------------------------------------- /src/interpreter/sts_interpreter.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef INTERPRETER_H_ 3 | #define INTERPRETER_H_ 4 | 5 | #include "../stormscript.h" 6 | 7 | void newScope(); 8 | void runBuiltin(); 9 | void runUnknown(); 10 | void interp(int psize, char *argv[], int argc); 11 | 12 | void forloop(); 13 | void whileloop(); 14 | 15 | // these are defined here because there is nowhere else to put them 16 | inline void wait() { 17 | program.loc++; 18 | 19 | sleep(std::stoi(getval().val)); 20 | 21 | program.loc--; 22 | } 23 | 24 | inline void sys() { 25 | program.loc++; 26 | 27 | system(getval().val.c_str()); 28 | 29 | program.loc++; 30 | } 31 | 32 | #endif // INTERPRETER_H_ 33 | 34 | -------------------------------------------------------------------------------- /src/networking/networking.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef NETWORKING_H_ 3 | #define NETWORKING_H_ 4 | 5 | #include "../stormscript.h" 6 | 7 | #if (PLATFORM) 8 | #include 9 | #include 10 | #include 11 | 12 | inline WSADATA data; 13 | #else 14 | #include 15 | #include 16 | #include 17 | #endif // PLATFORM == 1 18 | 19 | // socket stuff: 20 | stsObject createSocket(string family, string hostname, uint16_t port, stsObject socketObject); 21 | stsObject awaitSocket(stsObject socketObject, string msg, bool output); 22 | stsObject connectSocket(stsObject socketObject, string msg); 23 | inline struct sockaddr_in addr; 24 | 25 | //functions that return "type" are treated as classes and should be declared inline in header files 26 | inline type socketClass() { 27 | type t; 28 | stsvars family, address, port, success, sockval; 29 | 30 | t.name = "socket"; 31 | 32 | // these are all defaults 33 | 34 | family.name = "family"; 35 | family.type = STRING; 36 | family.val = "AF_INET"; 37 | 38 | address.name = "address"; 39 | address.type = STRING; 40 | address.val = "127.0.0.1"; 41 | 42 | port.name = "port"; 43 | port.type = INTEGER; 44 | port.val = "9999"; 45 | 46 | success.name = "success"; 47 | success.type = STS_BOOL; 48 | success.val = "false"; 49 | 50 | sockval.name = "sockval"; 51 | sockval.type = INTEGER; 52 | sockval.val = "-1"; 53 | 54 | t.members.push_back(family); 55 | t.members.push_back(address); 56 | t.members.push_back(port); 57 | t.members.push_back(success); 58 | t.members.push_back(sockval); 59 | 60 | return t; 61 | } 62 | 63 | #endif // NETWORKING_H_ -------------------------------------------------------------------------------- /src/networking/stsSocket.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "networking.h" 3 | 4 | stsObject createSocket(string strfamily, string hostname, uint16_t port, stsObject socketObject) { 5 | /* 6 | * Socket Object Guide: 7 | * socketObject.members[0]: Family (AF_INET or AF_INET6) 8 | * socketObject.members[1]: address (ip or hostname) 9 | * socketObject.members[2]: port 10 | * socketObject.members[3]: success (Always should be true if successful) 11 | * socketObject.members[4]: socket val: error or success state of socket 12 | */ 13 | 14 | socketObject.members[0].val = strfamily; 15 | socketObject.members[1].val = hostname; 16 | socketObject.members[2].val = std::to_string(port); 17 | socketObject.members[3].val = "true"; 18 | 19 | 20 | // porting to winsock2 requires some changes 21 | #if (PLATFORM == 0) 22 | sa_family_t family; 23 | 24 | if (strfamily == "AF_INET") family = AF_INET; 25 | else if (strfamily == "AF_INET6") family = AF_INET6; 26 | #else 27 | WSAStartup(MAKEWORD(2, 2), &data); // this has to be called for winsock to work 28 | 29 | int family; 30 | 31 | if (strfamily == "AF_INET") family = 2; 32 | else if (strfamily == "AF_INET6") family = 23; 33 | #endif 34 | 35 | addr.sin_family = family; 36 | addr.sin_addr.s_addr = inet_addr(hostname.c_str()); 37 | addr.sin_port = htons(port); 38 | 39 | int s = socket(family, SOCK_STREAM, 0); 40 | 41 | socketObject.members[4].val = std::to_string(socket(family, SOCK_STREAM, 0)); 42 | 43 | if (std::stoi(socketObject.members[4].val) < 0) 44 | socketObject.members[3].val = "false"; // some sort of error occured 45 | 46 | return socketObject; 47 | } 48 | 49 | 50 | /* 51 | * awaiting a connection and connecting work very similarly 52 | * It would make sense to combine the commands needed to connect to client/server 53 | * into only a socket.await or socket.connect method respectively 54 | */ 55 | stsObject awaitSocket(stsObject socketObject, string msg, bool output) { 56 | int socketval = std::stoi(socketObject.members[4].val); 57 | int bindval; 58 | int clientSock; 59 | int r = 0; 60 | 61 | #if (PLATFORM == 0) 62 | int addrsizei = sizeof(addr); // integer form of addrsize 63 | socklen_t *addrsize = (socklen_t *)&addrsizei; 64 | bindval = bind(socketval, (struct sockaddr *)&addr, (socklen_t)sizeof(addr)); 65 | #else 66 | int *addrsize = (int *)new unsigned long(sizeof(addr)); 67 | bindval = bind(socketval, (SOCKADDR *)&addr, sizeof(addr)); 68 | #endif 69 | 70 | int listenval = listen(socketval, 3); 71 | clientSock = accept(socketval, (struct sockaddr *)&addr, addrsize); 72 | 73 | #if (!PLATFORM) 74 | if (listenval < 0 || bindval < 0) 75 | socketObject.members[3].val = "false"; 76 | #else 77 | if (listenval == SOCKET_ERROR || bindval == SOCKET_ERROR) 78 | socketObject.members[3].val = "false"; 79 | #endif 80 | else { 81 | 82 | char buffer[1024] = {0}; 83 | r = recv(clientSock, buffer, 1024, 0); 84 | 85 | r = send(clientSock, msg.c_str(), msg.size(), 0); 86 | 87 | if (output) 88 | cout << buffer << "\n"; 89 | } 90 | 91 | #if (PLATFORM) 92 | WSACleanup(); 93 | #endif 94 | return socketObject; 95 | } 96 | 97 | stsObject connectSocket(stsObject socketObject, string msg) { 98 | int socketval = std::stoi(socketObject.members[4].val); 99 | int addrsize = sizeof(addr); 100 | 101 | #if (PLATFORM == 0) 102 | sa_family_t family; 103 | 104 | if (socketObject.members[0].val == "AF_INET") family = AF_INET; 105 | else if (socketObject.members[0].val == "AF_INET6") family = AF_INET6 ; 106 | 107 | int pres = inet_pton(family, socketObject.members[1].val.c_str(), &addr.sin_addr); 108 | 109 | if (pres <= 0) { 110 | socketObject.members[3].val = "false"; 111 | return socketObject; 112 | } 113 | #else 114 | int family; 115 | 116 | if (socketObject.members[0].val == "AF_INET") family = 2; 117 | else if (socketObject.members[0].val == "AF_INET6") family = 23; 118 | #endif 119 | 120 | int connects = connect(socketval, (struct sockaddr *)&addr, addrsize); 121 | 122 | if (connects < 0) 123 | socketObject.members[3].val = "false"; 124 | else { 125 | send(socketval, msg.c_str(), msg.size(), 0); 126 | 127 | char buffer[1024] = {0}; 128 | int val = recv(socketval, buffer, 1024, 0); 129 | cout << buffer << '\n'; 130 | } 131 | 132 | #if (PLATFORM) 133 | WSACleanup(); 134 | #endif 135 | return socketObject; 136 | } 137 | -------------------------------------------------------------------------------- /src/operations.cc: -------------------------------------------------------------------------------- 1 | #include "stormscript.h" 2 | 3 | bool toBool(string s) { 4 | return (s == "true"); 5 | } 6 | 7 | string striplit(string line) { 8 | line.pop_back(); 9 | line.erase(line.begin()); 10 | 11 | return line; 12 | } 13 | 14 | bool isint(string s) { 15 | for (int i = 0; i < s.size(); i++) { 16 | if ((std::isdigit(s[i])) || ((s[i]=='-') && (std::isdigit(s[i])))) 17 | return true; 18 | else 19 | return false; 20 | } 21 | 22 | return false; 23 | } 24 | 25 | void scopedown() { // exit current scope 26 | int endreq = 1; 27 | 28 | while (endreq != 0) { 29 | if (program.expressions[program.loc].tktype == OPENCURL) endreq += 1; 30 | else if (program.expressions[program.loc].tktype == CLOSEDCURL) endreq -= 1; 31 | 32 | program.loc++; 33 | } 34 | program.loc--; 35 | } 36 | -------------------------------------------------------------------------------- /src/parser/eval.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "sts_parser.h" 3 | 4 | Value getValue(string ctn) { 5 | if (ctn.front() == '\"') return STRING; 6 | else if (isint(ctn)) return INTEGER; 7 | else if ((ctn == "true") || (ctn == "false")) return STS_BOOL; 8 | return NOVAL; 9 | } 10 | 11 | tokenType gettktype(string tkn) { 12 | if (tkn == "is") return IS; 13 | else if (tkn == "not") return NOT; 14 | else if (tkn == "less") return LESS; 15 | else if (tkn == "lesseq") return LESSEQ; 16 | else if (tkn == "greater") return GREATER; 17 | else if (tkn == "greatereq") return GREATEREQ; 18 | else if (tkn == "?") return TERNARY1; 19 | else if (tkn == ":") return COLON; 20 | else if (tkn == "=>") return ARROW; 21 | else if (tkn == "{") return OPENCURL; 22 | else if (tkn == "}") return CLOSEDCURL; 23 | else if (tkn == "[") return OPENBRACKET; 24 | else if (tkn == "]") return CLOSEDBRACKET; 25 | else if (tkn == "+") return PLUS; 26 | else if (tkn == "-") return MINUS; 27 | else if (tkn == "/") return DIVISION; 28 | else if (tkn == "*") return MULTIPLICATION; 29 | else if (tkn == ",") return COMMA; 30 | else if (tkn == ".") return DOT; 31 | return NOTOKEN; 32 | } 33 | 34 | Builtin getBuiltincmd(string kwd) { 35 | if (kwd == "print") return PRINT; 36 | else if (kwd == "printl") return PRINTL; 37 | else if (kwd == "in") return STSIN; 38 | else if (kwd == "if") return IF; 39 | else if (kwd == "else") return ELSE; 40 | else if (kwd == "func") return FUNCTION; 41 | else if (kwd == "type") return TYPE; 42 | else if (kwd == "int") return TYPE_INTEGER; 43 | else if (kwd == "str") return TYPE_STRING; 44 | else if (kwd == "bool") return TYPE_STS_BOOL; 45 | else if (kwd == "list") return TYPE_LIST; 46 | else if (kwd == "init") return CONSTRUCTOR_SCOPE; 47 | else if (kwd == "mod") return MODULE; 48 | else if (kwd == "return") return RETURN; 49 | else if (kwd == "while") return WHILE; 50 | else if (kwd == "for") return FOR; 51 | else if (kwd == "foreach") return FOREACH; 52 | else if (kwd == "exit") return EXIT; 53 | else if (kwd == "sys") return SYSTEM; 54 | else if (kwd == "wait") return WAIT; 55 | else if (kwd == "write") return WRITE; 56 | else if (kwd == "read") return READ; 57 | else if (kwd == "random") return RANDOM; 58 | else if (kwd == "randomrange") return RANDOMRANGE; 59 | else if (kwd == "length") return LENGTH; 60 | else if (kwd == "break") return BREAK; 61 | else if (kwd == "socket") return STSSOCKET; 62 | else if (kwd == "private") return TYPE_PRIVATE; 63 | return NONE; 64 | } 65 | 66 | void evaluateProgram() { 67 | for (int i = 0; i < program.expressions.size(); i++) { 68 | string contents = program.expressions[i].contents; 69 | Builtin btn = getBuiltincmd(contents); 70 | tokenType tktype = gettktype(contents); 71 | Value val = getValue(contents); 72 | 73 | if (btn != NONE) { 74 | program.expressions[i].t = BUILTIN; 75 | program.expressions[i].btn = btn; 76 | } 77 | else if (gettktype(contents) != NOTOKEN) { 78 | program.expressions[i].t = TOKEN; 79 | program.expressions[i].tktype = tktype; 80 | } 81 | else if (val != NOVAL) { 82 | program.expressions[i].t = VALUE; 83 | program.expressions[i].literalType = val; 84 | } 85 | else if (contents == ";") 86 | program.expressions[i].t = ENDEXPR; 87 | else 88 | program.expressions[i].t = UNKNOWN; 89 | 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/parser/modules.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "../sts_files.h" 3 | #include "sts_parser.h" 4 | 5 | void importModules(int *i) { 6 | /* 7 | * Importing a module works the same way as executing a normal program. 8 | * (Why should it be any different?) 9 | * 10 | * Instead of being called, modules are actually just added to the parsed version of 11 | * the original program. This saves time as in this case the module only has to be opened 12 | * once during a single run 13 | */ 14 | *i += 1; 15 | 16 | int endexprloc = 0; 17 | 18 | while (program.expressions[endexprloc].t != ENDEXPR) endexprloc++; 19 | 20 | while (*i < endexprloc) { 21 | if (program.expressions[*i].tktype != COMMA) { 22 | string modname, _filename; // filename adds .sts to the end of the modname 23 | modname = program.expressions[*i].contents; 24 | _filename = modname + ".sts"; 25 | 26 | program_t program_old = program; 27 | program.expressions.clear(); 28 | 29 | program.filename = _filename; 30 | stsread({}, 0); // stsread() is run without argv 31 | 32 | program_old.expressions.insert(program_old.expressions.begin() + endexprloc + 1, 33 | program.expressions.begin(), program.expressions.end()); 34 | 35 | program = program_old; 36 | } 37 | 38 | *i += 1; 39 | } 40 | *i += 1; 41 | } 42 | -------------------------------------------------------------------------------- /src/parser/parse.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "../sts_files.h" 3 | #include "sts_parser.h" 4 | 5 | /* 6 | the interpreter parses the file and calls functions in other files 7 | */ 8 | void parse() { 9 | int y = 0; 10 | 11 | while (y!=parserProgram.size()){ 12 | int z = 0; 13 | bool inquotes = false; 14 | if (program.expressions.size() > 0) 15 | program.expressions.resize(program.expressions.size()+1); 16 | 17 | while (parserProgram[y][0]==' ') 18 | parserProgram[y].erase(parserProgram[y].begin()); 19 | 20 | 21 | while (z!=parserProgram[y].size()){ 22 | if (parserProgram[y][z]=='"'){ 23 | if (inquotes == false) 24 | inquotes = true; 25 | else 26 | inquotes = false; 27 | } 28 | 29 | // this is what checks for chars to remove from prs version 30 | if (((parserProgram[y][z]==' ') || (parserProgram[y][z]=='\n') || (parserProgram[y][z]=='(') || (parserProgram[y][z]==')')) && (inquotes==false)){ 31 | if ((program.expressions.back().contents.size() != 0)) 32 | program.expressions.resize(program.expressions.size()+1); 33 | z++; 34 | program.expressions.back().line = y; 35 | continue; 36 | } 37 | else if ((parserProgram[y][z]=='#')) // line comment 38 | break; 39 | else if (((parserProgram[y][z]==';') || (parserProgram[y][z]=='}') || (parserProgram[y][z]=='{')) && (inquotes==false)) { 40 | program.expressions.resize(program.expressions.size() + 1); 41 | program.expressions.back() = string(1,parserProgram[y][z]); 42 | program.expressions.back().line = y; 43 | break; 44 | } 45 | else if (((parserProgram[y][z]=='+') || (parserProgram[y][z]=='-') || (parserProgram[y][z]=='*') || ((parserProgram[y][z]=='/') && (program.expressions[program.expressions.size()-2].contents!="mod")) || (parserProgram[y][z]=='[') || (parserProgram[y][z]==',') || (parserProgram[y][z]==']') || (parserProgram[y][z] == ':') || (parserProgram[y][z] == '.')) && (inquotes==false)) { 46 | program.expressions.push_back( string(1,parserProgram[y][z]) ); 47 | program.expressions.back().line = y; 48 | program.expressions.resize(program.expressions.size()+1); 49 | } 50 | else if ((parserProgram[y][z]=='\t') && (inquotes==false)) { 51 | z++; 52 | program.expressions.back().line = y; 53 | continue; 54 | } 55 | else { 56 | if (program.expressions.size() == 0) 57 | program.expressions.push_back(expression()); 58 | program.expressions.back().contents+=parserProgram[y][z]; 59 | } 60 | program.expressions.back().line = y; 61 | z++; 62 | } 63 | y++; 64 | } 65 | 66 | for (int i = 0; i < program.expressions.size(); i++) { 67 | if ((program.expressions[i].contents=="\0") || (program.expressions[i].contents.size() == 0) || (program.expressions[i].contents=="\n") || 68 | (program.expressions[i].contents.size() == 1 && program.expressions[i].contents[0] == 0)) { //this part makes sure that the last empty line is not parsed at all 69 | program.expressions.erase(program.expressions.begin() + i); 70 | i--; // we want to subtract one so that the parser does leave one of two consecutive blank expressions 71 | } 72 | } 73 | 74 | evaluateProgram(); 75 | } 76 | -------------------------------------------------------------------------------- /src/parser/parseerrors.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "../sts_files.h" 3 | 4 | void parseErrors() { 5 | /* 6 | * this function does not parse runtime errors for: 7 | * a. speed: it is significantly faster to parse unknown command and missing semicolons before the program is run 8 | * b. there are certain errors that should only be triggered at runtime 9 | */ 10 | std::vector globnames; 11 | 12 | // Stores the names of the local variables in the current scope 13 | std::vector localnames = globnames; 14 | 15 | bool glob = 1; 16 | 17 | for (int i = 0; i < program.expressions.size(); i++) { 18 | if ((program.expressions[i].line == parserProgram.size() - 1 && i == program.expressions.size()-1) || program.expressions[i + 1].line != program.expressions[i].line) { // this checks if there is no semicolon at the end of line 19 | if (program.expressions[i].t != ENDEXPR && program.expressions[i].tktype != CLOSEDCURL && program.expressions[i].tktype != OPENCURL) 20 | error(1, std::to_string(program.expressions[i].line + 1)); // add 1 to line because line gives index, which always starts at 0 21 | } 22 | else if (program.expressions[i].tktype == OPENCURL) { 23 | glob = 0; 24 | } 25 | else if (program.expressions[i].tktype == CLOSEDCURL) { 26 | glob = 1; 27 | localnames = globnames; 28 | } 29 | else if ((program.expressions[i].t == UNKNOWN && 30 | (program.expressions[i-1].btn == FUNCTION || program.expressions[i+1].tktype == COLON || 31 | program.expressions[i-1].btn == TYPE || 32 | program.expressions[i-1].btn == TYPE_INTEGER || program.expressions[i-1].btn == TYPE_STRING || program.expressions[i-1].btn == TYPE_LIST || program.expressions[i-1].btn == TYPE_STS_BOOL)) || 33 | program.expressions[i].btn == CONSTRUCTOR_SCOPE) 34 | { // names vector allows names to be "marked" as known program.expressions 35 | localnames.push_back(program.expressions[i].contents); 36 | if (program.expressions[i+1].tktype == ARROW) { 37 | i+= 2; 38 | while (program.expressions[i].tktype != OPENCURL) { 39 | if (program.expressions[i].tktype == COMMA) i++; 40 | 41 | localnames.push_back(program.expressions[i].contents); 42 | 43 | i++; 44 | } 45 | i--; 46 | glob = 0; 47 | } 48 | } 49 | else if (program.expressions[i].t == UNKNOWN && program.expressions[i+1].t == UNKNOWN && 50 | std::find(localnames.begin(), localnames.end(), program.expressions[i].contents) != localnames.end()) 51 | { 52 | localnames.push_back(program.expressions[++i].contents); 53 | } 54 | else if (program.expressions[i-1].btn == MODULE) { 55 | /* 56 | * It's easier to import modules before runtime because it allows 57 | * for checks to be run on the modules at the same time that they are 58 | * run on the original program 59 | */ 60 | i--; 61 | importModules(&i); 62 | } 63 | else if (program.expressions[i].btn == STSSOCKET) { 64 | if (program.expressions[++i].t != UNKNOWN) 65 | error(11, std::to_string(program.expressions[i].line)); 66 | 67 | localnames.push_back(program.expressions[i].contents); 68 | localnames.push_back("family"); 69 | localnames.push_back("address"); 70 | localnames.push_back("port"); 71 | localnames.push_back("success"); 72 | localnames.push_back("sockval"); 73 | localnames.push_back("await"); 74 | localnames.push_back("connect"); 75 | 76 | i += 6; 77 | } 78 | else if (program.expressions[i].btn == STSIN) { 79 | i++; 80 | // in followed by a variable should be accounted for, as it is currently the only unordinary way to define a variable 81 | switch (program.expressions[i].t) { 82 | case UNKNOWN: 83 | localnames.push_back(program.expressions[i].contents); 84 | break; 85 | case ENDEXPR: 86 | error(12, std::to_string(program.expressions[i-1].line)); 87 | break; 88 | default: 89 | error(13, program.expressions[i].contents); 90 | break; 91 | } 92 | 93 | } 94 | else if // written like this to make it more clear what is happening 95 | ( 96 | (program.expressions[i].t == UNKNOWN && (program.expressions[i+1].t == ENDEXPR || program.expressions[i+1].tktype == ARROW || program.expressions[i+1].tktype == COMMA)) && 97 | (localnames.size() == 0 || // if size is 0 it must be an error 98 | std::find(localnames.begin(), localnames.end(), program.expressions[i].contents) == localnames.end() // true if not in names 99 | ) 100 | ) // make sure it is not a function before throwing unknown command error 101 | { 102 | error(3, program.expressions[i].contents); 103 | } 104 | 105 | if (glob) globnames = localnames; // every scope change keeps the previous scope's variables 106 | } 107 | } -------------------------------------------------------------------------------- /src/parser/read.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "../sts_files.h" 3 | #include "../interpreter/sts_interpreter.h" 4 | #include 5 | 6 | void stsread(char *argv[], int argc) { 7 | std::ifstream file; 8 | string contents; 9 | 10 | parserProgram = {}; 11 | 12 | int sizeoff = 0; 13 | 14 | file.open(program.filename.c_str()); 15 | 16 | if (file.fail()) 17 | error(0, program.filename); 18 | 19 | char c = file.get(); 20 | 21 | while (file.good()) { 22 | contents += c; 23 | c = file.get(); 24 | } 25 | 26 | file.close(); 27 | 28 | for (int x = 0; x <= contents.size(); x++) { 29 | if (contents[x] == '\n') 30 | sizeoff++; 31 | } //create sizeof in lines 32 | 33 | sizeoff++; 34 | parserProgram.resize(sizeoff); //create vector for lines 35 | int loc = 0; 36 | int a = 0; 37 | for (int x = 0; x <= contents.size(); x++) { 38 | if (contents[x] == '\n') { 39 | for (int y = loc; y < x; y++) 40 | parserProgram[a] += contents[y]; //add lines to vector 41 | 42 | a++; 43 | loc = x + 1; 44 | } 45 | } 46 | for (int x = loc; x <= contents.size(); x++) 47 | parserProgram[parserProgram.size() - 1] += contents[x]; //add last line to vector 48 | 49 | interp(sizeoff, argv, argc); 50 | } 51 | -------------------------------------------------------------------------------- /src/parser/sts_parser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef STS_PARSER_H_ 3 | #define STS_PARSER_H_ 4 | 5 | void parse(); 6 | void evaluateProgram(); 7 | void parseErrors(); 8 | 9 | #endif // STS_PARSER_H_ 10 | -------------------------------------------------------------------------------- /src/scripts/update.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Check if version is latest, and download latest update 3 | import sys 4 | import os 5 | import json 6 | import urllib.request 7 | 8 | cwd = os.getcwd() 9 | 10 | version = sys.argv[1] 11 | 12 | sizetypes = ["B", "KiB", "MiB", "GiB"] # I hope it never reaches the GiB size, but putting it there to be safe 13 | 14 | latest = json.loads(urllib.request.urlopen("https://api.github.com/repos/stormprograms/stormscript/releases/latest").read()) 15 | latesttag = latest["tag_name"] 16 | latestsize = latest["assets"][1]["size"] 17 | latestfname = latest["assets"][1]["name"] 18 | latesturl = latest["assets"][1]["browser_download_url"] 19 | 20 | if latesttag == version: 21 | print("You are currently on the latest version") 22 | exit(0) 23 | 24 | print("StormScript version {} is out now!".format(latesttag)) 25 | 26 | sizetypenum = 0 27 | 28 | while len(str(latestsize)) > 3: 29 | latestsize = str(round(int(latestsize) / 1000)) 30 | sizetypenum += 1 31 | 32 | latestsize += " {}".format(sizetypes[sizetypenum]) 33 | 34 | c = '' 35 | while c not in {"y", "n", "Y", "N"}: 36 | c = input("Confirm Update from StormScript {0} to {1} [{2}] (y/n) ".format(version, latesttag, latestsize)) 37 | 38 | if c == 'y': 39 | print("Starting Update") 40 | print ("Downloading {}".format(latestfname)) 41 | 42 | os.system("curl -LOs {}".format(latesturl)) 43 | os.system("mkdir /tmp/stormscript; mv {} /tmp/stormscript".format(latestfname)) 44 | os.system("cd /tmp/stormscript; tar -xf {0} {1};".format(latestfname, latestfname[:-7])) 45 | os.system("cd /tmp/stormscript/{}; ./install.sh".format(latestfname[:-7])) 46 | os.system("cd {}; rm -rf /tmp/stormscript".format(cwd)) 47 | else: 48 | print("Canceling Update") 49 | 50 | exit(0) -------------------------------------------------------------------------------- /src/stormscript.cc: -------------------------------------------------------------------------------- 1 | #include "stormscript.h" 2 | #include "sts_files.h" 3 | /* 4 | _____ _ _____ _ _ 5 | / ____| | / ____| (_) | | 6 | | (___ | |_ ___ _ __ _ __ ___ | (___ ___ _ __ _ _ __ | |_ 7 | \___ \| __/ _ \| '__| '_ ` _ \ \___ \ / __| '__| | '_ \| __| 8 | ____) | || (_) | | | | | | | |____) | (__| | | | |_) | |_ 9 | |_____/ \__\___/|_| |_| |_| |_|_____/ \___|_| |_| .__/ \__| 10 | | | 11 | |_| 12 | */ 13 | 14 | void showhelp() { 15 | cout << "Usage: stormscript [file|options]\n"; 16 | cout << "StormScript is a powerful, open source programming language for many operating systems.\n\n"; 17 | cout << " -h, --help: display help\n"; 18 | cout << " --version: show version\n\n"; 19 | #if (!PLATFORM) 20 | cout << " update: Download and install the latest update\n"; 21 | #endif 22 | cout << " install: install a module\n\n"; 23 | cout << "StormScript " << VERSION << '\n'; 24 | cout << "git: https://github.com/stormprograms/StormScript\n"; 25 | cout << "For documentation, go to https://stormscript.dev/docs\n"; 26 | } 27 | 28 | int main(int argc, char *argv[]) { 29 | if (argc != 1) { 30 | if (string(argv[1])=="--version") 31 | cout << "StormScript " << VERSION << '\n'; 32 | else if ((string(argv[1])=="--help") || (string(argv[1])=="-h")) 33 | showhelp(); 34 | 35 | 36 | #if (!PLATFORM) // this only works on linux for now 37 | else if (string(argv[1])=="update") { 38 | execl("/usr/bin/python3", "python3", "/usr/share/stormscript/update.py", VERSION, (char *)0); 39 | } 40 | #endif 41 | 42 | 43 | else if (string(argv[1])=="install") { 44 | string cmd = "wget https://storage.googleapis.com/stormscript/"; 45 | if (argc > 2) { 46 | cmd+= argv[2]; 47 | cmd+= ".sts"; 48 | system(cmd.c_str()); 49 | } 50 | else 51 | error(9, "none"); 52 | } 53 | else { 54 | program.filename = argv[1]; 55 | stsread(argv, argc); 56 | } 57 | } 58 | else 59 | showhelp(); 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /src/stormscript.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef STORMSCRIPT_H_ 3 | #define STORMSCRIPT_H_ 4 | 5 | /* 6 | * This macro changes executed code based on platform 7 | * When platform is 1, it is on windows, otherwise run unix code 8 | */ 9 | #define PLATFORM (defined(_WIN32) || defined(__MINGW32__)) // true if on windows 10 | 11 | #define VERSION "v1.1.0" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | using std::cout; 25 | using std::string; 26 | 27 | // forward dec for use in program struct 28 | class expression; 29 | class type; 30 | class stsfunc; 31 | class stsvars; 32 | class stsObject; 33 | 34 | // basic scope info, so current variables, functions, objects, and types 35 | struct scope { 36 | std::vector types; 37 | std::vector functions; 38 | std::vector variables; 39 | std::vector objects; 40 | 41 | scope(std::vector f = {}, std::vector v = {}, std::vector t = {}, std::vector V = {}) { 42 | types = t; 43 | functions = f; 44 | variables = v; 45 | objects = V; 46 | } 47 | }; 48 | 49 | // this is the base struct with program info 50 | inline struct program_t { 51 | int loc = 0; 52 | int function = -1; 53 | 54 | // looping flag is global to allow nested loops not all breaking on a break token not inside the original loop 55 | bool looping = false; 56 | 57 | string filename; 58 | 59 | std::vector expressions; 60 | 61 | /* 62 | * The reason that thisScope is initialized with the program_t struct is 63 | * because it is tied with the program. 64 | * 65 | * When a new program_t instance is created, 66 | * it should have a new scope to go with it 67 | */ 68 | scope thisScope; // this is the current scope, and it is initialized with the global scope 69 | } program; // I will also declare the program struct type here and just use it with "backup" versions for function scopes 70 | 71 | void error(int num, string issue); 72 | 73 | enum ExprType { 74 | BUILTIN, 75 | UNKNOWN, // user defined things 76 | VALUE, 77 | TOKEN, 78 | ENDEXPR 79 | }; 80 | 81 | enum tokenType { // tokens 82 | NOTOKEN, 83 | IS, 84 | NOT, 85 | LESS, 86 | LESSEQ, 87 | GREATER, 88 | GREATEREQ, 89 | TERNARY1, 90 | COLON, 91 | ARROW, 92 | OPENCURL, 93 | CLOSEDCURL, 94 | OPENBRACKET, 95 | CLOSEDBRACKET, 96 | PLUS, 97 | MINUS, 98 | DIVISION, 99 | MULTIPLICATION, 100 | COMMA, 101 | DOT 102 | }; 103 | 104 | enum Builtin { // these are built in commands 105 | NONE, 106 | PRINT, 107 | PRINTL, 108 | STSIN, 109 | IF, 110 | ELSE, 111 | FUNCTION, 112 | TYPE, 113 | TYPE_INTEGER, 114 | TYPE_STRING, 115 | TYPE_STS_BOOL, 116 | TYPE_LIST, 117 | TYPE_PRIVATE, 118 | CONSTRUCTOR_SCOPE, 119 | MODULE, 120 | RETURN, 121 | WHILE, 122 | FOR, 123 | FOREACH, 124 | EXIT, 125 | SYSTEM, 126 | WAIT, 127 | WRITE, 128 | READ, 129 | RANDOM, 130 | RANDOMRANGE, 131 | LENGTH, 132 | BREAK, 133 | STSSOCKET, 134 | }; 135 | 136 | enum Value { // these are types 137 | INTEGER, 138 | STRING, 139 | STS_BOOL, 140 | LIST, 141 | NOVAL 142 | }; 143 | 144 | class expression { 145 | public: 146 | string contents; 147 | 148 | expression(string c = "") { 149 | contents = c; 150 | } 151 | 152 | ExprType t = UNKNOWN; // give type of expression 153 | tokenType tktype = NOTOKEN; 154 | Builtin btn = NONE; 155 | Value literalType = NOVAL; 156 | int line; 157 | }; 158 | 159 | class stsvars { 160 | public: 161 | Value type; 162 | string val; 163 | 164 | std::vector vals; 165 | 166 | int length; 167 | string name; 168 | 169 | bool privateMember = 0; // only used for type members 170 | 171 | void assignlist(); 172 | }; 173 | 174 | class stsfunc:public stsvars{ 175 | public: 176 | std::vector contents; 177 | std::vector args; 178 | 179 | program_t funcprog; 180 | }; 181 | 182 | class type { 183 | public: 184 | string name; 185 | 186 | std::vector members; 187 | std::vector methods; 188 | }; 189 | 190 | class stsObject: public type { 191 | public: 192 | string Parentname; 193 | 194 | stsObject(const type &_Parent = type()) { 195 | Parentname = _Parent.name; 196 | members = _Parent.members; 197 | methods = _Parent.methods; 198 | } 199 | }; 200 | 201 | stsvars getval(); 202 | 203 | // basic functions 204 | string striplit(string line); 205 | bool isint(string s); 206 | bool toBool(string s); 207 | 208 | // go down a scope 209 | void scopedown(); 210 | 211 | // There might be a better place to put this 212 | void importModules(int *i); 213 | 214 | #endif // STORMSCRIPT_H_ 215 | -------------------------------------------------------------------------------- /src/stream/files.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "sts_stream.h" 3 | 4 | stsvars readfile() { 5 | stsvars v; 6 | v.type = STRING; 7 | 8 | program.loc += 1; 9 | 10 | std::ifstream file; 11 | string contents; 12 | string name = getval().val; 13 | 14 | file.open(name); 15 | 16 | if (file.fail()) 17 | error(0, name); 18 | 19 | char c = file.get(); 20 | 21 | while (file.good()) { 22 | contents += c; 23 | c = file.get(); 24 | } 25 | 26 | file.close(); 27 | 28 | v.val = contents; 29 | 30 | return v; 31 | } 32 | 33 | void writefile() { 34 | program.loc += 1; 35 | std::ofstream file; 36 | string name = getval().val; 37 | 38 | file.open(name); 39 | 40 | program.loc += 1; 41 | string contents = getval().val; 42 | 43 | file.write(contents.c_str(), contents.size()); 44 | file.close(); 45 | 46 | program.loc += 1; 47 | } -------------------------------------------------------------------------------- /src/stream/io.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "sts_stream.h" 3 | 4 | string print() { //handles both print and printl. 5 | program.loc++; 6 | stsvars v = getval(); 7 | string value = v.val; 8 | 9 | return value; 10 | } 11 | 12 | stsvars in() { 13 | stsvars input; 14 | 15 | input.name = program.expressions[program.loc+1].contents; 16 | 17 | char valstring[256]; // allocate a 256 bit char array for value storage 18 | 19 | std::cin.getline(valstring, 256); // use std::cin.getline to get value 20 | input.val = valstring; 21 | 22 | input.type = ((isint(input.val)) ? INTEGER : STRING); 23 | 24 | input.length = input.val.size(); 25 | 26 | program.loc += 2; 27 | 28 | return input; 29 | } -------------------------------------------------------------------------------- /src/stream/sts_stream.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef STS_STREAM_H_ 3 | #define STS_STREAM_H_ 4 | 5 | #include "../stormscript.h" 6 | #include 7 | 8 | // files.cc 9 | void writefile(); 10 | stsvars readfile(); 11 | 12 | // io.cc 13 | string print(); 14 | stsvars in(); 15 | 16 | #endif // STS_STREAM_H_ -------------------------------------------------------------------------------- /src/sts_files.h: -------------------------------------------------------------------------------- 1 | #ifndef STS_FILES_H_ 2 | #define STS_FILES_H_ 3 | 4 | #include "stormscript.h" 5 | 6 | void stsread(char *argv[], int argc); // read stormscript programs 7 | 8 | inline std::vector parserProgram; //unparsed program 9 | 10 | #endif // STS_FILES_H_ 11 | -------------------------------------------------------------------------------- /src/type/objectmember.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "sts_type.h" 3 | #include "../networking/networking.h" 4 | 5 | void objectMember() { 6 | /* 7 | * Find and manipulate object members 8 | * run class methods 9 | */ 10 | 11 | int ObjNum, MemberNum; 12 | 13 | // find object 14 | find(program.thisScope.objects, program.expressions[program.loc].contents, &ObjNum); 15 | 16 | if (program.expressions[program.loc+3].tktype == ARROW && program.thisScope.objects[ObjNum].Parentname == "socket") { // socket functions are handled by c++, not stormscript 17 | if (program.expressions[program.loc+2].contents == "await") { 18 | program.loc += 4; 19 | 20 | if (program.expressions[program.loc].t != VALUE && program.expressions[program.loc].t != UNKNOWN) 21 | error(5, "await"); // generic "function requires args error" 22 | 23 | string msg = getval().val; // message to be sent to client 24 | 25 | program.loc += 2; 26 | bool output = toBool(getval().val); // determines whether to output connection or not 27 | 28 | program.thisScope.objects[ObjNum] = awaitSocket(program.thisScope.objects[ObjNum], msg, output); 29 | } 30 | else if (program.expressions[program.loc+2].contents == "connect") { 31 | program.loc += 4; 32 | if (program.expressions[program.loc].t != VALUE && program.expressions[program.loc].t == UNKNOWN) 33 | error(5, "connect"); 34 | 35 | string msg = getval().val; // message to be sent to server 36 | 37 | program.thisScope.objects[ObjNum] = connectSocket(program.thisScope.objects[ObjNum], msg); 38 | } 39 | 40 | return; 41 | } 42 | 43 | program.loc += 2; 44 | 45 | // find member or method 46 | 47 | if (program.expressions[program.loc+1].tktype == COLON) { 48 | // definition 49 | 50 | find(program.thisScope.objects[ObjNum].members, program.expressions[program.loc].contents, &MemberNum); 51 | 52 | if (program.thisScope.objects[ObjNum].members[MemberNum].privateMember) 53 | error(14, program.thisScope.objects[ObjNum].members[MemberNum].name); 54 | 55 | program.loc += 2; 56 | 57 | stsvars newval = getval(); 58 | 59 | if (program.thisScope.objects[ObjNum].members[MemberNum].type == newval.type) 60 | program.thisScope.objects[ObjNum].members[MemberNum].val = newval.val; 61 | else error(2, program.expressions[program.loc].contents); 62 | } 63 | else { 64 | find(program.thisScope.objects[ObjNum].methods, program.expressions[program.loc].contents, &MemberNum); 65 | 66 | program_t program_old = program; 67 | 68 | /* 69 | * Class methods are run in there own mini 70 | * programs to isolate the class members 71 | */ 72 | program.loc = 0; 73 | program.expressions.clear(); 74 | program.expressions.push_back(expression()); 75 | program.expressions[0] = program_old.expressions[program_old.loc]; 76 | 77 | program_old.loc += 1; 78 | 79 | if (program_old.expressions[program_old.loc].tktype == ARROW) { 80 | while (program_old.expressions[program_old.loc].t != ENDEXPR) { 81 | program.expressions.push_back(program_old.expressions[program_old.loc]); 82 | 83 | program_old.loc += 1; 84 | } 85 | } 86 | 87 | program.expressions.push_back(program_old.expressions[program_old.loc]); 88 | 89 | program.thisScope.functions.push_back(program.thisScope.objects[ObjNum].methods[MemberNum]); 90 | program.thisScope.variables.insert(program.thisScope.variables.begin(), program.thisScope.objects[ObjNum].members.begin(), program.thisScope.objects[ObjNum].members.end()); 91 | 92 | runfunc(0); 93 | 94 | program_old.thisScope.objects[ObjNum].members = program.thisScope.variables; 95 | 96 | program = program_old; 97 | } 98 | } -------------------------------------------------------------------------------- /src/type/sts_type.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef STS_TYPE_H_ 3 | #define STS_TYPE_H_ 4 | 5 | #include "../stormscript.h" 6 | #include "../values/sts_values.h" 7 | 8 | void objectMember(); 9 | 10 | void declareType(); 11 | void declareObject(); 12 | 13 | #endif // STS_TYPE_H_ -------------------------------------------------------------------------------- /src/type/type.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | 3 | #include "../values/sts_values.h" 4 | #include "../networking/networking.h" 5 | // for declare object to call evaluate program 6 | #include "../parser/sts_parser.h" 7 | 8 | void declareType() { 9 | program.loc += 1; 10 | 11 | type t; 12 | 13 | t.name = program.expressions[program.loc].contents; 14 | 15 | program.loc += 2; 16 | 17 | while (program.expressions[program.loc].tktype != CLOSEDCURL) { 18 | stsvars member; 19 | stsfunc c; 20 | 21 | switch (program.expressions[program.loc].btn) { 22 | case TYPE_PRIVATE: 23 | member.privateMember = 1; 24 | program.loc++; 25 | case TYPE_INTEGER: 26 | case TYPE_STRING: 27 | case TYPE_LIST: 28 | case TYPE_STS_BOOL: 29 | if (program.expressions[program.loc].btn == TYPE_STS_BOOL) member.type = STS_BOOL; 30 | else if (program.expressions[program.loc].btn == TYPE_INTEGER) member.type = INTEGER; 31 | else if (program.expressions[program.loc].btn == TYPE_STRING) member.type = STRING; 32 | else member.type = LIST; 33 | 34 | member.name = program.expressions[++(program.loc)].contents; 35 | program.loc++; 36 | 37 | t.members.push_back(member); 38 | break; 39 | case CONSTRUCTOR_SCOPE: 40 | case FUNCTION: 41 | program.loc += 1; 42 | 43 | if (program.expressions[program.loc -1].btn == FUNCTION) c.name = program.expressions[(program.loc)++].contents; 44 | else c.name = "init"; 45 | 46 | if (program.expressions[program.loc].tktype == ARROW) { 47 | program.loc += 1; 48 | 49 | while (true) { 50 | 51 | if (program.expressions[program.loc].tktype == OPENCURL) break; 52 | else if (program.expressions[program.loc].tktype != COMMA) { 53 | c.args.push_back(stsvars()); 54 | c.args.back().name = program.expressions[program.loc].contents; 55 | } 56 | program.loc += 1; 57 | } 58 | } 59 | 60 | program.loc += 1; 61 | 62 | int endreq = 1; 63 | 64 | while (endreq != 0) { 65 | if (program.expressions[program.loc].tktype == CLOSEDCURL) endreq--; 66 | else if (program.expressions[program.loc].tktype == OPENCURL) endreq++; 67 | 68 | c.contents.push_back(program.expressions[program.loc]); 69 | 70 | program.loc += 1; 71 | } 72 | program.loc -= 1; // subtract 1 because the previous scope automatically adds 1 at the end 73 | 74 | t.methods.push_back(c); 75 | break; 76 | } 77 | program.loc += 1; 78 | } 79 | 80 | program.thisScope.types.push_back(t); 81 | } 82 | 83 | void declareObject() { 84 | int num; 85 | int initnum; 86 | 87 | find(program.thisScope.types, program.expressions[program.loc].contents, &num); 88 | bool init = find(program.thisScope.types[num].methods, "init", &initnum); // find the init method 89 | 90 | stsObject t = program.thisScope.types[num]; 91 | 92 | t.name = program.expressions[++(program.loc)].contents; 93 | 94 | if (program.thisScope.types[num].name == "socket") { 95 | // socket works as class 96 | program.loc += 2; 97 | 98 | string familyval = getval().val, address; 99 | 100 | program.loc += 2; 101 | address = getval().val; 102 | 103 | program.loc += 2; 104 | t = createSocket(familyval, address, std::stoi(getval().val), t); 105 | program.loc += 1; 106 | } 107 | else if (t.methods.size() > 0 && init) { 108 | program_t program_old = program; 109 | 110 | program.thisScope.functions.push_back(t.methods[initnum]); 111 | program.thisScope.variables.insert(program.thisScope.variables.begin(), t.members.begin(), t.members.end()); 112 | 113 | program.expressions.push_back(expression()); 114 | program.expressions[0].contents = "init"; 115 | program.expressions[0].line = 1; 116 | // if there are arguments 117 | if (program_old.expressions[program_old.loc + 1].tktype == ARROW && program_old.thisScope.types[num].methods[initnum].args.size() > 0) { 118 | program_old.loc += 1; 119 | 120 | while (program_old.expressions[program_old.loc].t != ENDEXPR) { 121 | program.expressions.push_back(expression()); 122 | program.expressions.back().contents = program.expressions[program.loc].contents; 123 | program.expressions.back().line = 1; 124 | 125 | program_old.loc += 1; 126 | } 127 | } 128 | else if (program_old.expressions[program_old.loc + 1].tktype == ARROW) // if user gives arguments when there are none 129 | error(10, t.Parentname); 130 | 131 | program.expressions.push_back(expression()); 132 | program.expressions.back().line = 1; 133 | program.expressions.back().contents = ";"; 134 | 135 | evaluateProgram(); 136 | runfunc(0); 137 | 138 | t.members = program.thisScope.variables; 139 | program = program_old; 140 | } 141 | 142 | program.thisScope.objects.push_back(t); 143 | } -------------------------------------------------------------------------------- /src/values/compare.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "sts_values.h" 3 | 4 | bool condition() { 5 | /* 6 | Comparisons are formatted like this: 7 | VALUE/UNKNOWN | TOKEN |VALUE/UNKNOWN 8 | -----------------------------------------------------|------------- 9 | var | is/not/greater/less/greatereq/lesseq | var 10 | 11 | The right and left hand values can also contain subscripts, in which case they would look more like this: 12 | UNKNOWN | TOKEN | VALUE/UNKNOWN | TOKEN 13 | var | [ | INTEGER | ] 14 | */ 15 | tokenType comparisonType; 16 | int opLocation; 17 | int _loc = program.loc; 18 | 19 | int i = program.loc; 20 | 21 | while ((program.expressions[i].tktype != IS) && (program.expressions[i].tktype != NOT) && (program.expressions[i].tktype != GREATER) && (program.expressions[i].tktype != GREATEREQ) && (program.expressions[i].tktype != LESS) && (program.expressions[i].tktype != LESSEQ)) 22 | i++; 23 | 24 | comparisonType = program.expressions[i].tktype; 25 | opLocation = i; 26 | 27 | program_t program_old = program; // create more isolated expressions to get the value to compare 28 | program.expressions = {}; 29 | program.loc = 0; 30 | program.looping = false; 31 | 32 | for (int i = program_old.loc; i < opLocation; i++) 33 | program.expressions.push_back(program_old.expressions[i]); 34 | 35 | stsvars comp1 = getval(); 36 | 37 | program.expressions = {}; 38 | int l = opLocation; 39 | 40 | for (l = opLocation+1; (program_old.expressions[l].t != ENDEXPR) && (program_old.expressions[l].tktype != OPENCURL) && (program_old.expressions[l].tktype != TERNARY1); l++) 41 | program.expressions.push_back(program_old.expressions[l]); 42 | 43 | program_old.loc = l; 44 | 45 | program.loc = 0; 46 | stsvars comp2 = getval(); 47 | 48 | program = program_old; 49 | 50 | if (comp1.type == comp2.type) { 51 | switch (comparisonType) { 52 | case IS: return (comp1.val == comp2.val); 53 | case NOT: return (comp1.val != comp2.val); 54 | case GREATER: 55 | if ((comp1.type == INTEGER) && (comp2.type == INTEGER)) return (std::stoi(comp1.val) > std::stoi(comp2.val)); 56 | else if (comp1.type != INTEGER) error(2, program.expressions[_loc].contents); // give error with first expression 57 | else if (comp2.type != INTEGER) error(2, program.expressions[opLocation+1].contents); // give error with second expression 58 | break; 59 | case LESS: 60 | if ((comp1.type == INTEGER) && (comp2.type == INTEGER)) return (std::stoi(comp1.val) < std::stoi(comp2.val)); 61 | else if (comp1.type != INTEGER) error(2, program.expressions[_loc].contents); // give error with first expression 62 | else if (comp2.type != INTEGER) error(2, program.expressions[opLocation+1].contents); // give error with second expression 63 | break; 64 | case GREATEREQ: 65 | if ((comp1.type == INTEGER) && (comp2.type == INTEGER)) return (std::stoi(comp1.val) >= std::stoi(comp2.val)); 66 | else if (comp1.type != INTEGER) error(2, program.expressions[_loc].contents); // give error with first expression 67 | else if (comp2.type != INTEGER) error(2, program.expressions[opLocation+1].contents); // give error with second expression 68 | break; 69 | case LESSEQ: 70 | if ((comp1.type == INTEGER) && (comp2.type == INTEGER)) return (std::stoi(comp1.val) <= std::stoi(comp2.val)); 71 | else if (comp1.type != INTEGER) error(2, program.expressions[_loc].contents); // give error with first expression 72 | else if (comp2.type != INTEGER) error(2, program.expressions[opLocation+1].contents); // give error with second expression 73 | break; 74 | } 75 | } 76 | else 77 | error(2, program.expressions[opLocation+1].contents); 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /src/values/find.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | 3 | bool find(std::vector vars, string query, int *num) { 4 | bool isvar = false; 5 | 6 | for (int i = 0; i < vars.size() && !isvar; i++) { 7 | isvar = (vars.at(i).name == query); 8 | if (isvar) 9 | *num = i; 10 | } 11 | 12 | return isvar; 13 | } 14 | 15 | bool find(std::vector functions, string query, int *num) { 16 | for (int i = 0; i < functions.size(); i++) { 17 | if (functions[i].name == query) { 18 | *num = i; 19 | return 1; 20 | } 21 | } 22 | 23 | return 0; 24 | } 25 | 26 | bool find(std::vector types, string query, int *num) { 27 | for (int i = 0; i < types.size(); i++) { 28 | if (types[i].name == query) { 29 | *num = i; 30 | return 1; 31 | } 32 | } 33 | 34 | return 0; 35 | } 36 | 37 | bool find(std::vector vars, string query, int *num) { 38 | for (int i = 0; i < vars.size(); i++) { 39 | if (vars[i].name == query) { 40 | *num = i; 41 | return 1; 42 | } 43 | } 44 | 45 | return 0; 46 | } -------------------------------------------------------------------------------- /src/values/getvals.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "../stream/sts_stream.h" 3 | #include "sts_values.h" 4 | 5 | void replaceEscapes(string *lit) { // escapes 6 | string newl; 7 | 8 | for (int i = 0; i < lit->size(); i++) { 9 | if (lit->at(i) == '\\') { 10 | i++; 11 | 12 | switch (lit->at(i)) { 13 | case 'n': 14 | newl += '\n'; 15 | break; 16 | case 't': 17 | newl += '\t'; 18 | break; 19 | case '\\': 20 | newl += '\\'; 21 | break; 22 | case '$': 23 | newl += '$'; 24 | break; 25 | } 26 | } 27 | else if (lit->at(i) == '$') { // dollar sign for concatenation 28 | string q; 29 | 30 | i++; 31 | 32 | while (lit->at(i) != ' ') { 33 | q += lit->at(i); 34 | 35 | 36 | if (i == lit->size() - 1 ) break; 37 | else i++; 38 | } 39 | 40 | int loc; 41 | find(program.thisScope.variables, q, &loc); 42 | 43 | newl += program.thisScope.variables[loc].val; 44 | if (lit->at(i) == ' ') newl += ' '; 45 | } 46 | else { 47 | newl += lit->at(i); 48 | } 49 | } 50 | 51 | *lit = newl; 52 | } 53 | 54 | stsvars getval() { 55 | /* 56 | * THIS FILE IS VERY IMPORTANT 57 | * When Modifying this function be sure that: 58 | * a. The code works in every circumstance where a value would be needed (act as though any value is grabbed with one expression; add to program.loc until it reaches the end of the expression) 59 | * b. The code uses returns a value with a type. Under no circumstance should the variable "v" have an empty type. 60 | * c. This should go without saying, but please document your code. I don't want to remove anything important because I can't figure out what it does 61 | */ 62 | 63 | stsvars v; 64 | bool dotCompare = false; // dot operations take up 2 extra expression slots 65 | 66 | if (program.expressions[program.loc+1].tktype == DOT && program.expressions[program.loc+3].tktype != COMMA && program.expressions[program.loc+3].t != ENDEXPR 67 | && program.expressions.size() > program.loc+3) { 68 | dotCompare = true; 69 | program.loc += 2; 70 | } 71 | 72 | bool operation = ((program.expressions[program.loc+1].t == TOKEN) && 73 | (program.expressions[program.loc+1].tktype != COMMA) && (program.expressions[program.loc+1].tktype != COLON) && (program.expressions[program.loc+1].tktype != OPENCURL) && (program.expressions[program.loc+1].tktype != CLOSEDBRACKET) && 74 | (program.expressions[program.loc+1].tktype != DOT) && (program.expressions[program.loc].btn != RANDOMRANGE) && 75 | (program.expressions.size() > program.loc+1)); 76 | 77 | switch (operation) { 78 | case 0: // if raw value 79 | if (program.expressions[program.loc].t == VALUE) { // returns literals with proper types 80 | string lit; 81 | 82 | switch (program.expressions[program.loc].literalType) { 83 | case STRING: 84 | lit = striplit(program.expressions[program.loc].contents); 85 | v.type = STRING; 86 | v.length = lit.size(); 87 | replaceEscapes(&lit); 88 | break; 89 | case INTEGER: 90 | case STS_BOOL: 91 | v.type = ((program.expressions[program.loc].literalType == INTEGER) ? INTEGER : STS_BOOL); 92 | lit = program.expressions[program.loc].contents; 93 | break; 94 | } 95 | 96 | v.val = lit; 97 | } 98 | else if (program.expressions[program.loc].t == BUILTIN) { 99 | // stsread just reads the file, but it is always used as a value because it returns a value 100 | switch (program.expressions[program.loc].btn) { 101 | case READ: 102 | v = readfile(); 103 | break; 104 | case RANDOM: 105 | v.val = ((randombool()) ? "true" : "false"); 106 | v.type = STS_BOOL; 107 | break; 108 | case RANDOMRANGE: 109 | v.val = std::to_string(genrandomintfromrange()); 110 | v.type = INTEGER; 111 | } 112 | } 113 | else if (program.expressions[program.loc].t == UNKNOWN) { 114 | int index; 115 | 116 | if (find(program.thisScope.variables, program.expressions[program.loc].contents, &index) || find(program.thisScope.objects, program.expressions[program.loc].contents, &index)) { 117 | if (program.expressions[program.loc+1].tktype != DOT) v = program.thisScope.variables.at(index); // get value 118 | else if (program.expressions[program.loc+2].btn == LENGTH) { // get length 119 | program.loc+= 3; 120 | 121 | v.type = INTEGER; 122 | 123 | if ((program.thisScope.variables.at(index).type == STRING) || (program.thisScope.variables.at(index).type == LIST)) 124 | v.val = std::to_string(program.thisScope.variables.at(index).length); 125 | 126 | else error(2, program.thisScope.variables.at(index).name); 127 | } 128 | else { // look for class members 129 | int MemberLoc; 130 | program.loc += 2; 131 | 132 | find(program.thisScope.objects[index].members, program.expressions[program.loc].contents, &MemberLoc); 133 | 134 | if (program.thisScope.objects[index].members[MemberLoc].privateMember) 135 | error(14, program.thisScope.objects[index].members[MemberLoc].name); 136 | 137 | v = program.thisScope.objects[index].members[MemberLoc]; // return member 138 | 139 | program.loc++; 140 | } 141 | } 142 | else if (find(program.thisScope.functions, program.expressions[program.loc].contents, &index)) { 143 | runfunc(index); 144 | v = program.thisScope.functions[index]; // if expression refers to function 145 | } 146 | } 147 | 148 | break; 149 | case 1: // if operation 150 | tokenType t = program.expressions[program.loc+1].tktype; 151 | std::vector placeholders; 152 | int index; 153 | stsvars sbsvar; 154 | tokenType plus1; 155 | 156 | int first, second; 157 | 158 | if ((t == PLUS) || (t == MINUS) || (t == DIVISION) || (t == MULTIPLICATION)) { 159 | // all math operations will return an integer, so we can set that first 160 | v.type = INTEGER; 161 | 162 | placeholders.resize(2); 163 | 164 | placeholders.at(0).expressions = {program.expressions[program.loc]}; 165 | placeholders.at(0).thisScope = program.thisScope; 166 | placeholders.at(1).expressions = {program.expressions[program.loc+2]}; 167 | placeholders.at(1).thisScope = program.thisScope; 168 | 169 | program.loc+= 2; 170 | 171 | // for math, access placeholder values and store as first and second for operation 172 | program_t program_old = program; 173 | program = placeholders[0]; 174 | first = std::stoi(getval().val); 175 | 176 | program = placeholders[1]; 177 | second = std::stoi(getval().val); 178 | program = program_old; 179 | } 180 | else if (t == OPENBRACKET) { 181 | program.loc += 2; 182 | int er = 1; 183 | int i = program.loc; 184 | 185 | placeholders.resize(1); 186 | placeholders.back().thisScope = program.thisScope; 187 | 188 | while (er != 0) { 189 | if ((program.expressions[i].t == TOKEN) && (program.expressions[i].tktype == CLOSEDBRACKET)) 190 | er--; 191 | else if ((program.expressions[i].t == TOKEN) && (program.expressions[i].tktype == OPENBRACKET)) 192 | er++; 193 | 194 | if (er != 0) 195 | placeholders.back().expressions.push_back(program.expressions[i]); 196 | 197 | i++; 198 | } 199 | program_t program_old = program; 200 | program = placeholders[0]; 201 | 202 | index = std::stoi(getval().val); 203 | 204 | program = program_old; 205 | 206 | int plus1n = placeholders[0].expressions.size() + program.loc + 1; // loc of plus 1 207 | plus1 = ((plus1n >= program.expressions.size()) ? NOTOKEN : program.expressions[plus1n].tktype); // set to zero if last expression 208 | } 209 | 210 | switch (t) { // perform based on token type 211 | case PLUS: // I'm sure there is an easier way to do this... 212 | v.val = std::to_string(first + second); 213 | break; 214 | case MINUS: 215 | v.val = std::to_string(first - second); 216 | break; 217 | case DIVISION: 218 | v.val = std::to_string(first / second); 219 | break; 220 | case MULTIPLICATION: 221 | v.val = std::to_string(first * second); 222 | break; 223 | case OPENBRACKET: 224 | if ((plus1 != IS) && (plus1 != NOT) && (plus1 != GREATER) && (plus1 != GREATEREQ) && (plus1 != LESS) && (plus1 != LESSEQ)) { 225 | int varn; 226 | find(program.thisScope.variables, program.expressions[program.loc-2].contents, &varn); 227 | 228 | sbsvar = program.thisScope.variables[varn]; 229 | 230 | switch(sbsvar.type) { 231 | case STRING: 232 | if ((index >= sbsvar.val.size()) || (index < 0)) { 233 | string fullexpr = sbsvar.name + "["; 234 | 235 | for (int n = 0; n < placeholders[0].expressions.size(); n++) // add full subscript to error details 236 | fullexpr += placeholders[0].expressions[n].contents; 237 | 238 | fullexpr += "]"; // add brackets for complete statement 239 | 240 | error(4, fullexpr); 241 | } 242 | 243 | v.type = INTEGER; 244 | v.val = sbsvar.val[index]; 245 | 246 | break; 247 | 248 | case LIST: 249 | if ((index >= sbsvar.vals.size()) || (index < 0)) { // out of range error 250 | string fullexpr = sbsvar.name + "["; 251 | 252 | for (int n = 0; n < placeholders[0].expressions.size(); n++) // add full subscript to error details 253 | fullexpr += placeholders[0].expressions[n].contents; 254 | 255 | fullexpr += "]"; // add brackets for complete statement 256 | 257 | error(4, fullexpr); 258 | } 259 | 260 | v = sbsvar.vals[index]; 261 | 262 | break; 263 | 264 | case INTEGER: // subscripts don't work on int or bool, so give error 265 | case STS_BOOL: 266 | error(2, sbsvar.name); 267 | break; 268 | } 269 | program.loc += placeholders[0].expressions.size(); 270 | 271 | break; 272 | } 273 | else 274 | program.loc -= 2; 275 | case IS: 276 | case NOT: 277 | case GREATER: 278 | case GREATEREQ: 279 | case LESS: 280 | case LESSEQ: 281 | // subtract 2 for condition function to get values 282 | if (dotCompare) program.loc -= 2; 283 | v.val = ((condition()) ? "true" : "false"); 284 | 285 | if (program.expressions[program.loc].tktype == TERNARY1) { 286 | /* 287 | For ternary, we can assume that it is structured like this: 288 | TOKEN | VALUE/UNKNOWN | TOKEN | VALUE/UNKNOWN 289 | -----------|---------------------------|-------------- 290 | ? | var | : | var 291 | 292 | as usual, these values can be anything, but getval() automatically fills in the gap so we don't have to do much here with different cases 293 | */ 294 | int _loc = program.loc; 295 | bool _val = toBool(v.val); 296 | stsvars primary, secondary; 297 | 298 | program.loc++; 299 | primary = getval(); 300 | program.loc = _loc; 301 | 302 | while (program.expressions[program.loc].tktype != COLON) program.loc++; 303 | program.loc += 2; 304 | secondary = getval(); 305 | program.loc = _loc; 306 | 307 | v.val = ((_val) ? primary.val : secondary.val); 308 | v.type = ((_val) ? primary.type : secondary.type); 309 | 310 | // exit ternary: 311 | while (program.expressions[++program.loc].t != ENDEXPR); 312 | } 313 | break; 314 | } 315 | 316 | break; 317 | } 318 | return v; 319 | } -------------------------------------------------------------------------------- /src/values/if.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "../interpreter/sts_interpreter.h" 3 | #include "sts_values.h" 4 | 5 | void ifs() { 6 | /* 7 | if statements are pretty easy to parse as they are always formated like this 8 | BUILTIN | VALUE/COMPARISON* | TOKEN 9 | --------|-------------------------|----------- 10 | if | var | { 11 | 12 | *The VALUE/EXPRESSION can be a bool literal, a variable, or a comparison. This is not determined here, but later in getval() 13 | */ 14 | 15 | program_t program_old = program; // store old program values for reuse 16 | program_old.loc++; 17 | 18 | program.loc = 0; 19 | program.expressions.clear(); 20 | 21 | while (program_old.expressions[program_old.loc].tktype != OPENCURL) { 22 | program.expressions.push_back(program_old.expressions[program_old.loc]); 23 | program_old.loc++; 24 | } 25 | 26 | program.expressions.push_back(program_old.expressions[program_old.loc]); 27 | bool expr = toBool(getval().val); 28 | 29 | program = program_old; 30 | 31 | if (expr) { 32 | program.loc++; 33 | newScope(); 34 | program.loc++; // get out of scope to check for else 35 | } 36 | else { 37 | program.loc++; 38 | 39 | scopedown(); 40 | 41 | if (program.expressions[program.loc+1].btn == ELSE) { 42 | /* 43 | This works because it parses the expression after else. 44 | This would be { or OPENCURL if it is a standard else statement and IF it it were an else if statement. 45 | */ 46 | program.loc += 2; 47 | newScope(); 48 | } 49 | } 50 | 51 | if (program.expressions[program.loc].btn == ELSE) { 52 | if (program.expressions[program.loc+1].btn == IF) 53 | while (program.expressions[program.loc - 1].tktype != OPENCURL) program.loc++; 54 | else program.loc += 2; 55 | 56 | scopedown(); 57 | } 58 | else if (expr) // subtract one if expression is true to compensate for next line of program 59 | program.loc -= 1; 60 | } 61 | -------------------------------------------------------------------------------- /src/values/random.cc: -------------------------------------------------------------------------------- 1 | #include "sts_values.h" 2 | #include 3 | #include 4 | 5 | #if (PLATFORM) 6 | #include 7 | #endif 8 | 9 | int genrandomintfromrange() { 10 | int range[2]; // range will store the min and max values 11 | 12 | program.loc++; 13 | 14 | range[0] = std::stoi(getval().val); 15 | program.loc++; 16 | range[1] = std::stoi(getval().val); 17 | 18 | #if (!PLATFORM) 19 | 20 | std::random_device randomd; 21 | 22 | std::mt19937_64 generate(randomd()); 23 | 24 | std::uniform_int_distribution<> dis(range[0], range[1]); 25 | 26 | return dis(generate); 27 | #else 28 | /* 29 | * This most likely uses more CPU than the Linux version, 30 | * but it is the best I can do until MinGW fixes mt19937_64 31 | */ 32 | { // in it's own scope to allow using namespace 33 | // not a bad idea as long as it is in a scope for only how long it is needed 34 | using namespace std::chrono; 35 | nanoseconds timens = duration_cast(steady_clock::now().time_since_epoch()); 36 | srand(timens.count()); 37 | } 38 | return rand() % range[1] + range[0]; 39 | #endif 40 | 41 | return 0; 42 | } 43 | 44 | bool randombool() { 45 | #if (!PLATFORM) 46 | std::random_device randomd; 47 | 48 | std::mt19937_64 generate(randomd()); 49 | std::uniform_int_distribution<> dis(0, 1); 50 | 51 | return dis(generate); 52 | #else 53 | { 54 | using namespace std::chrono; 55 | nanoseconds timens = duration_cast(steady_clock::now().time_since_epoch()); 56 | srand(timens.count()); 57 | } 58 | return rand() % 2; 59 | #endif 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /src/values/runfunc.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "../interpreter/sts_interpreter.h" 3 | 4 | void runfunc(int num) { 5 | program_t program_old = program; 6 | 7 | std::vector _variables = program.thisScope.variables; 8 | 9 | program_old.thisScope.variables.insert(program_old.thisScope.variables.end(), 10 | program_old.thisScope.functions.at(num).args.begin(), program_old.thisScope.functions.at(num).args.end()); 11 | 12 | program.function = num; 13 | program.expressions = program_old.thisScope.functions.at(num).contents; 14 | 15 | int argbegin = _variables.size(); 16 | 17 | if (program_old.thisScope.functions.at(num).args.size() > 0) { 18 | if (program_old.expressions[program_old.loc+1].tktype != ARROW) 19 | error(5, program_old.thisScope.functions.at(num).name); 20 | else { 21 | program_old.loc += 2; 22 | 23 | int argon = 0; 24 | 25 | while (true) { 26 | program_t _prog = program; 27 | program = program_old; 28 | 29 | program.thisScope.variables[argbegin + argon] = getval(); 30 | 31 | program_old = program; 32 | program = _prog; 33 | 34 | program_old.thisScope.variables[argbegin + argon].name = program_old.thisScope.functions.at(num).args[argon].name; 35 | 36 | program_old.loc += 1; 37 | if (program_old.expressions[program_old.loc].t == ENDEXPR) break; 38 | else if (program_old.expressions[program_old.loc].tktype == COMMA) { 39 | program_old.loc++; 40 | argon += 1; 41 | } 42 | } 43 | } 44 | } 45 | 46 | program.thisScope = program_old.thisScope; 47 | program.loc = 0; 48 | newScope(); 49 | 50 | program_old.thisScope = program.thisScope; 51 | program_old.thisScope.variables.erase(program_old.thisScope.variables.begin() + _variables.size(), program_old.thisScope.variables.end()); 52 | 53 | program = program_old; 54 | } 55 | -------------------------------------------------------------------------------- /src/values/sts_values.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef STS_VALUES_H_ 3 | #define STS_VALUES_H_ 4 | 5 | #include "../stormscript.h" 6 | 7 | void ifs(); 8 | 9 | void runfunc(int num); 10 | 11 | // find is overloaded to allow finding any of the main types easily 12 | bool find(std::vector vars, string query, int *num); 13 | bool find(std::vector functions, string query, int *num); 14 | bool find(std::vector types, string query, int *num); 15 | bool find(std::vector vars, string query, int *num); 16 | 17 | // random functions 18 | int genrandomintfromrange(); 19 | bool randombool(); 20 | 21 | 22 | // stsdec functions 23 | void declareFunc(); 24 | void define(); 25 | 26 | bool condition(); 27 | 28 | #endif // STS_VALUES_H_ -------------------------------------------------------------------------------- /src/values/stsdec.cc: -------------------------------------------------------------------------------- 1 | #include "../stormscript.h" 2 | #include "sts_values.h" 3 | 4 | void declareFunc() { 5 | program.thisScope.functions.push_back(stsfunc()); 6 | 7 | program.loc += 1; 8 | 9 | program.thisScope.functions.back().name = program.expressions[program.loc].contents; 10 | 11 | program.loc += 1; 12 | 13 | if (program.expressions[program.loc].tktype == ARROW) { 14 | program.loc += 1; 15 | 16 | while (true) { 17 | program.thisScope.functions.back().args.push_back(stsvars()); 18 | program.thisScope.functions.back().args.back().name = program.expressions[program.loc].contents; 19 | program.loc += 1; 20 | 21 | if (program.expressions[program.loc].tktype == OPENCURL) break; 22 | else if (program.expressions[program.loc].tktype == COMMA) program.loc += 1; 23 | } 24 | 25 | } 26 | program.loc += 1; 27 | 28 | int endreq = 1; 29 | 30 | while (endreq != 0) { 31 | if (program.expressions[program.loc].tktype == OPENCURL) endreq += 1; 32 | else if (program.expressions[program.loc].tktype == CLOSEDCURL) endreq -= 1; 33 | 34 | program.thisScope.functions.back().contents.push_back(program.expressions[program.loc]); 35 | 36 | program.loc += 1; 37 | } 38 | 39 | program.thisScope.functions.back().contents.pop_back(); // remove last line as it is just a closed curl 40 | program.loc -= 1; 41 | } 42 | 43 | std::vector 44 | listgen() { 45 | std::vector values; 46 | program.loc++; 47 | 48 | while (program.expressions[program.loc-1].tktype != CLOSEDBRACKET) { 49 | values.push_back(getval()); 50 | program.loc+= 2; 51 | } 52 | 53 | program.loc--; 54 | 55 | return values; 56 | } 57 | 58 | 59 | void define() { //variable declarations 60 | int num = program.thisScope.variables.size(); 61 | string name = program.expressions[program.loc].contents; 62 | 63 | if (find(program.thisScope.variables, name, &num)) { 64 | /* 65 | * If already defined, this changes the value of 66 | * the variable 67 | */ 68 | program.loc += 2; 69 | if (program.thisScope.variables.at(num).type != 'l') 70 | program.thisScope.variables.at(num).val = getval().val; 71 | else 72 | program.thisScope.variables.at(num).vals = listgen(); 73 | program.thisScope.variables.at(num).name = name; 74 | } 75 | else { 76 | program.thisScope.variables.push_back(stsvars()); 77 | program.loc += 2; 78 | 79 | if (program.expressions[program.loc].tktype != OPENBRACKET) 80 | program.thisScope.variables.back() = getval(); 81 | else { 82 | program.thisScope.variables.back().type = LIST; 83 | program.thisScope.variables.back().vals = listgen(); 84 | } 85 | 86 | program.thisScope.variables.back().name = name; 87 | } 88 | 89 | switch (program.thisScope.variables.at(num).type) { 90 | case STRING: 91 | program.thisScope.variables.at(num).length = program.thisScope.variables.at(num).val.size(); 92 | break; 93 | case LIST: 94 | program.thisScope.variables.at(num).length = program.thisScope.variables.at(num).vals.size(); 95 | break; 96 | } 97 | while (program.expressions[program.loc].t != ENDEXPR) program.loc += 1; 98 | } -------------------------------------------------------------------------------- /tests/argtest.sts: -------------------------------------------------------------------------------- 1 | func f => x, y { 2 | printl x; 3 | printl y; 4 | } 5 | 6 | 7 | n: 3; 8 | f => "hi", n; -------------------------------------------------------------------------------- /tests/classtest.sts: -------------------------------------------------------------------------------- 1 | type person { 2 | str name; 3 | int age; 4 | 5 | func birthday => years, div { 6 | y: years / div; 7 | age +: y; 8 | } 9 | 10 | init => nm, _age { 11 | name: nm; 12 | age: _age; 13 | } 14 | } 15 | 16 | person p => "bob", 30; 17 | 18 | printl p.name, " is " p.age; 19 | 20 | p.birthday => 20, 2; 21 | 22 | printl p.name, " is " p.age; -------------------------------------------------------------------------------- /tests/comptest.sts: -------------------------------------------------------------------------------- 1 | x: "hi"; 2 | y: "hi"; 3 | n: 3; 4 | d: true; 5 | 6 | if n is 3{ 7 | printl "x is 3"; 8 | } 9 | 10 | if d is false{ 11 | printl "Hi"; 12 | } 13 | else if n is 4{ 14 | printl "d is true"; 15 | } 16 | else{ 17 | printl n; 18 | } 19 | 20 | if x is y{ 21 | printl x, " is ", y; 22 | } -------------------------------------------------------------------------------- /tests/comptest2.sts: -------------------------------------------------------------------------------- 1 | #even though it changes nothing about the output, I think that it is smarter to use parentheses around ternary operations 2 | 3 | y: 0; 4 | x: 4; 5 | if y is 0 { 6 | printl (x greatereq 4) ? 10 : 3; 7 | } -------------------------------------------------------------------------------- /tests/concattest.sts: -------------------------------------------------------------------------------- 1 | x: 200; 2 | 3 | printl "$x is my favorite number"; -------------------------------------------------------------------------------- /tests/errortest.sts: -------------------------------------------------------------------------------- 1 | thisisnotacommand; -------------------------------------------------------------------------------- /tests/etc/example.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abbyonstott/StormScript/326ab0828f6011bfd82f3ce9454fd08729008802/tests/etc/example.txt -------------------------------------------------------------------------------- /tests/etc/readtest.txt: -------------------------------------------------------------------------------- 1 | hello world -------------------------------------------------------------------------------- /tests/etc/testmod.sts: -------------------------------------------------------------------------------- 1 | func hello { 2 | printl "Hello, World!"; 3 | } -------------------------------------------------------------------------------- /tests/foreachtest.sts: -------------------------------------------------------------------------------- 1 | colors: ["green", "yellow", "black", "blue", "black"]; 2 | animals: ["cat", "dog", "cow", "sheep"]; 3 | 4 | for color in colors { 5 | for animal in animals { 6 | printl "$color $animal"; 7 | } 8 | } -------------------------------------------------------------------------------- /tests/forlooptest.sts: -------------------------------------------------------------------------------- 1 | a: 0; 2 | b: 1; 3 | c: 0; 4 | 5 | for 25 { 6 | printl c; 7 | 8 | c: a + b; 9 | a: b; 10 | b: c; 11 | } -------------------------------------------------------------------------------- /tests/lengthtest.sts: -------------------------------------------------------------------------------- 1 | x: "hi"; 2 | y: ["hi", "there"]; 3 | 4 | printl x.length; 5 | printl y.length; -------------------------------------------------------------------------------- /tests/littest.sts: -------------------------------------------------------------------------------- 1 | if "this" is "this"{ 2 | printl "Test Succeded"; 3 | } -------------------------------------------------------------------------------- /tests/mathtest.sts: -------------------------------------------------------------------------------- 1 | n: 3; 2 | printl n; 3 | printl n-1; 4 | x: n*20; 5 | printl x, " ", x/3; -------------------------------------------------------------------------------- /tests/modtest.sts: -------------------------------------------------------------------------------- 1 | mod etc/testmod; 2 | 3 | hello; -------------------------------------------------------------------------------- /tests/outputs/argtest.sts.txt: -------------------------------------------------------------------------------- 1 | hi 3 2 | -------------------------------------------------------------------------------- /tests/outputs/classtest.sts.txt: -------------------------------------------------------------------------------- 1 | bob is 30 bob is 40 2 | -------------------------------------------------------------------------------- /tests/outputs/comptest.sts.txt: -------------------------------------------------------------------------------- 1 | x is 3 3 hi is hi 2 | -------------------------------------------------------------------------------- /tests/outputs/comptest2.sts.txt: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /tests/outputs/concattest.sts.txt: -------------------------------------------------------------------------------- 1 | 200 is my favorite number 2 | -------------------------------------------------------------------------------- /tests/outputs/errortest.sts.txt: -------------------------------------------------------------------------------- 1 | Error: thisisnotacommand is not a recognized command 2 | -------------------------------------------------------------------------------- /tests/outputs/foreachtest.sts.txt: -------------------------------------------------------------------------------- 1 | green cat green dog green cow green sheep yellow cat yellow dog yellow cow yellow sheep black cat black dog black cow black sheep blue cat blue dog blue cow blue sheep black cat black dog black cow black sheep 2 | -------------------------------------------------------------------------------- /tests/outputs/forlooptest.sts.txt: -------------------------------------------------------------------------------- 1 | 0 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 2 | -------------------------------------------------------------------------------- /tests/outputs/lengthtest.sts.txt: -------------------------------------------------------------------------------- 1 | 2 2 2 | -------------------------------------------------------------------------------- /tests/outputs/littest.sts.txt: -------------------------------------------------------------------------------- 1 | Test Succeded 2 | -------------------------------------------------------------------------------- /tests/outputs/mathtest.sts.txt: -------------------------------------------------------------------------------- 1 | 3 2 60 20 2 | -------------------------------------------------------------------------------- /tests/outputs/modtest.sts.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | -------------------------------------------------------------------------------- /tests/outputs/printtest.sts.txt: -------------------------------------------------------------------------------- 1 | Single string printl. Multple string printl with variable. Single string print. Multiple string print with variable. 2 | -------------------------------------------------------------------------------- /tests/outputs/privatemembers.sts.txt: -------------------------------------------------------------------------------- 1 | Tried to access private member x outside of type method 20 2 | -------------------------------------------------------------------------------- /tests/outputs/readtest.sts.txt: -------------------------------------------------------------------------------- 1 | hello world 2 | -------------------------------------------------------------------------------- /tests/outputs/returntest.sts.txt: -------------------------------------------------------------------------------- 1 | 3 2 | -------------------------------------------------------------------------------- /tests/outputs/whiletest.sts.txt: -------------------------------------------------------------------------------- 1 | 4 5 6 7 8 9 10 2 | -------------------------------------------------------------------------------- /tests/outputs/writetest.sts.txt: -------------------------------------------------------------------------------- 1 | hello, world 2 | -------------------------------------------------------------------------------- /tests/printtest.sts: -------------------------------------------------------------------------------- 1 | x: "string"; 2 | 3 | printl "Single string printl."; 4 | printl "Multple ", x, " printl with variable."; 5 | 6 | print "Single string print.\n"; 7 | print "Multiple ", x, " print with variable.\n"; -------------------------------------------------------------------------------- /tests/privatemembers.sts: -------------------------------------------------------------------------------- 1 | type test { 2 | private int x; 3 | int y; 4 | 5 | init => startingx { 6 | x: startingx; 7 | y: x + 10; 8 | } 9 | } 10 | 11 | test t => 10; 12 | 13 | printl t.y; 14 | printl t.x; -------------------------------------------------------------------------------- /tests/readtest.sts: -------------------------------------------------------------------------------- 1 | x: read "etc/readtest.txt"; 2 | printl x; -------------------------------------------------------------------------------- /tests/returntest.sts: -------------------------------------------------------------------------------- 1 | func returntest { 2 | return 3; 3 | } 4 | 5 | printl returntest; -------------------------------------------------------------------------------- /tests/whiletest.sts: -------------------------------------------------------------------------------- 1 | x: 3; 2 | y: 10; 3 | while x not y { 4 | x: x + 1; 5 | printl x; 6 | } -------------------------------------------------------------------------------- /tests/writetest.sts: -------------------------------------------------------------------------------- 1 | write "etc/example.txt" "hello, world"; 2 | printl read "etc/example.txt"; 3 | write "etc/example.txt" ""; --------------------------------------------------------------------------------