First use of Marpa scanless in 'production'

105 views
Skip to first unread message

Peter Stuifzand

unread,
Jan 7, 2013, 5:05:10 PM1/7/13
to marpa-...@googlegroups.com
Hello,

today I wrote this parser for a simple DSL.

parser/generator: https://github.com/pstuifzand/star-linemode/blob/build/build/codes.pl
example code: https://github.com/pstuifzand/star-linemode/blob/build/codes.spec

I would like to show it as an example of how I used Marpa for something useful. The language is something I come up with today.

I had already written a bit of the code behind it. I knew what it needed to do in terms of pack and it's format. This new 'language' let's me specify method names and the bytes that are used in the formatting language. The number in between is the number of arguments that can be used.

So today I wanted to write a small language from which I could generate the code that I needed. I tried a few things and wrote a short text file with the codes. I already knew from before that I could separate this into a few rules with different prefixes. I tried the prefix block with within it the rules that use the prefix.

After that I also wanted to use <spec rule>s outside the <prefix block>, which is as simple as adding "| <spec rule>" to <spec decl>.

After the parse is completed, all rules are normalized by inserting the prefixes before every rules own bytes. Then from each rule a piece of Perl code is generated.

Before Marpa I would write this same with regexes (or some eval hack, which you can see in the other branch). I would also have avoided any kind of recursive structure or block.

Total time to write: about 1 hour.

--
Peter Stuifzand

Durand Jean-Damien

unread,
Jan 7, 2013, 5:18:45 PM1/7/13
to marpa-...@googlegroups.com
Very nice -;

Jeffrey Kegler

unread,
Jan 7, 2013, 11:52:43 PM1/7/13
to marpa-...@googlegroups.com
Very nice. And it's not quite a week old. -- jeffrey
Reply all
Reply to author
Forward
0 new messages