[antlr-interest] Possible Bug in ANTLR Python

Suman Karumuri mansuk at gmail.com
Tue Oct 18 05:51:39 PDT 2005


Hi all,

I am unsure if this is a bug in antlr python code generation routine,
but it does look like a bug.I am reading the getting started tutorial
by terrence parr and i tried to implement the basic calculator.

I have created the lexer and grammar files, generated the python
classes, imported them into main and startes the main script.

The main script should ideally read a line (from sys.stdin) of input
and after EOL compute the expr(), print expr and exit. But in this
case it is accepting the input and executing it only after i give
another expression as input. So upon giving 2 inputs it is executing
the first one.

To trace this i added a few prints  to the generated parser code whose
output executed as follows:

suman at suman:~/exercise/paper/npl_sw/python/src$ python main.py
2 + 3
Value in atom 2
Value in mexpr 2
Value in atom 3
3
Value in mexpr 3
Value in expr 5
5

suman at suman:~/exercise/paper/npl_sw/python/src$ python main.py
2 * 4
Value in atom 2
Value in atom 4
*
7
Value in atom 7
7
Value in mexpr 56
Value in expr 56
56
suman at suman:~/exercise/paper/npl_sw/python/src$

The ouput is more peculiar, if * is given(actualy mexpr is atom
STAR(*) atom ) .But this is not the case when the input if redirected
from a file as in

python main.py< test.npl

I am attaching the files here. Please add some print statements before
the returns to see the output shown above.

Please clarify if this is a bug.

-Suman
-------------- next part --------------
A non-text attachment was scrubbed...
Name: npl.tar.gz
Type: application/x-gzip
Size: 1567 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20051018/ade783f4/npl.tar.gz


More information about the antlr-interest mailing list