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

Pages: 1... 7891011... 20
Have you ever tried C::B?
Yes. Its gdb interface is unusable. gdb in general is craptastic, but Code::Blocks doesn't help in the least.
I fixed the multiplication error, but, the problem still stands. It always throws me a value :
(1+1)+((1+1)+(1+1))*10^2 + (1+1)+((1+1)+(1+1))/10^2
= 1604.16
Can anyone explain this crazy value?
Your expression is equivalent to this:
2+(4*10)^2 + 2+(4/10)^2
rather than this:
2+4*(10^2) + 2+4/(10^2)

Exponentiation has a precedence lower or equal to that of division and multiplication (it should be higher).
Last edited on
Finally...
//////////////////////////////////////////////////////////////////////////////////////

Sorry, I cannot handle power command completely. It's too hard to change the default precedence correctly, despite all my efforts.
So now, the power command has been deleted...
I'm very tired now...

NB : C++ doesn't support quick power command symbol...
The code :
if(!Multiply)

And assembly code that the compiler generated :
1
2
3
4
5
1401:  if(!Multiply)
004029E7    mov          eax,dword ptr [ebp-1Ch]
004029EA    and          eax,0FFh
004029EF    test         eax,eax
004029F1    jne          Start+825h (004031ea)

//It seems the and command is redundant...

What do these code mean? And I want to optimize it anyway. Is it possible? :)
Last edited on
My really question :

x = 100 * 10 + 1 * (321+123-pow(321123, (2+2)) * 0xDEADFACE)+15
My next step is : How to detect and get a string out of the expression.

I tried with the code :
My latest code :
1
2
3
4
5
6
7
if(str[i] == '(')
do
{
strTemp.push_back(str[i]);
i++;
}
while(i != len && str[i] != ')');


But... in short : no luck :(
The machine loses two members : the hex value and the last number +15

What is the problem guys? And any better solution? :)
So now, What's next?
The idea now is : Push all parameters onto the stack, then check & call the function that the string specified.
Is it a bad idea when I'm trying to list all functions in the header files?
Calling a function now IMO is really a gigantic step. There are two different ways of string :
Type : Name + (...commands...)
Exactly it's a function call. The function command certainly may contain other function calls. That's another small complex world.
The default comma operator is disabled, instead of this it's used to parse function parameters.

Type : Name + [...commands....]
Maybe it's a variable, or structure. There is only a parameter : The variable index.

The most complex things that a expression may contain first, parentheseses symbols, second, string. "String" is divided into two big categories, one is "Function Call" and one another is "Variable Element Access".

What do you think? How to build and complete this step properly?
Last edited on
First of all, Safe start point : Variable world. :)

How do you feel about this code below :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//nPos = world->Search(string);
//if(nPos != -1)stack.Push(world->GetValue(nPos), nMode);

int main()
{
ClassData classItem;
world = &classItem; //Global - Test variable
//Init...
	classItem.data.push_back(Data("zero",0));
	classItem.data.push_back(Data("one",0));
	classItem.data.push_back(Data("two",0));
	classItem.data.push_back(Data("three",0));
	classItem.data.push_back(Data("four",0));
	classItem.data.push_back(Data("five",0));
	classItem.data.push_back(Data("six",0));
	classItem.data.push_back(Data("seven",0));
	classItem.data.push_back(Data("eight",0));
	classItem.data.push_back(Data("nine",0));
	classItem.data.push_back(Data("ten",0));
for(int number = 0;number <= 10;number++)
classItem.data[number].SetVariable(number);

char *string = "true + (one + two) + (three + four) + (five + six) +\
 (seven + eight) + (nine + ten) * zero";

Stack stack(0.0); //Calculator machine...
Expression(string,strlen(string),stack);//string, length, stack
stack.Cal(); //Let's rock now!!!
//Result...
}


And here's the output :

1
2
char *string = "true + (one + two) + (three + four) + (five + six) +\
 (seven + eight) + (nine + ten) * zero";


Result : 37
Time : 295.406 sec(s)
Length : 900.000.000
Speed : 33.898 (loops)
Characters per second : 3.050.847 (characters)
Last edited on
Storing a symbol table in a global is pretty crappy. A symbol table with linear search is no less crappy.

Did you fix the issue with exponentiation?
helios, You said storing variables (global) is pretty crappy?
world = &classitem;
This tells a new world has been assigned for the main stack expression.
In my opinion, It is not very stable.
This also means it is a pointer, so you can assign any WorldItem for a specific expression.
Certainly, using global variables is pretty bad. But I tried using this in order to check the correctness of the search algorithm and symbol table data. Of course I'm going to remove it as soon as possible and assign it as a function local parameter. Like you said before, the data symbol has a Linear Search function, but it's highly optimized and you no need to think too much about code performance. I used a character-switch case filter. So, it's fast. I'm making a copy constructor which creates a new whole Stack copy. After parsing process, (especially while-for loop) it saves the Stack progress by copying all variable data, then after completing a loop it recovers the default Stack state. It's a great idea because it can save your time and you'll only need to analyze the expression once, then save it for futher expression calculation. Instead of analyzing and re-analyzing 1000 for-loop...

How do you feel about this idea?
Last edited on
Like you said before, the data symbol has a Linear Search function, but it's highly optimized and you no need to think too much about code performance.
Judging from what you've previously called "optimization", I'm willing to bet that you haven't.
Not that it matters anyway, since a poor choice of algorithm puts an absolute limit on the performance of the program.

I used a character-switch case filter.
Well, now I need to see that.
Yup! I've just successfully completed the copy constructor. It's so much wonderful because my ten-million-expression loop with this tweak code works properly and actually now takes less time than normal (I see time measuring results between the original and the optimized one it only takes 25% the total time of the unoptimized...) That means the parsing process now is 4x 4x faster!!!

But there is an another problem. :(
That is a harder, harder exercise. Now let's take a look guys :
1
2
x = one + two + three
y = twenty.one + twenty.two + twenty.three //?!? 

Now, look at "Y" expression, the word "twenty" is a structure for certain. While the X expression can be solved very easily, then next in case Y expression, I have to get twenty unique values through a structure (E.g twenty). The class also has ten elements, "zero" to "nine". The element name is followed by a dot symbol. The problem is I could not get the right value despite all my efforts... :( Sometimes it crashs, sometimes it makes an infinite loop, sometime it produces crazy results (when I input a different string). Oh obviously that's completely difficult!!!!! So, I need your help, I need your help right now...!!! I'd like to hear guys how to do this... What should I do first????...
Last edited on
Completed. Now...
result = number[22] + number.nine
//////////////////////////////////////////
Result : variable
number : structure
number.nine : equals number[9] or number.nine[0] (= 9)

EDIT : Can I use this definition?
1
2
3
4
5
6
7
8
9
10
11
12
struct VariableData
{
inline VariableData(){size = 1;attribute = b_None;type = t_Double;}
union valuedata
{
char chr[8];
unsigned char uchr[8];
double fVal;
};
std::vector <valuedata> value;
unsigned size, attribute : 2, type : 3;
};
Last edited on
Hey guys, I have a question : How to make an error handler? I really want to make a try..catch structure... You can throw, and then catch anything...
Is this possible... or impossible guys? :)
I guess you cannot unless you put everything into a try/catch block, and in the catcher block, if your interpreted code is in a 'try' piece, handle the expection in your interpreted code's catch piece. Makes sense?
In short, to achieve the max space optimization, I have to divide the double union into many parts. To save memory (if you want to use char for example, we may divide the union into eight small parts). Personally I want to keep boolean and then use the char generic allocated memory space instead, eight bits for a single boolean value. But I'm still confused - A boolean value should take exactly a single bit. I don't want to waste memory so much, but if I do so, I have to spent a plenty of time and add a bunch of code...Speed vs Memory? I have no idea about memory, but I considered that memory is the most important thing, rather than speed. The next problem is how to access an element correctly (especially char and boolean). Like I said before, double union is a primary element value. But the union can be divided - 8x smaller for char and 64x for boolean values. So, you cannot use the regular accessing method by accessing an element via an index value directly (Why? Because the double itself also is a container) Max allowed range for char type is 8, and boolean is 64. Otherwise, the parser will create & allocate a new value element (8 bytes per allocation) to store and handle all remaining data. E.g :
1
2
3
4
5
6
7
8
char *s = "0123456789"; // 10 bytes
Data("0123456789"); //First-8-byte holds "01234567" and "89" is moved to the next 8-byte element.
cout << s[4]; //Ok
cout  << Data.value[0].chr[4]; // Ok

cout << s[9]; // Ok
cout << string.value[0].chr[9]; // Wrong - Out of range
cout <<string.value[1].chr[1]; // Ok  


I don't know the best defintion for variable data managing & structure is, but now here is my lastest version :
1
2
3
4
5
6
7
8
9
10
11
12
struct Var
{
union PrimValue
{
union Chr
{
bool b1 : 1, b2 : 1, b3 : 1, b4 : 1, b5 : 1, b6 : 1, b7 : b8 : 1;
}chr[8];
double fValue;
};
std::vector<PrimValue> value;
};
Last edited on
closed account (3qX21hU5)
Sorry for the off topic post ( If there still is a topic =/ ) but does anyone else notice that Jackson Marie doesn't really respond to anyone's advice or posts, its more like he/she is talking to herself more then anyone else.
@Zereo
In my opinion, you are wrong. But your concern? Yes. I understand.

The interpreter itself is a really big project, so most of the time I don't have much time to handle & answer all small advice or answers instantly. Instead of this I will answer them someday...whenever I have enough free time. In short I usually take a quick look and re-correct my draft if needed, and generally speaking almost of advice posts by many people certainly are advisable, useful and helpful... :)
Believe me, Zereo...
Last edited on
My opinion, you are working on a project larger than what you can handle. But that's just my opinion.

And I feel Zereo is partially right, partially not.
I may look repetitive to you, JM, but I think you're too early into C++ to go this deep, then, who knows.
closed account (3qX21hU5)
I think I phrased that wrong what I meant was you totally ignore advice given not that you don't answer their advice. Now granted I only had time to skim half of the 150+ posts (I was bored what can I say) , but I did see people giving you very good advice then in the next couple of posts you do exactly what they advise you not to do. My advice (If you take it) is don't just ignore what more experienced people advise you do to take it in consideration. The only reason for you to post this thread and your ideas is to get advice on it and take that advice to improve your work.
Pages: 1... 7891011... 20