473,774 Members | 2,252 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to "overload" AND with &

I am making a script parser and I need to interpret the word AND and
"replace" it with an &, so that it can be compiled at runtime with the
C# compiler.

My script would read e.g: if( (iCounter1 < 20) AND (iCounter2 <
iCounter1) )

How can I make the compiler understand that AND means &? (or means &&)

I do not want to use the Replace("AND"," &") on the string I read,
because this gives me some validation implementation which I want to
avoid.

I have seen some nasty operator overloads of ** doing what Math.Pow
does and I hope there could be a way to do a reverse operator overload
of some kind on the AND to return &. (or &&)

Can I define an operator called AND which would be the same as & .....?

I have looked at the opCode-thing but found nothing.

Hmm, hope somebody has a good answer to this one. Any input is more
than welcome.
Thanks in advance.

Jan 4 '07 #1
3 1432
Hi,

If it's the token "AND" that your require for "&&" functionality then you'll
have to look for it when you parse the line of code. In other words, your
parser must expect an operator at the current position in the string, which
must be either AND or OR, for example. Any other value should throw an
exception.

Note: You have to determine whether you really mean & or && since they are
different. I assume it's actually the boolean && that you want.

Instead of creating your own scripting language, it might be better to
create a sandboxed AppDomain in which to compile and load the code, as is.
That way any .NET language could be chosen, even JScript.NET.

--
Dave Sexton
http://davesexton.com/blog

"Kim Stubberup" <st*******@gmai l.comwrote in message
news:11******** *************@s 80g2000cwa.goog legroups.com...
>I am making a script parser and I need to interpret the word AND and
"replace" it with an &, so that it can be compiled at runtime with the
C# compiler.

My script would read e.g: if( (iCounter1 < 20) AND (iCounter2 <
iCounter1) )

How can I make the compiler understand that AND means &? (or means &&)

I do not want to use the Replace("AND"," &") on the string I read,
because this gives me some validation implementation which I want to
avoid.

I have seen some nasty operator overloads of ** doing what Math.Pow
does and I hope there could be a way to do a reverse operator overload
of some kind on the AND to return &. (or &&)

Can I define an operator called AND which would be the same as & .....?

I have looked at the opCode-thing but found nothing.

Hmm, hope somebody has a good answer to this one. Any input is more
than welcome.
Thanks in advance.

Jan 5 '07 #2
>
Note: You have to determine whether you really mean & or && since they are
different. I assume it's actually the boolean && that you want.
& works also for booleans, it's an "AND" without short-circuit
evaluation, so both sides are always evaluated (whereas && only
evaluates the second expression when the first returned true).

and for completeness: & for int's is a bitwise-AND

Hans Kesting
Jan 5 '07 #3
Hi Hans,

True, but that doesn't mean that he can use either one arbitrarily. If he's
designing a language he has to choose a mapping for AND to && or &, but
obviously it can't be both - they are different.

--
Dave Sexton
http://davesexton.com/blog

"Hans Kesting" <ne***********@ spamgourmet.com wrote in message
news:mn******** *************** @spamgourmet.co m...

Note: You have to determine whether you really mean & or && since they
are different. I assume it's actually the boolean && that you want.

& works also for booleans, it's an "AND" without short-circuit evaluation,
so both sides are always evaluated (whereas && only evaluates the second
expression when the first returned true).

and for completeness: & for int's is a bitwise-AND

Hans Kesting


Jan 5 '07 #4

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

Similar topics

7
2187
by: Raghu | last post by:
Hello All, I need some help regarding overloading operation. Is there any way to overload typecasting? I mean if i have a piece of code as below. int a = 2: float b; b = (float)a;
0
1633
by: bjpandapark | last post by:
Hi, I am working on my homework...and I have to do create a class where it can calculate the area of the rectangle while under these conditions.. 1. limit the width and length ...under 20 2. use set_length, get_length, set_width, and so on..and have the user input the length and width value 3. after the calculation is done, I have to use the function draw to draw the rectangle with some sort of symbol such as +++ or ===
4
2385
by: Alex Maghen | last post by:
Does a call to Response.Redirect result in an immediate exit from the current page function (i.e. a "return()")? I want to make sure that the statements after the Response.Redirect() do not get called. Alex
5
2186
by: Alan Searle | last post by:
I am exporting ms-access data to XML files. This works fine. However, I need to insert one line at the top of each exported file (i.e. a reference to the XSL file) and am having a problem with this. First I did the following: Export the XML file (using standard XML export) and then read the file (line by line) and writing it out (together with the required extra line) to a new file.
3
1382
by: 0infinity0 | last post by:
Why wont the operator work #include <iostream.h> class A { public: A * operator = (A * rhs) { cout << "Ptr cpy" << endl; return this;
1
6509
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting" setting to be "E_ALL", notices are still not getting reported. The perms on my file are 664, with owner root and group root. The php.ini file is located at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem to be having an effect? ...
14
2814
by: Jess | last post by:
Hi, I read about operator overloading and have a question regarding "operator->()". If I have two classes like this: struct A{ void f(); }; struct B{
2
1275
by: BlackMustard | last post by:
hi all, i am trying to convert the string "32999" to a number, in order to compare it to other numbers and tell which one is the largest one, or if they're equal. i keep getting an overflow error. this is for a macro organizing numbered folders, so i started out with lower numbers using CInt(myNumberString) which worked fine up to this point. the odd thing is that i get overload using CLng and CDbl as well, even though i understand the...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10267
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9914
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.