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

Pages: 1234... 20
I'm a chicken, so the basic knowledge I must know.

Give you some links I will.
http://en.wikipedia.org/wiki/C_%28programming_language%29
http://en.wikipedia.org/wiki/C%2B%2B
Begin, some questions... :)
Can I put all various definition types into (*void)? For example : POINT pt;void * data = &pt; Is this possible?
Is there any way to define a variable? How to find a word while parsing a file?
Not sure what you intend to do with that void*. In general, you should avoid doing such a thing as void* are hard to work with. But yes, any address can be assigned to a void*.

If you're writing an interpreter, you should keep a stack of maps from strings to values. stack is there to help with local scopes. It would be good to start with a language that, for example, has no functions and all variables are integers.

Parsing is usually not too easy. See "recursive descent parser" I mentioned in my earlier post.

It is important to make one step at a time. For example,

* First write a recursive descent parser to recognize arithmetic expressions, like (3*4+2)*3. Be sure to return it all in a usable data structure (a tree preferably. See "parse tree" or "abstract syntax tree").

* Then decide how you want your language to look. Try to think not "what would be cool?", but "what would be simple yet usable?". Decide what data structure should represent the language to interpret. Write that structure and the interpreter. Hopefully you've picked a simple enough language. Forget about parsing at this point.

* Finally, write the parser and convert its output to the structure you came up with. I suggest doing that last so that you can come up with a syntax not too far from the one interpretation needs.
@hamsterman
It's good to hear your answer.
As I mentioned earlier, the parsing should start and then end immediately.
My interpreter may skip an entire compiling command but my target is "it should show the result immediately, without checking the level of the source . (complex or not)"

After the process removing all spaces and symbols, It should get a word. Then I'll use the function strcmp to locate the variable or a function, or just find a system programming command. "Variable names" is not a big problem, but function names....I think that each header file at least has hundreds of different functions, and therefore adding process with function parameter lists is not really easy.

Second, checking problem... (Variable - function finding)
For index i = 0; i < (thousands); i++...
Each loop has a strcmp function. A Input may have a bunch of characters, that means performing this checking command may take a lot of times. :(
So, is there any method, that better than the function "strcmp"?
And, In my opinion the biggest problem when performing a complex system command (for , while , if, switch case)
Last edited on
Nothing happens "immediately". It will only be fast if you pick a simple grammar.

I have no idea what you mean by "level".

In general, you're looking at it wrong. Source code is the least comfortable form of a program for the computer to work with. (Unless we're talking about brainfuck). Compilation is nothing else than the long way from text to something the computer can understand. (Interpretation is just compilation made half-way).

Also, strcmp is as fast as can be. Note that if you do it well, you'll only be searching a few lists, not the entire code. That is part of the motivation behind parsing. You should forget about magical efficiency for now. Just concentrate on making (parts of) it work.

Did you start already? You won't learn much without trying. Try writing any one bit of the interpreter, then we'll discuss what's good, what's bad and where to go next.
hey guys can you tell me how to build an operating system?






haha just kidding (my emotional robot is coming on well however)
Well, I've just found a very very good reason. It will encourage me and also It's a great idea. That's the shortest way , I think hehe... Hope the dream will come true (soon)... ??!!
Last edited on
you will get there eventually

eeeeeveeeeeeentuaalll eeeeeeee eeeh

im slowly absorbing knowledge, i hope c++ isnt obsolete by the time i get there
Ok start now
schmeh? start what now??
This is only a draft... :)

I considered about this carefully, determined all important steps. Generally speaking it should be divided into several parts. All interpreters (and mine) need the stability in general, so first, a few steps :

Step 1 : Determine the language structure. An interpreter should have variables, functions and the world around. Create a class which stores a variable with its attributes and value. And the functions, create an array and use the "Linear search" method. Maybe I'll combine all various basic variable definitions into a single definition, such as "double", only double and double. Only a thing I'm afraid is the double is always calculated slower than other definitions. The vector is a great idea, but I doubt, the reason of speed. "A good thing that a vector can do" is unlimited variable size with lots of effective algorithms. So it can avoid almost of different crash errors (such as Access Violation). I'll delete some concept words, such as "inline", because it's not necessary. IMO calling a function is not easy, I have to make two types, the first one is the "local function" (or the "handmade function") which the debugger execute directly. The second one is calling other functions through Dlls (Dynamic-link-library). The simple language and grammar are really a perfect choice. I have no idea, and now I'm trying to think about new concepts. I'm not a professional programmer... :)

Step 2 : Building a compiler : A proper compiler for a specific source type is very necessary. And certainly, nowadays all compilers are very intelligent. A compiler compiles a source and submits the compiling results to a linker. But I have the another idea. In this case the compiler is not one of the most important tool (Negative??) The debugger still loads and runs any script source properly, even without a compiler. The compiler (can be called as "repairer") compiles the source the shows the user how many compiling errors (errors & warnings) are there in a specific source that an user specified. The additional feature is code optimization. The goal is making a source run faster without affecting the program results. Warnings and minor errors (can be repaired), only major errors (which and where the debugger will halt immediately) are showed completely. And certainly the debugger also is an intelligent compiler. The compiler is just a part of the debugger (or parser) product. The world of any primary programming language certainly is very large, however in case script language, the world is limited, and so it needs a primary language to work. That requires lots of times to add all necessary things. I'll generate a new address, then assign something. That only requires a code, then the parser, the compiler and the debugger will do all for you...

Long story short, a language should be clear, easy to read and understand. A clear language will make everything simpler more, you'll only need to build the structures and a loader, and pick a source that you want to execute...
And the next step? No obvious answers. And finally, consider again :
First : Code look & style - Second : Performance - Third : Efficiency.

Edit : And a question :

Simple code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int FunctionName(char *string){if(!string || !strlen(string))return -1;
int min = 0, max;

switch(string[0])
{
case 'a' : max = value;break;
case 'b' : min = value;max = value;break;
case 'c'....
}

for(int i = min;i <= max;i++)
if(!strcmp(string, funcName[i]))return i;

return -1;
}


Is this a good idea? That uses two variables : min, and max. In short they will limit the search range and hence the program will run faster.


What do you think? Any idea? :)
Last edited on
A vector with variable names, attributes and values is fine. You may consider using a map though.

No idea what you're saying about doubles.

Forget about dlls for now. Interpreter is a complicated thing. If you get "x = y + 2;" to work, that will be good. You can think about fancy stuff later.

You're misunderstanding what a debugger is, it seems. But never mind that. It's irrelevant. You are writing half-compiler. Forget about debugging and linking.

No idea what you mean by "world".

What is that code supposed to do? Is that the syntax you want to use? Or is that a parser?

I see you're thinking of C++ minus some features. It's not a good way to think. C++ standard is 400 pages long (excluding standard library specification). http://www.nongnu.org/hcb/ is how C++ grammar looks like. Naturally a C++ parser is more complex. Your language does not have to be like this. Do little or you'll end up doing nothing.
Rather than spending so much time thinking about it, I'd recommend that you actually try to implement your proposals. Then you'll realize why most of them are unreasonable for a first timer.
I see...
That is a draft but it contains lots of major things. I tried two loading methods. The first method is loading file through the memory by the function ReadFile() first, then after that, start parsing process. This is not a good idea, so I tried "fread" function. And I completed the process optimizing the loading process (maybe). I used the Log function to log all result words..Does anyone have any idea?
And I think I should use multi-threads to greatly improve speed of the parsing process, instead of using only the main thread, that is very slow and the users have to wait for a long time.
Last edited on
And I think I should use multi-threads to improve speed of the parsing process
Like I said before, actually try implementing your ideas. One can think up any ridiculous idea they want, but from there to actual materialization there's usually a gigantic step.

I don't think anyone has ever come up with a parallelizable parsing algorithm.
Hey everybody! I got an idea.

While I was making the data class structure, I discovered, that using the union type definition will give the data class a dynamic access and reduce greatly the memory consuming. All data will use a single memory allocation.

Then :

1
2
3
4
5
6
7
8
9
10
union z_Data{

	double d;
	long l;
	float f;
	int i;
	short s;
	char c;

}data;

So, I only set one of these members above a value :
data.i = 45560;

And the output :
data.d  = data.l = data.f = data.i = 45560;
//Not tested yet...



Is this a good idea? Any suggestion?
Last edited on
How will you know which type is currently used? This could work, though for now just stick to one type.
Last edited on
The code :

1
2
3
4
5
6
union z_Data{

char bit[8];
long l;

}data;


Usage :
1
2
3
4
date.bit[0] = 65; //data.l = 65
date.bit[1] = 4; //data.l += 256 * 4
date.bit[2] = 2; //data.l += 65536 * 2
...............................................................


I think it may be a good idea :)
@hamsterman

I tried these code :

1
2
3
4
5
6
union z_Data{

bool bit[64];
long l;

}data;

After testing this code, I see that the memory consuming of this structure is too high (64 bytes)

Or :
1
2
3
4
5
6
union z_Data{

unsigned bit[64] : 1;
long l;

}data;

And I caught several compiling errors.

But, why this caused these problems? And how to access a specific bit of a value?
I'd like to know some advices and suggestions :

Here is the code, simple (initialization)
1
2
3
4
5
6
int a;
int a[10];
int a[10 - 4];
int a[MAX_SIZE];
int a[MAXSIZE - 5];
int a[MAXSIZE + Function()];


Those are array access methods. How to parse it properly?
I don't know. In short it's too complex... Help!
Last edited on
Pages: 1234... 20