Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Back Ends: Making Expression Templates Do Useful Work

Expression Evaluation: Imparting Behaviors with a Context
Evaluating an Expression with proto::eval()
Defining an Evaluation Context
Proto's Built-In Contexts
default_context
null_context
callable_context<>
Expression Transformation: Semantic Actions
Activating Your Grammars
Handling Alternation and Recursion
Callable Transforms
Object Transforms
Example: Calculator Arity
Transforms With State Accumulation
Passing Auxiliary Data to Transforms
Implicit Parameters to Primitive Transforms
Unpacking Expressions
Separating Grammars And Transforms
Proto's Built-In Transforms
Building Custom Primitive Transforms
Making Your Transform Callable

Now that you've written the front end for your EDSL compiler, and you've learned a bit about the intermediate form it produces, it's time to think about what to do with the intermediate form. This is where you put your domain-specific algorithms and optimizations. Proto gives you two ways to evaluate and manipulate expression templates: contexts and transforms.

Two ways to evaluate expressions! How to choose? Since contexts are largely procedural, they are a bit simpler to understand and debug so they are a good place to start. But although transforms are more advanced, they are also more powerful; since they are associated with rules in your grammar, you can select the proper transform based on the entire structure of a sub-expression rather than simply on the type of its top-most node.

Also, transforms have a concise and declarative syntax that can be confusing at first, but highly expressive and fungible once you become accustomed to it. And -- this is admittedly very subjective -- the author finds programming with Proto transforms to be an inordinate amount of fun! Your mileage may vary.


PrevUpHomeNext