473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
May 16 '07 #1
4 2729
Why not let your users add @ in front of all variables and introduce that as
a standard.
That should facilitate parsing the text.

Robert

"Jan" <j0****************@world.dkwrote in message
news:AC**********************************@microsof t.com...
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

May 16 '07 #2
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!

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

Robert
May 16 '07 #3
If you need a more robust solution, consider writing a parser. A simple
depth-first one, in C#, can be found at
http://www.frontiernet.net/~fredm/dps/Contents.htm , chapter 3. A more
robust one is at
http://www.frontiernet.net/~fredm/pa...istWebPage.htm .

If these are a little too complex, consider a recursive descent parser.
They are simple to write:
http://www.cs.wm.edu/~noonan/java/parsing/
"Jan" <j0****************@world.dkwrote in message
news:02**********************************@microsof t.com...
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!

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

Robert

May 16 '07 #4
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

"Fred Mellender" wrote:
If you need a more robust solution, consider writing a parser. A simple
depth-first one, in C#, can be found at
http://www.frontiernet.net/~fredm/dps/Contents.htm , chapter 3. A more
robust one is at
http://www.frontiernet.net/~fredm/pa...istWebPage.htm .

If these are a little too complex, consider a recursive descent parser.
They are simple to write:
http://www.cs.wm.edu/~noonan/java/parsing/
"Jan" <j0****************@world.dkwrote in message
news:02**********************************@microsof t.com...
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!

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

Robert


May 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: kelvin | last post by:
How do I use get data in a url sent from aform on an other page. All i want to do is take this data and display it on the page. thanking you in anticipation
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
81
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there...
32
by: Stephen | last post by:
Is there a standard way to remove the warning that a C compiler might produce from the statement: if (a = b) {} I don't want to do: if ((a = b) != 0) {} Because my "a = b" is actually...
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
48
by: mahurshi | last post by:
I am new to c++ classes. I defined this "cDie" class that would return a value between 1 and 6 (inclusive) It runs fine and gives no warnings during compilation. I was wondering if you guys...
1
by: Alex Maghen | last post by:
I'm taking text from a multi-line TextBox into a database. Then, on other pages, I'm displaying that text as read-only. But the problem is, when I set the Text property of a Label control to that...
30
by: josh | last post by:
Hi all, what does it meaning that strange sintax (look at the object :) ? if I have i.e. array.length I can use array. and is it IE/Firefox compatible??
13
by: hn.ft.pris | last post by:
Hi: I have the following simple program: #include<iostream> using namespace std; int main(int argc, char* argv){ const double L = 1.234; const int T = static_cast<const int>(L); int arr;
3
by: shammika | last post by:
Hi, can you give more details about the Pre fix & Post fix of java with examples.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.