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

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


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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: text/x-python
Size: 520 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20080620/6be6f4e1/attachment.py 


More information about the antlr-interest mailing list