Okey Dokey… It was early in the morning… lemme alone
This isn’t THAT related to SDL, but since you are all such smart
people… kicks the pebble on the ground around with his foot
Uhm, ok… allright then.
Alright here’s the deal.
tile{
x: 1312
y: 128
file: “grass.bmp”
}
Ok, so we’re talking about parsing here…
This is the format…
I want it to go through the file and look for “tile{” then… start
looking for “x:” then the number right after that should be assigned to
the integer x.
Then search for y, and assign y.
Look for file, then assign file… then I will take that info and make
tiles out of it.
then when it finds “}” start over looking for “tile{” or some other
thing.
I’ve made a way to load tiles before, but it wasn’t very flexible, and
I wouldn’t be able to define things like:
animation_tile {
x: 32
y: 32
files: “grass1.bmp”
“grass2.bmp”
“grass3.bmp”
}
When I go to load the x,y, and the file it spits out 0 for x and y, and
some garble 30 characters long for the file.
And yes, x = 0 and y = 0 before I started all this
Hope I have given you enough info this time around. Thank you for even
responding
Yeah, it makes a lot more sense now - I mean, how hard could it be to
read a text file? (While on the contrary, parsing is an entire form
of science, more or less…)
Sure, you could parse this kind of stuff with “raw” C or C++ code if
you really enjoy hacking that kind of stuff - or if you need top
performance, and your format is “plain” enough to be parsed in some very
efficient way.
If not, I think you should learn to use the parser generator bison (GNU
replacement for the traditional Unix tool “yacc”), or something similar.
Parser generators aren’t particularly hard to use once you figure out the
basics, and save loads of time, while still generating pretty fast
code. You get “recursive” constructs (expression in expression and the
like) virtually for free, and all you have to do is write a grammar file
with a few lines of C or C++ inside the rules.
Of course, for real flexibility, you may also need to add a symbol table
(to manage variables, labels, functions, objects etc) and other objects
commonly found in interpreters and compilers.
A parser generator lets you focus on that, and the language syntax,
instead of messing around with argument stacks, state machines and all
that - it’s already written and optimized, and the generator builds the
data structures, and stuffs your C/C++ rule code where it belongs, all
according to your grammar file.
In short, spends some time starting off “properly” with a parser
generator - after that, it’s just half an hour of hacking to add support
for mathematical expressions where you used to take “raw” numbers for
granted. Add a basic linked list symbol table (look at the one from the
bison calculator example :-), and you can add variables just as easily.
I won’t say adding scripting is all that easy, but the parser generator
makes it a lot simpler - after all, it’s the kind of problems these
tools were designed for.
//David Olofson — Programmer, Reologica Instruments AB
.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |
-------------------------------------> http://olofson.net -'On Monday 12 November 2001 19:35, Bryan Arant wrote: