02-14-2005, 08:50 AM
Hi again everyone -- I need to borrow someone's brain for a bit.
This is actually a VB question, but I rather think that more eyeballs see this forum than the General Programming one buried all the way down at the bottom.
Okay, it's a parser for C-style code. I already have it breaking the source into tokens as
- Numeric Constants
- Identifiers
- Operators
- Parenthesis
- Braces
- Semicolons
The tokens are stored in a Collection Object. The second stage introduces the CodeBlock token, which is simply a token containing a pointer to a further block of tokens. Any braces are consumed and the tokens inside them are moved into sub-collections, forming a tree.
What I'm having trouble with is what I percieve to be the next phase -- figure out where the expressions are and turn them into a similar nested-tree approach, where each node basically contains two pointers to subnodes, and the operator that connects them.
I'd like it to recognize order of operations, but I'm finding it all rather overwhelming. Without a lot of computer science background or formal training, is there a good site that explains the logic process for turning these linear tokens into a meaningful tree?
A quick Google just revealed a bunch of philisophical guff about RPN. Anyone want to recommend a practical resource?
Thanks!
Mike
ps. The language that I'm dealing with doesn't need to account for string constants or compiler directives (eg, macros).
This is actually a VB question, but I rather think that more eyeballs see this forum than the General Programming one buried all the way down at the bottom.
Okay, it's a parser for C-style code. I already have it breaking the source into tokens as
- Numeric Constants
- Identifiers
- Operators
- Parenthesis
- Braces
- Semicolons
The tokens are stored in a Collection Object. The second stage introduces the CodeBlock token, which is simply a token containing a pointer to a further block of tokens. Any braces are consumed and the tokens inside them are moved into sub-collections, forming a tree.
What I'm having trouble with is what I percieve to be the next phase -- figure out where the expressions are and turn them into a similar nested-tree approach, where each node basically contains two pointers to subnodes, and the operator that connects them.
I'd like it to recognize order of operations, but I'm finding it all rather overwhelming. Without a lot of computer science background or formal training, is there a good site that explains the logic process for turning these linear tokens into a meaningful tree?
A quick Google just revealed a bunch of philisophical guff about RPN. Anyone want to recommend a practical resource?
Thanks!
Mike
ps. The language that I'm dealing with doesn't need to account for string constants or compiler directives (eg, macros).