Q
Q
qwead2017-12-12 17:03:46
C++ / C#
qwead, 2017-12-12 17:03:46

A C# program that executes ("possibly interprets") another program. Is it possible to?

Is it possible to implement such a program that could read files of a certain format and execute instructions written in them?
well for example:
Main.cs :

var answer = Console.ReadLine();
if (answer == "1") {
    interpete("./subprograms/first.prog");
}

./subprograms/first.prog
__this subroutine prints the message "enter X" and prints the square of that number to the console__

And so that you can add these subroutines for the main program, without interfering and recompiling the main program (Main)?
At the moment, there is such a simple project:
https://github.com/DailyDDose/patterns
And I would like to add other subroutines to it in a separate folder in ./src and at the same time not touch the files that are in the root of the project, namely (BaseProgram.cs, Executor.cs, Program.cs)
UPD 1: Is it really necessary to pull some lua ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
#
#, 2017-12-12
@qwead

you can pull js:
https://github.com/tjanczuk/edge
https://github.com/nilproject/NiL.JS
you can pull F#
https://docs.microsoft.com/en-us/dotnet/fsharp /tut...
and even C# itself
https://msdn.microsoft.com/ru-ru/magazine/mt614271.aspx
https://habrahabr.ru/post/170385/
... and so on..
it's about " scripting"...
... and " dynamic compiling and loading C# " is generally a fucking topic in search engines

A
Alexander, 2017-12-12
@alexr64

Is it possible to implement such a program that could read files of a certain format and execute instructions written in them?

Can.
Don't you know yourself? Read the file, parse it into words, execute commands depending on the words.
And if you want the ability to attach plugins to your program, then look towards dynamic loading of assemblies . Describe in interfaces what the plugins should look like and what services you provide to the plugins. Good luck.

D
denismaster, 2017-12-12
@denismaster

lua, ironpython.
For something of your own - write an interpreter based on the grammar of your language)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question