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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.