[antlr-interest] Problem with python runtime example (stdin)
hfrequency at gmail.com
Fri Jun 20 14:31:40 PDT 2008
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.
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)
> eval = Eval(nodes)
> This is a copy-paste of the code from
> 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"
>>> 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?
More information about the antlr-interest