O'Reilly logo

Building Parsers with Java™ by Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required