vassilych / cscs

CSCS: Customized Scripting in C#
MIT License
169 stars 49 forks source link

Love it but Missing doc #4

Open michalss opened 6 years ago

michalss commented 6 years ago

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

vassilych commented 6 years ago

Hi Michal,

Thanks for the nice words! There is no doc yet, but you can check out a few CSCS examples at https://github.com/vassilych/cscs/tree/master/cscs/bin/Debug/scripts

There is also a repository for mobile development in CSCS for iOS and Android (via Xamarin): https://github.com/vassilych/mobile

Also, you can check out a free E-book describing CSCS: https://www.syncfusion.com/ebooks/implementing-a-custom-language

And a few articles: http://msdn.microsoft.com/magazine/mt632273 http://msdn.microsoft.com/magazine/mt829272 http://www.codemag.com/Article/1607081/How-to-Write-Your-Own-Programming-Language-in-C# http://www.codemag.com/Article/1711081/Developing-Cross-Platform-Native-Apps-with-a-Functional-Scripting-Language

Thanks and looking forward to your feedback, Vassili

michalss commented 6 years ago

Hello,

Still not sure how to add custom command and his function. :(

In this article : http://www.codemag.com/Article/1607081/How-to-Write-Your-Own-Programming-Language-in-C# , i did try and it works ok, but it is a bit different then this on git.

What i did:

Add contant in Constants.cs

Then add my own function class in FunctionsOS.cs

And then register it in Interpreter. But keep saying cannot parse it :(.... Can you please write some doc how exactly to add it pls ? I was trying to implement ping as example..

Not sure what else need to be done, i was thinking this is all. Also it would be great to explaination if want to add custom function with more then 1 para..

Getting this : Couldn't parse [ping"127.0.0.1"] in StringOrNumber

Thx a lot

michalss commented 6 years ago

Also found the bug, once i assing string its print it to console output why ? example: $ip = "127.0.0.0"; will print ip to console, but it is not wanted to work like this..

michalss commented 6 years ago

Another bug: if else does not work.. Couldn't parse [else] in StringOrNumber

vassilych commented 6 years ago

Hi,

--> Getting this : Couldn't parse [ping"127.0.0.1"] You should use parentheses, like in ping("127.0.0.1"). It's possible to have a function without parentheses, but more work is involved, see e.g. the implementation of the "return" statement.

--> example: $ip = "127.0.0.0"; will print ip to console, but it is not wanted to work like this.. Don't use dollar sign with variables, use just ip = "...";

--> if else does not work.. Couldn't parse [else] in StringOrNumber There is no "if else" construct. Use "elif" instead (like in Python). Also, "if", "elif", and "else" all require curly brackets, like in if (a>0) {print("hi"); }

Also, take a look at the source code how a simple function is implemented, e.g. sin().

All the best, Vassili

michalss commented 6 years ago

hmm well,

I have to say it does not work at all.

Pls try it yrself. It is not work... BTW in your examples u have used if else commands, look at here: https://github.com/vassilych/cscs/blob/master/cscs/bin/Debug/scripts/if_while_bool.cscs

image

image

Another thing is, output result is in revers order :(...

vassilych commented 6 years ago

You are using elif instead of else. "elif" is used instead of "else if" in a condition. Also the functions like print must have arguments in parentheses. Here is the working code:

ip = "127.0.0.1"; if (1==1) { print("OK"); } else { print("Not OK"); } print(ip);

michalss commented 6 years ago

Ok thx all working now. Another question how can i concat string pls ?

Example:

machine = import(); file_to_check = "\"; file_to_check += machine; file_to_check += "\c$\Program Files\application.exe";

print(file_to_check);

michalss commented 6 years ago

i cannot use "\" this always get me cannot parse it.. :( But is there a way to make it work ?

vassilych commented 6 years ago

You can concatenate strings just with a "+", e.g.: a = "Hello " + "World";

file_to_check = "\"; is not a valid string (in any language). If you want to include a quote into the string, it must be: file_to_check = "\""; If you want to have a backslash, you must use another backslash, e.g. file_to_check += "\\c$\\Program Files\\application.exe";

michalss commented 6 years ago

No my point was to use "\\" i need to save into variable double backslash..

vassilych commented 6 years ago

ah, ok, then use file_to_check = "\\"; for a backslash and file_to_check = "\\\\"; for a double backslash.

michalss commented 6 years ago

Wrong parse, it wont take it.. :(

Couldn't parse ["\\\\";] in StringOrNumber

vassilych commented 6 years ago

Cut and paste the whole code snippet that doesn't work for you and explain what final strings you expect - then it should be easy to fix.

michalss commented 6 years ago

This , but not matter what it wont parse it in any case when i use even single \

\\machine\c$\Program Files\Company\Client\app.exe

and this i want to save it into variable

vassilych commented 6 years ago

x = "\\\\machine\\c$\\Program Files\\Company\\Client\\app.exe";

michalss commented 6 years ago

No it does not work as excepted. Machine is variable string with ip or pc name in it..

x = "\\"; x += machine; x += "\c$\Program Files\Company\Client\app.exe";

print(x);

return cannot parse

michalss commented 6 years ago

Have you find the solution for this pls ?

vassilych commented 6 years ago

Just look at the examples I pasted in this thread. For the one that you need now the correct code is:

a="\\\\machine\\c$\\Program Files\\Company\\Client\\app.exe"; print("a=", a);

You just always need to protect a backslash with another backslash.

michalss commented 6 years ago

No it does not work try it pls... :( it is a bit frustrating

machine = "127.0.0.1";

a = "\\\\machine\\c$\\Program Files\\Company\\Client\\app.exe"; print("a=", a);

It will print this: a=\\machine\c$\Program Files\Company\Client\app.exe

but expected result should be đź‘Ť a=\\127.0.0.1\c$\Program Files\Company\Client\app.exe

So it does not work at all...

vassilych commented 6 years ago

How would it know that the "machine" is not a constant but a variable? You should do this:

machine = "127.0.0.1"; a = "\\\\"+ machine + "\\c$...";

michalss commented 6 years ago

Well i have try this of course, giving error during the parsing. Just pls try it on your own. it wont work. No matter ill try still could not parse it. But if i use this / it works and i can save it in variable..

michalss commented 6 years ago

ok officially try everything, u cant simply conecat "\\" + machine... there is no way to do it..

ndmuratsahin commented 6 years ago

Hi Vassilych, It's great job. Thanks for your all description. How can I implement to run multiple scripts in the same code. As I read your code, As I understand I can't create a new class for every script file because local variables are hold in static variables.

Thanks again,

Kind Regards,

Murat

vassilych commented 6 years ago

Hi Murat,

Thanks for kind words! But I don't think I quite get what you mean. Could you elaborate? Also, for instance, how can you run multiple scripts, say in Python?

Thanks, Vassili

ndmuratsahin commented 6 years ago

Hi Vassili, I mean that I want to run some scripts at the same application. But I don't want that the variables values couldn't be mixed ? As I see that, I can't create independent script interpreter classes in the same application. How can I do that? Local Variables and Global Functions are held in ParserFunctions class but they are global variables and doesn't hold in a class. I examine the code but I couldn't find an easy method to carry the local and global variables in a class.

Do you have any advice for this?

Thanks,

Murat

ndmuratsahin commented 6 years ago

Hi Vassili, Any news on this pls ?

vassilych commented 6 years ago

Hi Murat,

Yes, it has been completed. If you define variables, like c=1; c will be global, as before. But if you want to define them locally, just in one file, do DefineLocal(varName, initValue); e.g.:

DefineLocal("myVar", 1); or DefineLocal("x"); // x will be an empty string by default.

Then as long as you use myVar or x, it will be in the local scope only...

By the way, you can also use a debugger with CSCS and also a REPL evaluator with CSCS with Visual Studio Code. See CSCS Debugger and CSCS REPL for details.

Cheers, Vassili

ndmuratsahin commented 6 years ago

Hi Vassili, I try to understand. In the script user should define the variable with DefineLocal("x) command. So can I run the same script in different threads separately?

Many thanks for your help.

Kinds,

Murat

vassilych commented 6 years ago

Hi Murat,

No, running exactly the same script file in multiple files is not supported yet. And yes, DefineLocal("x") will define a variable to be used just in a particular script file (so any changes to it in that file won't be visible outside). Can you describe a scenario you had in mind, when you mentioned: "run the same script in different threads separately"?

Thanks, Vassili

ndmuratsahin commented 6 years ago

Hi Vassili, Thanks for your answer. I am sorry for my late feedback. Now I am on holiday :)

I mean that I would run several scripts in one application. So these scripts can run independently and each script holds their values independently.

I want to use Interpreter as a class. For each script, I would create a new Interpreter class and I can use them independently.

Is it clear?

Thanks, Murat

vassilych commented 6 years ago

Hi Murat,

Yes, your point is clear and the ask is reasonable. Unfortunately, this is not supported yet, but it would be a good idea to implement (but it would take rather a long time, at least a few months)... At the moment I am sure that there should be some workarounds for this... I could offer you probably a workaround if you describe more details of a problem that you are trying to solve...

Best, Vassili

ndmuratsahin commented 6 years ago

Hi Vassili, Thanks for your positive answer. I can wait for a couple of months :) In the beginning, I can continue work without this feature.

Many Thanks,

Murat

gitfreshfish commented 5 years ago

Dear Vassili,The following example : b=-2;print(-b);Couldn't parse [-b] in StringOrNumber. It seems scsc doesn't Identify variable b, though it can use print(-1*b) instead。how to fix and make the problem simpler? Thanks

vassilych commented 5 years ago

Hi there, Thanks a lot for this bug report! It has been fixed and checked in. Please check it out! Best, Vassili

gitfreshfish commented 5 years ago

Dear Vassili, I define a function like this : UserFunction("Info",{100,0},{200,0},23.3). The problem is CSCS doesn't parse the arguments correctly, "List args = script.GetFunctionArgs();" returns 6 arguments (only 4 actually ). I mean CSCS goes some problem when parsing direct array arguments. of course,U can define "a={100,0};b={200,0}; UseFunction("Info",a,b,23.3)" instead, and it can work correctly. Could this little bug be fixed ? Many Thanks,

vassilych commented 5 years ago

Hi there, fixed with the latest check in! Cheers, Vassili