I'm pretty new to parsing, but I've written a simple parser to read in an effect file format, which was formatted a bit like this (people who are familiar from Ogre will notice that the format is very similar).
I'll give you a very very brief overview of the process. I'm not a very good writer, but hopefully this will at least give you a basic idea of what happens. Please, someone else feel free to expand on what I've said, correct anything I've said that's wrong or too complex, and make it a bit more newbie friendly :)
I'm not the best person to help you, but I wanted to at least try, because I know how frustrating it can be getting a foothold into this particular topic! Apart from the Flipcode scripting tutorial, I've never found a simple parsing tutorial geared towards the newbie. They all seem to assume some kind of previous knowledge on the subject. (I've not looked for a long time though, so maybe things have improved since then)
OK
//comment////this is a simple effect file////blah blahEffect "terrain/dirt.ofx"{ Technique { Sorting SKYBOX CastShadows ENABLED LODLevel 0 Pass { DepthWrite DISABLED DepthFunc LEQUAL FogDensity 0.7 CullingMode CLOCKWISE } }}
Part 1: The lexer:
You use flex, to write a lexer, which basically reads in data from the file, and tells the parser what kind of tokens were found, and an optional value for the token. A token could be a single word, a number, a string, whatever.
Flex takes in a file, that describes all the tokens, and generates C or C++ code for the lexer.
In an attempt to explain what a token is, here's a list of tokens that flex will understand from this effect file, from my parser. The kind of tokens it understands depends on the input file to flex, basically you give flex an input file, and it generates a C++ program to parse the input.
Anyway, i'm rambling, so here's the list of the tokens my parser would get from this effect file.
Token: Token Type:===============================================//comment COMMENT (the parser is set to just skip these// COMMENT until it finds a token that isn't a //this is a simple effect file COMMENT comment )// COMMENT//blah blah COMMENTEffect EFFECT{ LEFT_CURLY_BRACKET"terrain/dirt.ofx" STRINGTechnique TECHNIQUE{ LEFT_CURLY_BRACKETSorting SORTINGSKYBOX SKYBOXCastShadows CAST_SHADOWSENABLED BOOLEANLODLevel LODLEVEL0 UNSIGNED_INTEGERPass PASS{ LEFT_CURLY_BRACKETDepthWrite DEPTHWRITEDISABLED BOOLEANDepthFunc DEPTHFUNCFogDensity FOGDENSITY0.7 FLOATLEQUAL CMPFUNC_LEQUALCullingMode CLOCKWISE} RIGHT_CURLY_BRACKET} RIGHT_CURLY_BRACKET} RIGHT_CURLY_BRACKET
Part two to follow in a second, I am really paranoid about my browser crashing, and losing all this.
Sorry if this explanation is a bit confusing, as I say, I'm not a good writer.
[Edited by - Oxyacetylene on September 2, 2005 6:19:09 AM]