in reply to Parsing and converting Fortran expression [solved]
There are many full-fledged parsing tools in CPAN ... a favorite is Parse::RecDescent but there are many more like Parse::Yapp.
So, another approach to the problem is to use an existing parser to create a parse-tree (AST) from the source, then to generate the “C” equivalent output. These approaches push the complexity into a grammar, resulting in a simpler program for you to write. I have achieved rather-miracles with these tools in the past, if I may say so myself. ;-)
Which is “best?” That’s up to you. Anonymous Monk has very generously presented you with two “hand-crafted” recursive-descent routines that (especially since they have just been handed to you by the PerlMonks Code-Writing Service™) might be just the ticket. They do look very, very good ... but they are hand-made, vis-a-vis what Parse::RecDescent would generate, which of course “might be an issue, or might not.” It very much depends on just how complex the Fortran expressions might be, whether they might contain syntax errors, and just how much this project might “scope-creep” in the future. The very nice thing is that Perl gives you so many powerful alternatives to choose from.
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing and converting Fortran expression
by Anonymous Monk on Aug 26, 2015 at 05:04 UTC | |
by kikuchiyo (Hermit) on Aug 26, 2015 at 18:52 UTC | |
by Anonymous Monk on Aug 26, 2015 at 19:11 UTC | |
by kikuchiyo (Hermit) on Aug 26, 2015 at 20:17 UTC | |
by Anonymous Monk on Aug 26, 2015 at 20:09 UTC |