[antlr-interest] Antlr 3 and the newline token problem

Martin Probst mail at martin-probst.com
Sat Nov 26 06:54:28 PST 2005


> I can. Attempting to tack on line/col/offset counting to a lexer via virtual
> method overrides for instance.

That's basically one virtual method call (newline();) per line break,
which is in turn one pointer de-referencing plus a method call per
newline. E.g. with a 4000 line file you get 4000 pointer de-referencing
ops more with a virtual function instead of a "normal" function. I don't
know what you're doing with the 4000 lines you have parsed in the same
time, but are 4000 de-refs really significant compared to stepping
through the parsing rules for 4000 lines of code and building the AST?

> > About the virtual methods: maybe some C++ crack might be able 
> > to change the ANTLR C++ code creation and move lots of the 
> > stuff now handled by virtual functions into some template 
> > magic. That would of course ruin compatibility with old 
> > compilers, so probably both modes should be available.
> 
> My comments also extend to the Java/C# targets. Virtual methods cost more
> than non-virtual methods. This probably isn't a worry in the general case...

Well, with Java/C# the JIT (and whatever the C# equivalent is) can find
methods that are virtual, but don't have any overriding classes, so that
they are inlinable. Still, I can't imagine this gives a real life
difference.

Martin



More information about the antlr-interest mailing list