Reputation: 734
My grammar contains production code. Is it really possible to mix this with visitors ? (my problem is to implement if cond then block endif )
In terms of performances, is there a difference between production code in grammar vs visitors ? (I have to re-evaluate several programs 30-60 times per second, in the browser on Javascript target. I understood direct production code was closer to compiled code but maybe I'm wrong).
Upvotes: 1
Views: 204
Reputation: 5991
Actions of the type shown only affect the content of the parse-tree -- an e
context node will be created with a return field having the Action computed value. Consequently, there is no bar to subsequently walking the parse tree with a visitor.
Using a visitor (without using the embedded Actions) can achieve the same end results.
Using a visitor will incur some overhead - impossible to say whether it would be significant without testing (using the Java/Antlr runtime, evaluating a relatively complex grammar with multiple walkers over a fairly lengthy source text, takes 3ms average in a warm environment - YMWV).
Upvotes: 1