I wrote a parser for the game that I am writing to make it easier for myself to change various aspects of the game (for example, character / stage / collision data). For example, I may have a character class as follows:
class Character { public: int x, y;
I configured my parser to read from a data structure file with syntax similar to C ++
Character Sidekick { X = 12 Y = 0 } Character AwesomeDude { X = 10 Y = 50 Teammate = Sidekick }
This will create two data structures and put them in the <std::string, Character*> map, where the key string is the name I gave it (in this case Sidekick and AwesomeDude). When my parser sees a pointer to a class, such as a pointer to a command, it is smart enough to look on the map to get a pointer to this data structure. The problem is that I cannot declare a Sidekick AwesomeDude teammate because he has not yet been placed in the character map.
I am trying to find a better way to solve this problem in order to be able to bind data structures to objects that have not yet been added to the map. The two simplest solutions that I can think of are either (a) adding the ability to send data structure declarations or (b) reading the analyzer file twice once to fill the map with pointers to empty data structures, and go through the second time them.
The problem with (a) is that I can also decide which constructor should call the class, and if I redirect the declaration, I have to have the constructor separate from the rest of the data, which can be confusing.The problem with (b) is that I might want to declare Sidekick and AwesomeDude in my files. I have to get my parser to take a list of files to read, and not just one at a time (this is not so bad, I think, although sometimes I may need a list of files to read from a file). (b) also has the disadvantage that it cannot use the data structures declared later in the constructor itself, but I don't think this is a huge deal.
Which way sounds like the best approach? Is there a third option that I have not thought about? There seems to be some kind of smart solution for this with links or pointer bindings or something else ...: - I suppose this is somewhat subjective, based on what functions I want to give myself, but any input is welcome.
c ++ parsing
Alex
source share