![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Professional Programmer
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2
![]() |
Parsing questions.
Hey!
I'm trying to write a parser, and I was hoping anyone could suggest/advise? What i'd like to do is write a generic parser class, without having to derive from this to parse certain files etc i.e. ...
Parser *parser = new Parser;
parser->Parse("anyformat.txt");
...
parser->Parse("anotherformat.dat");
...instead of ...
Parser *parser = new AnyFormatParser;
parser->Parse("anyformat.txt");
...
delete parser;
parser = new AnotherFormatParser;
parser->Parse("anotherformat.dat");
...I don't know what you think about this? Maybe a little irrational? I think it would be nicer to have a "generic" parser class, and just define a "grammar/syntax" for parsing. So my idea was to create an abstract class, ParseTree, from which I derive certain other parse trees, such as AnyFormatParseTree, AnotherFormatParseTree etc So the generic parser would use it like: ...
Parser *parser = new Parser;
AnyFormatParseTree afpt;
parser->SetParseTree(afpt);
parser->Parse("anyformat.txt");
...
AnotherFormatParseTree anfpt;
parser->SetParseTree(anfpt);
parser->Parse("anotherformat.dat");
...The idea is that the user doesnt have to do anything to the ParseTree subclass (unless deriving their own version) in that the ParseTree subclass already contains a "pre-built" parse tree, so all that is required is to pass an instace of ParseTree* to Parser: etParseTree(...).What do you think? Incidentally i'd like to ask a couple of questions about parse trees and parsing in general. What is the best method to write an extensible parser framework that can be reused as much as possible? With a parse tree, what we do is construct a tree of characters, so if i had the keywords in a certain file: akeyword, dosomething, blah The parse tree would contain branches that took paths to the following keywords, or to NULL right? Would it be a good idea to implement a certain "callback" via function pointer at completion of parsing a keyword? Or not? Hope someone can help! Thanks! ![]() |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Template Questions | King | C++ | 3 | Feb 3rd, 2007 7:30 PM |
| hardware questions | programmingnoob | Coder's Corner Lounge | 28 | Aug 8th, 2006 8:04 PM |
| Novice questions. | snafu | Python | 3 | Oct 5th, 2005 5:03 PM |
| ucf cs student has some questions | raspberryh | Coder's Corner Lounge | 33 | Sep 12th, 2005 2:49 PM |
| Emergency: Confusing C Programming assignment questions | silvia | C | 3 | Jul 13th, 2005 3:39 AM |