View Single Post
Old Aug 27th, 2007, 7:29 AM   #3
rwm
Professional Programmer
 
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2 rwm is on a distinguished road
Hey!

Thanks for the reply!

Quote:
Originally Posted by lectricpharaoh View Post
All in all, expecting to create a 'one solution fits all' approach for this sort of thing just isn't feasible. Even though it's possible to do without subclassing, it would mean the user of your class would need to pass in all kinds of data to tell it how to accomplish the parsing. This seems a throwback to the C way of doing things, rather than an object-oriented approach.
Mmm, well im trying to think of it at a different point of view... Look at it this way, we only have a single Parser instance that takes on any subclass of ParseTree (or any other structure for that matter, if one were so inclined?)...

It seems to me that the standard method of parsing is to use a parse tree... Maybe im getting the whole concept wrong?

I know, its probably a good idea to subclass an abstract Parser interface, that would seem the standard way to do things, but what about using a different class that represents a data structure as a parameter to the Parser interface?

Or not?

Maybe im missing the concept entirely? I wrote a plugin toolkit for Maya a while ago, I wrote the whole thing, just so I could learn more about programming, and when it came to parsing files, what I did was write the following:

Tokenizer - read a file into a buffer and converted the file to a list of tokens (with the options to provide custom delimitiers, the standard delimiters were ' ','\t','\r' and '\n').

Then I wrote a parser for each kind of file, derived from an abstract Parser class, which took on a Tokenizer as a data member.

Then what i did was simply read each token, evaluating them one at a time, if a token was a keyword then I would enter a token evaluator method, which stepped through the token list till it hit the end of the keyword block, while building a data structure to store the parsed data...

It worked well, it was fast... But I felt it wasn't a very *elegant* solution...

Maybe you could help me by outlining the standard approaches to parsing, unless i'm doing it the standard way?

Thanks! Looking forward to a reply!



EDIT: Maybe I wasn't clear enough, by using ParseTree* I could be thinking along the lines of using a custom callback function at the end of parsing a certain keyword???

Actually it sounds stupid!
rwm is offline   Reply With Quote