On Tue, May 20, 2008 at 6:50 PM, Terence Parr <[EMAIL PROTECTED]> wrote: > > On May 20, 2008, at 3:53 AM, Benjamin Niemann wrote: >> Usually I stayed very close to the Java implementation when porting it >> to Python. IIRC this is one of the cases where my version looked very >> different from Java, because Python has a much more powerful built-in >> support for lists. There are a few occasions where I boiled down 30 >> lines of Java code to 2 or 3 Python lines ;) > > Sweet...is thereAn obvious java v python example you can show?
Mmm.. let's see.. http://fisheye2.cenqua.com/browse/antlr/runtime/Java/src/org/antlr/runtime/tree/BaseTree.java?r=4921#l204 vs. http://fisheye2.cenqua.com/browse/antlr/runtime/Python/antlr3/tree.py?r=4914#l800 The comparison is not entirely fair (and it was just 20 lines, not 30..), because your version does some extra optimization by overwriting as many array indeces as possible. But that could be done without manual iterations as well by using the slice operator, e.g. for (int j=0; j<numNewChildren; j++) { children.set(startChildIndex+j, newChildren.get(j)); } would looks something like children[startChildIndex:startChildIndex+numNewChildren] = newChildren[0:numNewChildren] And scanning through the code, I've just seen numerous places that could be written much more elegant and/or efficient, but I just did a mostly 1:1 conversion to get things done. -Ben _______________________________________________ antlr-dev mailing list [email protected] http://www.antlr.org:8080/mailman/listinfo/antlr-dev
