[antlr-interest] Problem with python runtime example (stdin)

Cesar Otero hfrequency at gmail.com
Fri Jun 20 14:51:57 PDT 2008


OK, my python installation is acting screwy :-(

Running the same program under either dos or python win, it works just
fine. But, if I run the program with Tkinter, the sys.stdin returns an
rpcProxy object. So, it's definitely not an antlr issue.

Thanks again for the feedback Ben!

Regards,
Cesar

On Fri, Jun 20, 2008 at 5:31 PM, Cesar Otero <hfrequency at gmail.com> wrote:
> Hi again:
>
> I think I have an idea of what the problem is.
>
> sys.stdin is suppose to be for standard input, correct? But checking
> the object in python, I get that stdin is a an rpcProxy object.
>
> Regards,
> Cesar
>
> On Fri, Jun 20, 2008 at 5:01 PM, Cesar Otero <hfrequency at gmail.com> wrote:
>> Hi Ben:
>>
>> Thanks for the reply! Here's the test.py as an attachment. (This is
>> maybe the third time in my life that I post to a newsgroup, I'm
>> assuming that's how I post a file...)
>>
>> Just in case here is the code:
>>
>> import sys
>> import antlr3
>> import antlr3.tree
>> from ExprLexer import ExprLexer
>> from ExprParser import ExprParser
>> from Eval import Eval
>>
>> char_stream = antlr3.ANTLRInputStream(sys.stdin)
>> lexer = ExprLexer(char_stream)
>> tokens = antlr3.CommonTokenStream(lexer)
>> parser = ExprParser(tokens)
>> r = parser.prog()
>>
>> # this is the root of the AST
>> root = r.tree
>>
>> nodes = antlr3.tree.CommonTreeNodeStream(root)
>> nodes.setTokenStream(tokens)
>> eval = Eval(nodes)
>> eval.prog()
>>
>> This is a copy-paste of the code from
>> http://www.antlr.org/wiki/pages/viewpage.action?pageId=4554829.
>>
>> Regards,
>> Cesar
>>
>> On Fri, Jun 20, 2008 at 4:42 PM, Benjamin Niemann <pink at odahoda.de> wrote:
>>> Hi Cesar,
>>>
>>> On Fri, Jun 20, 2008 at 9:43 PM, Cesar Otero <hfrequency at gmail.com> wrote:
>>>> Greetings to everyone!
>>>>
>>>> I recently stumbled onto this wiki entry "Book Examples Modified for Python"
>>>>
>>>> http://www.antlr.org/wiki/pages/viewpage.action?pageId=4554829
>>>>
>>>> Generating the grammar files works just fine. But, when I go to
>>>> execute the test.py I get the following error message:
>>>>
>>>> ####
>>>>
>>>> Traceback (most recent call last):
>>>>  File "C:/grammars/test.py", line 8, in <module>
>>>>    char_stream = antlr3.ANTLRInputStream(sys.stdin)
>>>>  File "C:\Python25\lib\site-packages\antlr_python_runtime-3.0.1-py2.5.egg\antlr3\streams.py",
>>>> line 534, in __init__
>>>>    data = file.read()
>>>> AttributeError: read
>>>>
>>>> ####
>>>
>>> That is indeed very strange. Looks like your sys.stdin is not a file object?!?!
>>> Can you post your test.py?
>>>
>>> -Ben
>>>
>>
>


More information about the antlr-interest mailing list