New child language - (Function member address (structure))

Pages: 1... 56789... 20
I really need opinions and suggestions or what you think about a project or something... And about myself, I don't need much code examples (Although I'm just a chicken in this large community...) This is prepairing...
Last edited on
Prepairing, eh? I can see how it might be useful to pair things up earlier than usual.
Last edited on
I added comparsion symbols and bitwise operators...
Now my idea :

Comparsion symbols : return false - or true
Basic symbols :
(+); (-); (x); (/); (%); (^); (&); (|)
With the symbol "=" (+=)
Will attach a variable as a pointer.


Now I can write :
1
2
3
4
5
6
double Result = 0;
Stack stack;stack.PushItSelf(&Result, Equal, true);

char *str = "50 + 5 / 25 * (5 == 5)";
Expression(str, strlen(str), stack);
cout << "Result : " << Result << endl;

Next step : Multiple complex comparison expressions...
Last edited on
Hey guys, I have a clear idea....
And, in short, this idea is : I will add a function which adds variables into a pointer vector list. Then while (in searching process), I only need to compare addresses between variable pointers and pointers.
The method IMHO may give instant result. Perhaps. :)
Generally speaking, the method above is fine, isn't it ? :-)
Last edited on
Are you so prejudice against std::map that you will find the hardest possible alternative?
Hi everyone!
Today I've successfully added the"(a - b) ? x : y" construct into my expression calculating machine. Now we have more (a convenient way) to perform commands directly without using if - else conditions.
The machine also has been redesigned completely (C++). I used map, vector instead of pointer. Also I fixed memory leak, bad variable memory allocation, and optimized the code a lot. The code now runs faster than the old one by 1.5x!!!

Now I can write :
1
2
3
x = 5 * (10 < 20) ? 2 : 3

y = 2 + ((2 * 5) > 5) ? ((10 < 20) ? 3 : 5) : ((20 > 5) ? (6 - 2) : 10)


Next step : Parsing conditions...
Last edited on
Hey guys : "150.000 characters per second..." - Fast, or slow?
In the US, that's very very slow.
In non-crazy countries, that's still slow but not nearly as slow as in America.
I did 1000 program loops, each loop has about 10000 characters. I used lots of parentheseses, and many comparsion expressions. To do this I used "strcat". "Parsing scripts" in my opinion it takes a lot of time, but the "calculating" process (I used another machine), I see it always finishs its work very quickly.
Last edited on
Seems I have to redesign the expression parsing machine...
But, hey guys, I don't know using the global variables...is fast? or slow? Almost variables (except some important variables) I used "global".
Using global variables probably won't make any difference in performance, unless you try to parallelise your code (i.e., use threads). The more globals you have, the more thread synchronisation you have to do (which slows the program down), and the more likely deadlocks (which result in infinite loops) and data races (which can result in deadlocks or incorrect output) are to occur.

More importantly, globals make your program more difficult to understand. Your brain can only keep track of so many variables at a time, but what it is good at is separating different contexts (the variables in a function are in a different context to the variables in a different function) because of the way human memory works (memory is aligned with locations, which is why people use the method of loci to memorise large volumes of data, and also why you might decide to do something in another room and forget what you're doing when you enter it, and then remember as soon as you leave).
I hate to burst your bubble Jackson, but I believe what you're creating already exists on a much larger scale.

See here for details: http://www.autohotkey.com/
Or the better one: http://l.autohotkey.net/

Code snippet:
1
2
3
4
5
6
7
f1::
_Cleaned_ := RegExReplace(Clipboard, "\[/color\]|\[color=\w*\]", "")
StringReplace, _Final_, _Cleaned_, `r`n, `n, All
Sendinput, {raw}%_Final_%
Sleep, 1000
Sendinput, ^a^x
Return


It's built around, and possibly with, C++. It comes with it's own .exe builder, GUI based interface options when creating any kind of forms, and is designed with global mouse and keyboard hooks. I just wanted to show you some of the scripting languages that exist out there, not necessarily to discourage you, but to show you how much stuff exists out there, what their code looks like, the features they have, and the extensive knowledge the creators have.

That's not to say that you have a bad idea by any means, I just don't know that you have enough knowledge for it yet, because I know I sure as well don't. Anyways, keep at it and if you need any help, post back here.
Very thanks guys. That encourages me a lot...

By the way, I have a doubt : Does C++ support 'negating' command (Negatives the expression result and forces the result to take a boolean value). E.g :
(>=) -> (<)
(==) -> (!=)
.......
Do you know? :)
Last edited on
Yes it does. But it's of no use, probably slower if unoptimized, and anyways the result of a common expression is already a boolean value. So you better stick with the builtins.
Yes. Thanks @EssGeEich!! I added "negating" feature. The '!' sign symbol is used to negative the result of a expression and force the result to take a boolean value. Examples :
x = !(5 > 2)
In this case, the '!' symbol changes the greater (>) symbol to (<=) (Less or equal)
x = !(!(10)) This expression is equal to x = (10 != 0)
You can negative some of comparison symbols, E.g :

x = (5 !!= 5) Similar expression : x = (5 == 5)

x = (5 !> 5) Similar expression : x = (5 <= 5)

Also I've just successfully added [type-casting] feature. IMO it is a way which converts a variable of one type, such as an int, a double,... to an another variable type, For E.g float->int...
Currently I included unsigned, signed, char, bool, int. The default definition is float. And, if you choose unsigned without changing the variable type, the machine will automatically convert the value to unsigned (Keeps the decimal value). Otherwise, if the value needs to convert, the machine will convert to a proper value with its correspond type.

Here's how :
Let's take a look :
1
2
3
4
5
x = 100 + [unsigned]- 57.35  //(1)
x = 100 + [unsigned int]- 57.35  //(2)
x = 100 + [int](3.64 - 2.46)  //(3)
x = 100 + [int](3.64 - [bool](2.34 + 3))  //(4)
x = [int](100 / 6)  // (5) 

First of all the first case the tag [unsigned] converts the value "-57.35" -> "57.35"
- Second : Same here, but it converts "-57.35" -> "57"
- Third : The [int] tag converts the final result of the expression (3.64 - 2.46) to a regular integer value.
- Fourth : Converts the final result of the expression (2.34 + 3) to a boolean value.
- Fifth : The exact value is 16.6666666... But the [int] tag truncates the decimal result, generates "17", not "16" as the value of the default C++ type-casting.

What do you think? Any suggestion or idea? Any mistake? :)
Last edited on
Hi...
Currently I got a trouble about C++ comparison expression. I tried to think up new idea but I couldn't.

That is a very hard question. Because I have to calculate the expression, by hand :

if ((4 > 5) && 3 && (5 < 2) || (100 > 10) || (4 / 2 > 3))

The program always gives "0" but I have no idea what it did.
How to calculate this expression type properly?
Does anyone know? Help, please...
Last edited on
!!=
Ugh! Why would you do that?!

((4 > 5) && 3 && (5 < 2) || (100 > 10) || (4 / 2 > 3))
((4 > 5) && 3 && (5 < 2) || (100 > 10) || (4 / 2 > 3))
(0 && 3 && (5 < 2) || (100 > 10) || (4 / 2 > 3))
(0 || (100 > 10) || (4 / 2 > 3))
((100 > 10) || (4 / 2 > 3))
(1 || (4 / 2 > 3))
(1)
1

If the operators have the wrong precedence, what will happen instead is
((4 > 5) && 3 && (5 < 2) || (100 > 10) || (4 / 2 > 3))
(0 && 3 && (5 < 2) || (100 > 10) || (4 / 2 > 3))
(0)
0

I question whether you should be programming at all if you don't understand how the language (by which I mean C++) evaluates its expressions.
Wow a many thanks helios! In my opinion you are really intelligent!!!
By the way - I have a question about union structure again...
At any rate in my point of view it always looks like a good idea, so first, let's take a look :
1
2
3
4
5
6
7
8
9
union data
{
long l;
double d;
};
bool bDouble = false;
.................................................
if(bDouble == false){[...]}// Performs integer commands...
else if (bDouble == true){[...]}// Performs double commands... 

In my opinion, the number range of the double definition is very very low, for example if I wrongly attach a very big value to the double member, such as one billion, then certainly it causes value error 100%... But if I turn off the data mode bDouble switch -) "false" (integer mode), then the range with the space-consuming problem... is completely solved... :)

Sorry, I haven't tested it yet, but, is this really a good idea? Any suggestion?...
Last edited on
It kinda is a good thing, but think about the fact that on most compilers a double uses 64-bits, and a long uses 32-bits, so in case you are using the long value, you are 'losing' 32-bits. If your compiler supports 64-bit integers, try using them.
See if this compiles:

1
2
3
4
5
6
7
struct GenericVariable {
    bool IsDouble;
    union Data {
        long long l;
        double d;
    };
};


Anyways, in my program, user had a non-typed array of data, each element of size of 32 bits.
In those 32 bits you can pack a float, or in 64 bits you can pack a double.
All of this done by changing the type of the pointer depending on the command. It is almost the same of what C++ does, but C++ takes informations about the type with each variable - and makes sure it is compatible with every function's requested informations on a parameter.

This isn't easy to explain but let me give you an example:
In the interpreter, packing a 2.4 float and printing it out as a hex value, i get: 0x4019999a.
If you wanted a 32-bit value as 0x4019999a and printed it out as a float value you would get 2.4 or a really similar value.

This may be a bit off-topic for you, I don't know if you want type-safety there.

By the way C/C++ are type-safe. My program is not- It just pushes functions a block of data.
Thanks EssGeEich, in any case your advice is really helpful!
But I'm very silly...!!! I don't know that I may use the basic C++ converting method to solve the generic data problem. Instead of the ugly and complex struct, operators with the union structure...

Here's how the simple double variable stores the integer value :
1
2
3
double Val = 1004200033; //1.004.200.033
cout << Val << endl;// Value : 1.0042e+009
cout << (unsigned int)Val << endl;// Value : 1004200033 


Even the example :
1
2
3
double Val = 1004200033.329589702;
cout << Val << endl;
cout << (unsigned int)Val << endl;// Value : 1004200033 

Still gives back the result correctly... (^_^)

It's so awesome! I used to imagine "double" (useless integer)... :)
Edit, I think C++ uses 4 high bytes for storing integer value, and all remaining bytes for decimal data.
Thanks! But, I still doubt that converting double to int is a little bit slow... Right? :)
Last edited on
Pages: 1... 56789... 20