antlr problem

222 views
Skip to first unread message

Mezzovento

unread,
Jan 21, 2009, 11:57:37 AM1/21/09
to java2python-discuss
Hi,
I've installed j2p with antlr 2.7.7 as prerequisites, but when I run
j2py somecode.java the following error occured:

Traceback (most recent call last):
File "/usr/bin/j2py", line 9, in <module>
from java2python.lib.lexer import Lexer
File "/usr/lib/python2.5/site-packages/java2python/lib/lexer.py",
line 4, in <module>
import antlr
ImportError: No module named antlr

even if antlr is installed ...

Please help me.
Thanks

Troy Melhase

unread,
Jan 21, 2009, 1:25:08 PM1/21/09
to java2pyth...@googlegroups.com
Hi there,

Your problem is either (1) you don't have the antlr python runtime, or
(2) you have it installed by it's not in your PYTHONPATH.

To fix the first item, download the antlr 2.7 tar.gz file, unpack it,
and from the antlr-2.7.2/lib/python/ directory, run the setup.py
installer.

To fix the second item, locate the antlr.py file and adjust your
PYTHONPATH environment variable to reference the directory.

Please let me know if I can help further,

troy

Mezzovento

unread,
Jan 22, 2009, 5:23:31 AM1/22/09
to java2python-discuss
Ok, thanks, was a PYTHONPATH issue.

Now I try this:
# j2py test.java
but j2py seems fallen in a infinite loop, then I stop it with a ctrl-
C:

Traceback (most recent call last):
File "/usr/bin/j2py", line 110, in <module>
ret = transform(options)
File "/usr/bin/j2py", line 31, in transform
P.compilationUnit()
File "/usr/lib/python2.5/site-packages/java2python/lib/parser.py",
line 192, in compilationUnit
la1 = self.LA(1)
File "/usr/local/lib/antlr.py", line 2025, in LA
return self.inputState.input.LA(i)
File "/usr/local/lib/antlr.py", line 1683, in LA
self.fill(k)
File "/usr/local/lib/antlr.py", line 1677, in fill
self.queue.append(self.input.nextToken())
File "/usr/lib/python2.5/site-packages/java2python/lib/lexer.py",
line 246, in nextToken
la1 = self.LA(1)
File "/usr/local/lib/antlr.py", line 1282, in LA
c = self.inputState.input.LA(i)
File "/usr/local/lib/antlr.py", line 742, in LA
self.fill(k)
File "/usr/local/lib/antlr.py", line 793, in fill
c = self.input.read(1)

The simple test.java code is:

public final class Util {

public static boolean reportException(Class context,Throwable
t) {
String className = context.getName();
for (StackTraceElement element : t.getStackTrace()) {
if (element.getClassName().equals(className))
{
System.out.println("** Caught
exception **");
System.out.println("Class :
"+className);
System.out.println("Method:
"+element.getMethodName());
System.out.println("File :
"+element.getFileName());
System.out.println("Line :
"+element.getLineNumber());
System.out.println("Message:");
int i = 0;
while (t != null) {
i++;
System.out.println(""+i
+":"+t.getMessage());
t = t.getCause();
}
if (i == 0) System.out.println
("...unknown...");
return true;
}
}
if (t.getMessage().equals("Connection refused")) {
System.out.println("** Connection refused
**");
System.out.println("Is the webservice
running?");
return true;
}
return false;
}
}

Any idea ?

Bye,
Davide

Troy Melhase

unread,
Jan 22, 2009, 1:00:41 PM1/22/09
to java2pyth...@googlegroups.com
The j2py command expects input from either (a) stdin, or (b) from the
filename specified with the "-i" switch. It's not caught in a loop,
it's waiting for you.

You can get this going with one of these:

$ j2py < test.java
$ j2py -i test.java

HTH,

troy
Reply all
Reply to author
Forward
0 new messages