Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

how do i wrote parser?

Name: Anonymous 2006-10-18 19:13

I have a pretty good educational understanding of computer grammar theory, so I get the concepts behind parsers and context-free grammars, but I've never actually implemented a parser.  And now I need to write one.

Specifically, I'm looking to write a loader for .md5mesh files (they are text format).  Let's say I'm able to get a grammar for it written on paper that matches that file format's general structure.  Where do I start in code?  This is fortunately not as complicated as a programming language's language, since it's a format that's about data and not code, but it's still a somewhat more complicated 3D format than, say, the Alias Wavefront .obj format (where reading and parsing is as simple as a for loop and sscanf -- but that format doesn't support skeletal animation and other things the way .md5mesh does).

Name: Anonymous 2006-10-28 18:36

>>16
I agree that it's less clear or obvious, but you can (and should) use the extended syntax where you can use whitespace liberally, then indent your regex properly, align |s, etc. I've had to modify such regexes and, if you are used to the syntax and don't let the /&$()=()/$&? look scare you, it can be done reasonably well.

Parsing with PCRE (assuming your language has a decent interface to them) has the advantage of being ridiculously simple and quick to write; you just can't do the same with a traditional lexer and a parser generator even if you typed everything as fast as you can without stopping one second to think.


>>17
Get your head out of your university teacher's ass and discover that what we call "regular expressions" are no longer regular expressions. They feature recursion, conditional matching, and backreferences and backward and forward lookaheads for context. I don't have a proof that they are Turing complete and don't need any, because when I want to use them for something that could get hard to write in a single regex, I write a 3 lines loop around a regular expression (or nest regular expressions using a 3 lines loop).

And BTW, we call them regexes because they started as such. But to avoid confusion, you can say "PCRE" (Perl-Compatible Regular Expressions, also a famous C library).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List