vassilych / cscs Goto Github PK
View Code? Open in Web Editor NEWCSCS: Customized Scripting in C#
License: MIT License
CSCS: Customized Scripting in C#
License: MIT License
Will namespaces be added to the program? as far as other functions like that?
Hi.
I'm making an editor for my own script and I want to integrate the debugger with it without using TCP but direct interaction with the Debugger class.
I was following the code to do so and I found that part of the parsing for the debuggerserver is within the Debugger class, that isn't as neat as it should be.
I suggest that the the parsing of that is within the DebuggerServer or client, and the Debugger class has all the functions to do the operations without any parsing as I want to use it.
Also it seems that it can only Debug existing files and not in memory code, that is quite annoying as I would have to save the file each time I'm debuging and I could easily pass the block of code to debug without having to specify any file.
Best regards.
Hello, I really like your idea of a custom language and I have tried to integrate cscs in unity, the way described in your article. But I have some problems getting my code running. the following code:
class MyMessageBusCallbackClass
{
MyMessageBusCallbackClass(gameApiProxy)
{
m_messageBusProxy = gameApiProxy.GetMessageBusProxy();
}
function ReceiveMessage()
{
messageQueue = m_messageBusProxy.GetMessageQueue(this, "WelcomeMessage");
welcomeMessage = messageQueue.DequeueMessage();
DebugLog("Callback from Message Bus: " + welcomeMessage.WelcomeMessage);
}
}
GameApiProxy = CreateGameApiProxyObject();
MessageBusProxy = GameApiProxy.GetMessageBusProxy();
MyMessageBusCallback = new MyMessageBusCallbackClass(GameApiProxy);
MessageBusProxy.SubscribeToMessage("MyMessageBusCallback", "WelcomeMessage");
Doesnt work as I thought it would.
The global Message bus proxy works as intented but the "this" keyword and the message bus proxy in the class doesnt seem to work. The Function "GetMessageQueue" doesnt get founded. Any idea why? When I use the global "MessageBusProxy" It works.
Hello,
is it possible to get a function arg by index ?
I would like create an IF function like excel.
IFELSE( [condition] , [if true action] , [if false action] )
the problem is, if I use GetFunctionArgs all args will be interpreted and this exemple "IFELSE( 1 != 1 , 1 / 0 , "ok")" the divided by zero will be catch.
the must will be to test fisrt param, if it return 0 the second param will not be interpreted only the third
Exemple
`
//get condition
var arg = script.GetFunctionArgByIndex(indexParam: 0);
var condition = Utils.GetSafeString(arg, 0);
if (condition == "1")
{
arg = script.GetFunctionArgsIndex(indexParam: 1);
string actionIfTrue = Utils.GetSafeString(arg, 0);
return new Variable(actionIfTrue);
}
else
{
arg = script.GetFunctionArgsIndex(indexParam: 2);
string actionIfFalse = Utils.GetSafeString(arg, 0);
return new Variable(actionIfFalse);
}
`
I tried to create the GetFunctionArgsIndex and it work with this IFELSE( 1 != 1 , 1 / 0 , "ok") but not with that
IFELESE ( functA(x) * functB(y) != 0 , 3 - 10 * Round( 1 / 0 ) , Ceil(0.4))
`
public static List GetFunctionArgsIndex(ParsingScript script,
char start, char end, Action outList, int indexParam )
{
List args = new List();
bool isList = script.StillValid() && script.Current == Constants.START_GROUP;
if (!script.StillValid() || script.Current == Constants.END_STATEMENT)
{
return args;
}
ParsingScript tempScript = script.GetTempScript(script.String, script.Pointer);
if (script.Current != start && script.TryPrev() != start &&
(script.Current == ' ' || script.TryPrev() == ' '))
{ // Allow functions with space separated arguments
start = ' ';
end = Constants.END_STATEMENT;
}
// ScriptingEngine - body is unsed (used in Debugging) but GetBodyBetween has sideeffects
#pragma warning disable 219
string body = Utils.GetBodyBetween(tempScript, start, end);
#pragma warning restore 219
// After the statement above tempScript.Parent will point to the last
// character belonging to the body between start and end characters.
int index = 0;
while (script.Pointer < tempScript.Pointer)
{
if (index == indexParam)
{
Variable item = Utils.GetItem(script, false);
args.Add(item);
break;
}
else
{
Parser.Split(script, Constants.NEXT_OR_END_ARRAY);
}
if (script.Pointer < tempScript.Pointer)
{
script.MoveForwardIf(Constants.END_GROUP);
script.MoveForwardIf(Constants.NEXT_ARG);
}
else if (script.Pointer > tempScript.Pointer)
{
script.MoveForwardIf(Constants.NEXT_ARG);
}
if (script.Pointer == tempScript.Pointer - 1)
{
script.MoveForwardIf(Constants.END_ARG, Constants.END_GROUP);
}
index++;
}
if (script.Pointer <= tempScript.Pointer)
{
// Eat closing parenthesis, if there is one, but only if it closes
// the current argument list, not one after it.
script.MoveForwardIf(Constants.END_ARG, end);
}
script.MoveForwardIf(Constants.SPACE);
//script.MoveForwardIf(Constants.SPACE, Constants.END_STATEMENT);
outList(isList);
return args;
}
`
Can you help me, please ?
You should add the most trivial example of creating a C# application that parses and executes a CSCS script to the readme.md file.
Doing some testing I notice the following. If you debug this code line by line. After entering the if and executing x++; it will jump to x=0; executing the print("x"); but not stopping with the debugger to that line.
`x = 1;
x++;
if (x > 1) {
x++;
}
print("x");
x=0;
`
Here is a demostration:
https://gyazo.com/c2b55dab06b1008283e4558a72d8a685
How would compiling to exe look/work?
Hi
why are you using please?
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> in the project ?
@vassilych pls help
Hello Vassily,
I have a question about scope of this interpreter. I wrote a script
i = 0;
function f()
{
i = 1;
print(i);
}
print(i);
f();
print(i);
And expect get output
0 1 0
But it returned
0 1 1
Is it possible to let interpreter take care of scope by itself?
Regards,
Adam
HI,
arr=["a","b"];
sintra["List"]=arr;
sintra["ActionType"]="Extract";
Is there any equivalent in c# to return this exact format from : ParserFunction please ? I cannot make it work ... :( also i cannot return from ParserFunction List... Simply say i need to return back to cscs complex object from c#. Something similar to..
returnData=SomeFunction
print(returnData["type"]); // this would be string
print(returnData["list"]); // this would be array
Try running the following script:
set(x,0);
print("x is; ",x);
Expect output: "x is; 0"
Actual output: "x is;"
Note the 0 was lost.
Trying to print "//" results in a can't extract token error.
(Note I found this from your MSDN version of this code. I haven't tried with the GitHub source. Apologies if you've already fixed it.)
I am interested to render TeX mathematics equation on Unity game engine like TeXDraw as well as on web browsers like MathJaX.
Is it worth learning cscs for developing TeX renderers above? Or I am in a wrong learning path?
Hi, I recently discovered your project, it's incredible and very inspiring, but I have a question, how can I remove the semicolon at the end of the instructions without breaking the algorithm or at least making it optional for when I want to write everything on the same line? can you help me?
Hi, i would like to import value from my selected source once i run the script, somewhere from my code. For example from listview or grid? Like i select something and get value from it and save it as cscs variable before any commands start process. Same for exporting variable, so example, saved some variable from cscs and i want to export it back to my code as variable. Can this be done pls ?
Thx
First of all, the job you have done is really fantastic.
For a proof of concept, I'm trying to extend your code to work with other types of Variables like series but the same question is valid for other Variable too.
If I develop a new function to create a new Series Variable I can do a script like this
a=CreateSeries(value1, value2 ecc.)
and the "a" variable is of type Series.
Now if I try to execute a script like b=a+1 the interpreter try to merge a and 1 but the Merge between Series and Number does not exist in the Parser.cs
Is there a method to extend the Merge capabilities as we do with the functions and modules?
I know that I could develop a new function like AddSeriesAndNumber with two parameters Serie and a Number but use the standard operator like + / ecc. would be very useful
thanks again for the great job
Hello, I think I found a new error while debugging, in fact there are 2 errors:
https://gyazo.com/1aa6094c8b440dd08b449c3bfde36755
Check this video,
When debugging, when the debugger enters the FOR, it should go back to the for line as it has an assignation and then go to the inside block, in this case, it will always mark the print(i) but not the assignation.
Also, after finishing the for, for some reason it enter the else of the IF above. Which is more important bug.
Here is the code:
`x = 1;
x++;
if (x < 10) {
for (i = 1; i < 10; i++) {
print(i);
}
} else {
print("hola2");
}_`
Hello sir
thank you for the cool work. I have been looking for this, originally found the mdsn articles...
I have a project that deals with financial data. I have projects, cashflows, etc.
I want to be able to let the user do some basic scripting and say 'this instance should be the sum of those things...' etc.
i originally pulled the code off msdn. After thinking about a lot of approaches... embedding delegates, i decided the most straight forward way was to make the parser not be a singleton.
Instead, i make a parser instance, and pass data into that, then all the functions have access to the parser.
i considered passing data into the singleton, but figured it was a matter of time before two scripts walked on each other. the data would essentially be a global.
I ran into an issue w/ the msdn code and found this github.
I am going to do some testing and make sure i dont have the same basic problem here.
Assuming that checks out, how would you suggest integrating host project data?
I see there is one other issue that essentially asking for the same thing.
Dear Dev,
I have to say i love this code, best ever im glad to use it in my projects, however what im missing is examples how exactly use all of commands. It would be enought just make sample for each command. And how to integrate own commands..
Thx
Line:
using static SplitAndMerge.ParserFunction;
inside Precompiler.cs gives error: 'static' is a keyword
VS 2012
Thanks
Hi,
The following script code snippet fails with a null exception.
x.a = 1;
myList =
{
{x, x},
{x, x}
};
print(myList[0][0].a); // This works fine
print(myList[0][0].a + myList[0][0].a); // This fails
print((myList[0][0].a) + (myList[0][0].a)); // This fails also
for(item : myList)
{
print(item[0].a);// This fails also
}
I tried to forward Constants.TOKEN_SEPARATION
to this function call in Functions.Flow.cs Line 1630:
m_propName = Utils.GetToken(script, Constants.NEXT_OR_END_ARRAY);
By doing this all the print statements before the for loop work fine. But the statement in the for loop still fails.
Hello,
is it possible to raise only this method when I call my custom function ?
` protected override async Task EvaluateAsync(ParsingScript script)
{
List args = script.GetFunctionArgs();
Utils.CheckArgs(args.Count, 1, m_name);
var url = Utils.GetSafeString(args, 0);
Variable results = await HttpGet(url);
return results;
}`
Thanks :)
Run the following script:
set(a(0),3);
set(a(1),2);
print(pow(a(0),a(1)));
print(a(0)):
print(a(1));
Expect output to be:
9
3
2
Actual result:
9
3
(what happened to the 2?)
Another example actually runs into a parser error (which is how I found this bug).
Run this script:
set(a(0),3);
set(a(1),2);
print(pow(a(0),a(1)));
while(1==1)
{
print(a(0)):
print(a(1));
}
Expect: some kind of infinite loop but whatever.
Actual: parser error: "Couldn't parse token [}]"
I worked around this in my script by setting two variables x and y to a(0) and a(1). That works fine.
Is there a more complete tutorial to build a language like cscs or others from the ground up? It just seems harder then it needs to be to create a language, I know most people don't like to spoon feed others but there is no good way to learn because all information is scattered.
I'm reading your book Implementing a custom language succinctly
. What I wished is a language which have much error reporting functionality. When users write a bad
cscs file and run them, they want to know where the errors come from. I think that's very import for the cscs script users.
Could you please give some hints on how to implement this functionality?
It's much better if you could add this functionality to the source.
Hi, thx for your great job, and I have two questions about how to debug cscs script:
Hello,
Are you planning to release CSCS as a NuGet package anytime soon ?
If one already exists, can you officialy link it ?
Thanks !
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.