PDA

View Full Version : Algorithms help!



Killboy
09-20-2007, 10:01 AM
Well, in college we're trying to simulate a compiler. I've generated the tokens and I know every compiler has a binary tree. The thing is that, I don't know how it works, I mean, it's not an ordinary binary tree.

Anyone knows how a compiler's tree is like?? And what's its algorithm?

Thanks

Andy
09-20-2007, 11:48 AM
Reading that post, the only thing I can think is "BWAAAAAA?!".

But then, I'm retarded when it comes to fancy computer shit.

The Talking Pie
09-20-2007, 12:41 PM
Aw, I was hoping you were going to ask for someone to write some complex algorithm for you. That I could help you with.

Endymion
09-20-2007, 04:26 PM
Well, in college we're trying to simulate a compiler. I've generated the tokens and I know every compiler has a binary tree. The thing is that, I don't know how it works, I mean, it's not an ordinary binary tree.

Anyone knows how a compiler's tree is like?? And what's its algorithm?

Thanks

i know gcc uses red-black trees. wikipedia's got a good writeup, if i remember correctly. it also really depends on what part of the compiler you're writing. is it the AST? the parse tree?

Killboy
09-20-2007, 08:39 PM
Aw, I was hoping you were going to ask for someone to write some complex algorithm for you. That I could help you with.

Well, yeah, the algorithm of the tree... I think it's complex


i know gcc uses red-black trees. wikipedia's got a good writeup, if i remember correctly. it also really depends on what part of the compiler you're writing. is it the AST? the parse tree?

The abstract syntax one

Endymion
09-20-2007, 11:36 PM
so you've parsed the input, tokenized it, and now you need to construct the AST. basically, you need to know how your input is structured (prefix? infix? postfix?) and generated a tree where operands are leaves and the node they're children of is the operator they're attached to. the algorithm for this should be some sort of push-down automata. look up context free grammars if you need some help.