API |
|
![]() |
SCBScript - Intelligent Easy Script |
Screenshots |
|
![]() |
|
Introduction |
|
SCBScript is a parser and execution engine for a script language similar to JavaScript.
It is easy to implement and comes with a source code debugger. Since it is developed in C#, you can import and use C# objects and methods with it. |
|
Install |
|
In Visual Studio, go to the [Tools] menu, then select [NuGet Package Manager] - [Package Manager Console].
PM> Install-Package SCBScript |
|
Download |
|
API Reference |
|
Implementation Example |
|
It can be easily implemented as follows:
// Initialize system objects scbscript.SystemObjectManager.SetSystemObjectTypes(); // Add native class type for script scbscript.SystemObjectManager.AddClass(typeof(XXXX)); // Add native global methods class type for script scbscript.SystemObjectManager.AddMethods(typeof(XXX)); // Script string[] arguments = new string[] { ... }; Script script = new Script(arguments); // Set a script source if(script.SetScriptCodeFromFile(scriptSourcePath) > 0) { // Errors have been occurred foreach (var node in script.Notifies.AllNotifies) { Console.Error.WriteLine(node.Message); } System.Environment.Exit(-1) } // Compile a script if (script.Parse() != 0) { // Errors have been occurred foreach (var node in script.Notifies.AllNotifies) { Console.Error.WriteLine(node.Message); } System.Environment.Exit(-1) } Interpreter interpreter; if (isDebug) { // Run with debugger example interpreter = new Interpreter(script, true); interpreter.DebuggerPageIcon = "../html/test.png"; interpreter.DebuggerTitle = "SCBScript Example Debugger"; interpreter.OnDebuggerClosed = () => { Console.WriteLine("<<<< Debugger Closed >>>>"); }; interpreter.DebugDelegate = (SyntaxBase synatx, Interpreter inter, SStack[] stacks) => { }; interpreter.DebugOperation = DebugOperation.StepIn; if (!interpreter.Run()) { // Output errors foreach (var node in script.Notifies.AllNotifies) { Console.Error.WriteLine(node.Message); } End(-1); } } else { // Run interpreter = new Interpreter(script, false); if(!interpreter.Run()) { // Output errors foreach (var node in script.Notifies.AllNotifies) { Console.Error.WriteLine(node.Message); } End(-1); } } // Call script function example var func = script.GetGlobalVariable("sum"); if(func != null && func.Type.Type == STypes.Function) { var result = func.CallFunction(interpreter, new SValue[] { new SValue(script, 1), new SValue(script, 50) }, null); Console.WriteLine($"sum : {result}"); } // Valuate expression example var value = interpreter.GetExpressionResult("hs[\"klm\"]"); if(value != null) { Console.WriteLine($"hs[\"klm\"] : {value}"); } |
|
Script Example |
|
The script adopts a syntax similar to JavaScript, as shown below:
//Define value start = 1; end = 100; // Define function function sum(start, end) { s = 0; // For syntax for(i = start; i <= end; i++) s += i; // Assign in function start = 0; end = 0; // Return return s; } // Function call s0 = sum(start, end); printf("Sum(%d - %d) : %d\n", start, end, s0); // Interporation string start = 50; end = 150; printf($"Sum({start} - {end}) : {sum(start, end)}\n"); // Array ar = [ 1, 3, 5, 7, 9, 2, 4, 6, 8]; ar2 = [ 10, 11, 12, 13, 14, 15]; // Array conatnation ar3 = ar + ar2; printf('Array[2] : %d\n', ar2[2]); // Foreach array i = 0; foreach(item in ar3) { // Switch - case - match - default switch(item) { case 3: case 4: printf("@Array (%d) : %d\n", i, item); break; case 7: case 8: printf("#Array (%d) : %d\n", i, item); break; match $ >= 10 && $ < 13: printf("<Array (%d) : %d\n", i, item); break; default: printf("Array (%d) : %d\n", i, item); break; } i++; } // Parallel expansion assignment (a1, a2, aa[*]) = ar; printf($"a1 : {a1}, a2 : {a2}\n"); foreach(item in aa) { printf("Array aa : %d\n", item); } (bb[*], b2, b1) = ar2; printf($"b1 : {b1}, b2 : {b2}\n"); foreach(item in bb) { printf("Array bb : %d\n", item); } // Hash hs = { "abc" : 1, "def" : 2, "efg" : 3, "hij" : 4, "klm" : 5, "nop" : 6, "qrs" : 7, "tuv" : 8, "wxy" : 9, "z" : 10 }; v = hs["klm"]; printf("Hash [klm] : %d\n", v); v = hs.qrs; printf("Hash.qrs : %d\n", v); hs["123"] = 100; hs["456"] = 101; hs["789"] = 102; // Foreach hash foreach(item in hs) { printf("Hash [%s] : %d\n", item.key, item.value); } // Regular expressions var s0 = "abcdefg12345ABCDEFG67890"; if(s0 in *"[^0-9]+([0-9]+)[^0-9]+([0-9]+)") { printf("Regex match count : %d\n", $#); printf("Match all $$ : '%s'\n", $$); printf("Match group $1 : '%s'\n", $1); printf("Match group $2 : '%s'\n", $2); } if(s0 in *"([a-z]+)[^A-Z]+([A-Z]+)") { printf("Regex match count : %d\n", $#); printf("Match all $$ : '%s'\n", $$); for(var i = 0; i < $#; i++) { printf("Match group $[%d] : '%s'\n", i, $[i]); } } |
|
License |
|
Copyright SO-SOFT All rights reserved. The redistribution and use in unmodified binary form are permitted for personal or commercial use, provided the following conditions are met: |
|
Third Party Notices |
|
・lz4net Copyright (c) 2013-2017, Milosz Krajewski All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ・SharpZipLib The MIT License (MIT) Copyright (c)2022 ICSharpCode Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ・System.Data.HashFunction.xxHash ・System.Data.HashFunction.Interfaces ・System.Data.HashFunction.Core The MIT License (MIT) Copyright (c) 2014 Data.HashFunction Developers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ・System.Text.Json The MIT License (MIT) Copyright (c)2022 Microsoft Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
List of Distribution Approval Recipients |
|
The following websites are officially recognized and approved by SO-SOFT for the distribution of this software's files.
Please exercise caution when distributing this software on websites other than these, as there is a possibility that the installer files may have been tampered with.
|