Creating a simple scripting language in C#
I need to create a very simple scripting language, as an evolution of a macro language (where placeholders were present and were exchanged for the realdata) which is based essentially on statements that need to be executed in order. I need to support nesting of statements and maybe possibly if conditions.
I think I need a parser to properly detect the statements
For example one statement could be:
Input("Message"=#Clipboard())
开发者_StackOverflow中文版In this case, I would need to execute the #Clipboard() statement first and then the #Input.
Any suggestion of what's the approach for it? I guess I need to contruct a tree and execute it. Thanks.
See my answer to a similar question here:
Basically, you parse your string using Postfix Notation.
Also, if you are going to use something more complex, look into building a Recursive Descent Parser. Eric White's blog has a great set of articles on the topic.
精彩评论