9

I would like to write simple parser in Perl that mainly provide an additional layer over an existing language. I was looking at Parse::Yapp, Parse::Lex or even Marpa::R2, but the only concrete example is always the same: a simple calculator that does 43 * 8 + 1. I cannot easily find any other examples so I am wondering if these packages are still a good choice to implement a parser.

Are Parse::Yapp, Parse::Lex or Marpa::R2 still a good solution over a hand-rolled approach?

Where can I find more examples and documentation on these modules? The CPAN pages are usually pretty empty

Community
  • 1
  • 1
nowox
  • 25,978
  • 39
  • 143
  • 293
  • 1
    Check the links [here](https://github.com/choroba/marpa-enhanced-calculator) for non-calculator examples on [Marpa::R2](http://p3rl.org/Marpa::R2) . – choroba Jul 01 '15 at 08:48
  • 1
    Try something like `calc.pl 'a = 43 b = 3 * 8; print a + b'`. But the point was to show the other links :-) – choroba Jul 01 '15 at 10:38
  • I updated the code in GitHub to accept input without a trailing separator. – choroba Jul 01 '15 at 10:47

2 Answers2

4

For small simple parser jobs like this sort of thing, I wrote Parser::MGC. Your particular case of numerical expression evaluation is likely some variant of one of the examples, namely

https://metacpan.org/source/PEVANS/Parser-MGC-0.13/examples/eval-expr.pl

LeoNerd
  • 8,344
  • 1
  • 29
  • 36
2

Marpa::R2 is in heavy and increasing use. IBM advertises their use of it: https://www.ibm.com/developerworks/community/blogs/jalvord/entry/sitworld_itm_situation_audit?lang=en Metacpan lists ~30 direct dependences and there are indirect dependences from those. There are open-source C, ECMAScript parsers. There's more stuff listed on the web site: http://savage.net.au/Marpa.html#Applications

Jeffrey Kegler
  • 841
  • 1
  • 6
  • 8
  • 1
    From this [study](http://drops.dagstuhl.de/opus/volltexte/2012/3513/pdf/6.pdf) Marpa looks pretty inefficient – nowox Jul 01 '15 at 23:50
  • 2
    Note the date; that it is talking about an earlier version of Marpa, Marpa::XS; and the methodological caveats. Alberto was gracious enough to share his paper with me before publication and it inspired a lot of the changes which appeared in Marpa::R2. – Jeffrey Kegler Jul 02 '15 at 00:25