0

I am trying to do continuation passing style for a simple programming language made with antlr. Typically you would have an eval procedure that takes as arguments the expression to be evaluated as well as the continuation of that expression. I guess it would be quite elegant to add an additional continuation parameter to the visitor's visit methods (or for the listener).

However, when I generate the parser code with the antlr jar, the visit methods only take one parameter, namely the context (i.e., the tree).

So my question is, how can I add additional parameters to the visit methods such that I get this:

/**
 * {@inheritDoc}
 *
 * <p>The default implementation does nothing.</p>
 */
@Override public void enterStart(Parser.StartContext ctx, Continuation cnt) { }

Instead of the currently auto generated code:

/**
 * {@inheritDoc}
 *
 * <p>The default implementation does nothing.</p>
 */
@Override public void enterStart(Parser.StartContext ctx) { }

If it is not possible to add additional parameters to the visitor's visit methods, how would one accommodate the continuation passing style in antlr?

Thanks a lot!

Plegeus
  • 139
  • 11
  • You could make a private version of the tool templates to generate what you want. – kaby76 Mar 31 '23 at 21:10
  • I don’t think I get what you mean, could you elaborate please? – Plegeus Mar 31 '23 at 22:34
  • Modify [this code](https://github.com/antlr/antlr4/blob/master/tool/resources/org/antlr/v4/tool/templates/codegen/CSharp/CSharp.stg) then follow the build procedure [here](https://github.com/antlr/antlr4/blob/master/doc/building-antlr.md). You will have a jar to generate your parser code with CPS. Use "find" to find the jar. – kaby76 Mar 31 '23 at 23:26
  • That seems like a big hastle, I think it might be simpler to just write one eval procedure to dispatch on the context if you get what I mean. – Plegeus Apr 01 '23 at 07:47

1 Answers1

0

ow can I add additional parameters to the visit methods

You cannot add any parameters to enter..., exit... or visit... methods.

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288