I've got a question or two about some methodologies on token parsing - I've read
Parsing, tokens and strings, and I got some ideas from it, but this project I may be taking on is a bit bigger than what's detailed there.
My brother-in-law is wanting to come up with a VHDL-to-spice parser, which are both languages he has to use in his chip design job. We've talked a little bit about writing a much more intelligent parser than they already have to do this task, but I don't know VHDL or spice, and he doesn't know enough Perl or C or any other languages to do this.
I've written a token parser once in C for a class, but it would seem to me that Perl is much more suited to the task, as it's processing text into text. I've also been reading through Perl & XML, and that's given me some other ideas too - I don't have any real pseudocode at this point, but I'm wanting to consider methodology.
When I wrote the parser in C, we basically read in elements that were nonwhitespace, and then ran each token through a switch, where further tokens were pulled off, etc.
Now, with Perl, I can read in a whole line at a time, split it, and then run through the array, but when I run into multiline blocks, that doesn't seem like it'd work as well.
I'd thought of slurping the entire file up into one big fat scalar, then using split limited to two elements, so that I have something akin to a current token, and the rest of the code to come, so the fact that whitespace exists isn't an issue anymore. This approach seems very undesirable, because if he's running it on incredibly large files, it'll eat RAM like there's no tomorrow, AFAIK.
In Perl & XML, there is an example of using
XML::Parser to read through an Apache logfile, by defining how the parse function works. That'd be an interesting approach, using something like that and a nice big symbol table of sorts to take care of it.
Has anyone attempted anything like this in the past? I know that there are simple ____2____ sorts of programs out there, but I haven't really read any language2language source code, and so I'm posting this in hopes of getting some good feedback.
~Brian