[antlr-interest] Interpreter built-in functions: code in grammar or use function table?

Michael Bedward michael.bedward at gmail.com
Sun Oct 28 13:22:27 PDT 2012


There would have to be some really pressing reason to do anything
other than a simple table lookup. The other approach seems like the
road to bloated grammars.

Michael

On 29 October 2012 06:17, Michael Cooper <tillerman35 at yahoo.com> wrote:
> I need the usual set of built-in functions for my (java-based) interpreter.  Stuff like string manipulation functions, math functions, date functions, etc.
>
> I'm on a fence about how to implement them.
>
> On the one hand, I could do it with two simple grammar rules.  One for method invocations and another for function calls.  Then all I would have to
> do is maintain a function table with a list of built-in functions.  I already maintain a function table for functions in the input, so it wouldn't be much of
> a stretch to adapt that to built-in functions as well.
>
> The other alternative is to define each built-in function in the grammar itself.  E.g. a rule for "println" and another for "substr" and another for "randbetween" etc. etc.
> The advantage to that approach is that they appear in the railroad diagrams in Eclipse.  Those are pretty handy for documentation.  I suppose I could write a
> little helper function to output function definitions to ANTLR-compatible grammar rules.
>
> Any thoughts?
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list