How do I make a simple C# expression "pre-parser"?

G

Guest

In my application the user can configure automation-scripts by inserting
different "actions" into a "procedure". These different procedure- and
action-objects are all translated into C# code before execution.

One "action" type is an expression-evaluator. At the moment the expression
the user writes into the action is just inserted into the generated C# code
unchanged.

The problem is the variables in my system and in the "procedures"; they are
not just the basic .NET types but my own types with more properties and
methods.

This means that the expression for incrementing the variable "myHeight"
looks like this: (myHeight.Value)++

I would like the user to be able to write: myHeight++
and my "pre-processor" would then convert it to: (myHeight.Value)++

I could just run through the expression and replace every occurrence of a
variable name with: (varname.Value)
but that would also take any occurrences of a variable name inside a string
constant or an object property or method with the same name as a variable.

Any suggestions how I could do this?
- I have no experience with parser- or compiler-construction.

Cheers,
Jan
 
R

robert

Why not let your users add @ in front of all variables and introduce that as
a standard.
That should facilitate parsing the text.

Robert
 
G

Guest

That could be a way to make a simple solution. If I ever thought about that,
I completely forgot about it again.

Thanks for your input!
 
G

Guest

Thank you very much Robert. I will definately have a look at that.

The best solution would absolutely be the one my users like the most and my
personal preference is C++/C#/Java-syntax-like expressions.
That would also give the simplest code gereration for me.

Thanks again.
Jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top