Production Rule

The ProductionRule pattern adds some power and reuse to http://st-www.cs.uiuc.edu/cgi-bin/wikic/wikic?InterpreterPattern. [[InterpreterPattern?]]

Doesn't seem to be any mention of ProductionRule there

There are two main improvements. First, it turns out that you can create new production rules as as objects (instead of as classes). This means that in five programming statements you can define a language that has five grammar rules. Powerful!

The second improvement is the use of application-specific Stackers instead of visitors. Stackers are helpers that get plugged into production rules. When you write a production rule, you can hand it a Stacker that does whatever you want to have happen when the rule fires. For example, if you're parsing an HTML file, when you see some <BOLD> stuff, you can have a stacker set the text style to be bold.

Any relation to Assemblers and Assemblies?

I've written this up in more detail in an article that I'm hoping will show up in Java Report in a few months. If you're aching to know more and can't wait, drop me a note at Steve dot Metsker@acm dot org.


See also RewriteRules


EditText of this page (last edited February 14, 2008) or FindPage with title or text search