16.7. Building Runtime Functions

When you create an imperative language, you often want to provide your users the ability to compose functions in your language. For example, Sling allows a user to type an expression such as abs(sin(2*pi*t)). One way to represent this function is as a new method—say, absSin2PiT()—that accepts a variable t and returns Math.abs(Math.sin(2*Math.PI*t)). The Sling environment does not create a new method but rather creates an object that represents this new function.

16.7.1. Function Wrapping

The desire to create new functions while a parser is running creates a paradox: You want to create a new method at runtime, but you must know all method names at compile time. A resolution to this paradox is as follows:

  • Design ...

Get Building Parsers with Java™ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.