cscs icon indicating copy to clipboard operation
cscs copied to clipboard

Love it but Missing doc

Open michalss opened this issue 7 years ago • 37 comments
trafficstars

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

michalss avatar May 14 '18 09:05 michalss

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

vassilych avatar May 14 '18 17:05 vassilych

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 avatar May 23 '18 05:05 michalss

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 avatar May 23 '18 07:05 michalss

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

michalss avatar May 23 '18 07:05 michalss

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

vassilych avatar May 23 '18 17:05 vassilych

hmm well,

I have to say it does not work at all.

  • elif does not work

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 :(...

michalss avatar May 24 '18 05:05 michalss

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);

vassilych avatar May 24 '18 11:05 vassilych

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 avatar May 25 '18 13:05 michalss

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

michalss avatar May 26 '18 21:05 michalss

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";

vassilych avatar May 27 '18 13:05 vassilych

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

michalss avatar May 27 '18 13:05 michalss

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

vassilych avatar May 27 '18 15:05 vassilych

Wrong parse, it wont take it.. :(

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

michalss avatar May 27 '18 21:05 michalss

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.

vassilych avatar May 28 '18 19:05 vassilych

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

michalss avatar May 29 '18 06:05 michalss

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

vassilych avatar May 29 '18 22:05 vassilych

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 avatar May 30 '18 13:05 michalss

Have you find the solution for this pls ?

michalss avatar Jun 08 '18 05:06 michalss

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.

vassilych avatar Jun 08 '18 11:06 vassilych

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...

michalss avatar Jun 18 '18 09:06 michalss

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$...";

vassilych avatar Jun 18 '18 20:06 vassilych

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 avatar Jun 18 '18 21:06 michalss

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

michalss avatar Jun 20 '18 10:06 michalss

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

ndmuratsahin avatar Jul 13 '18 16:07 ndmuratsahin

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

vassilych avatar Jul 15 '18 21:07 vassilych

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 avatar Jul 16 '18 08:07 ndmuratsahin

Hi Vassili, Any news on this pls ?

ndmuratsahin avatar Jul 27 '18 12:07 ndmuratsahin

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

vassilych avatar Jul 30 '18 17:07 vassilych

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

ndmuratsahin avatar Aug 06 '18 19:08 ndmuratsahin

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

vassilych avatar Aug 07 '18 02:08 vassilych