473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What's wrong with that comment?

Hi, I ran into a funny thing when I played with the python parser, to
build a python call graph for learning...

When I have a (special) python program, that runs without any error it
gives an error, when I try to parse it parser.suite. The error is,
when my program has a comment on the last line after an indented
block. Note that there no newline behind "# comment". With a newline
everything is fine.

For example:
#!/usr/bin/env python

from parser import suite, ast2list
fh = file(__file__)
s = fh.read()
fh.close()
ast = suite(s)

while False:
print "hello world"
# comment

Looks like a little bug in parser; but what I don't understand is that
I thought parser was build with the current syntax of python.

So, why can python run the script (an it can if you comment out the
line "ast = suite(s)") but parser can't?

Looking forward for answers...

Ludwig
Jun 27 '08 #1
3 1000
Ludwig Miniatur wrote:
For example:
#!/usr/bin/env python

from parser import suite, ast2list
fh = file(__file__)
s = fh.read()
fh.close()
ast = suite(s)

while False:
print "hello world"
# comment

Looks like a little bug in parser; but what I don't understand is that
I thought parser was build with the current syntax of python.
I didn't read the grammar but I assume that Python grammar requires a
comment to have the form #.*<end-of-line>.
>
So, why can python run the script (an it can if you comment out the
line "ast = suite(s)") but parser can't?
The interpreter probably appends a newline after the input stream as a
friendly service :)

--
Joe

Jun 27 '08 #2
En Tue, 20 May 2008 16:22:10 -0300, Joe P. Cool
<jo********@googlemail.comescribió:
Ludwig Miniatur wrote:
>For example:
#!/usr/bin/env python

from parser import suite, ast2list
fh = file(__file__)
s = fh.read()
fh.close()
ast = suite(s)

while False:
print "hello world"
# comment

Looks like a little bug in parser; but what I don't understand is that
I thought parser was build with the current syntax of python.

I didn't read the grammar but I assume that Python grammar requires a
comment to have the form #.*<end-of-line>.
>>
So, why can python run the script (an it can if you comment out the
line "ast = suite(s)") but parser can't?

The interpreter probably appends a newline after the input stream as a
friendly service :)
Something like that. The last line of source *must* end in a newline (be
it a comment or not); this is a known limitation. See py_compile.py for an
example.

--
Gabriel Genellina

Jun 27 '08 #3
On 21 Mai, 00:12, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Tue, 20 May 2008 16:22:10 -0300, Joe P. Cool
<joe.p.c...@googlemail.comescribió:
Ludwig Miniatur wrote:
For example:
#!/usr/bin/env python
from parser import suite, ast2list
fh = file(__file__)
s = fh.read()
fh.close()
ast = suite(s)
while False:
print "hello world"
# comment
Looks like a little bug in parser; but what I don't understand is that
I thought parser was build with the current syntax of python.
I didn't read the grammar but I assume that Python grammar requires a
comment to have the form #.*<end-of-line>.
So, why can python run the script (an it can if you comment out the
line "ast = suite(s)") but parser can't?
The interpreter probably appends a newline after the input stream as a
friendly service :)

Something like that. The last line of source *must* end in a newline (be
it a comment or not); this is a known limitation. See py_compile.py for an
example.

--
Gabriel Genellina
Uoh, you never stop learning...
Thanks for the explanation. I thought something like that, but it made
me some headaches.

Lutz
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
62
by: TheShadow1 | last post by:
safetyTips - this array is in here.js ...
1
by: cylin | last post by:
Dear all, I am a newbie using lex and yacc. I really don't know what's wrong with my code, because the output is not what I want. My yacc rules don't match, and yylex seems just read only one...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
15
by: robert maas, see http://tinyurl.com/uh3t | last post by:
Here's the source: #include <stdio.h> #include <errno.h> main () { char* str = "9999999999"; long long int llin; char* endptr; /* Set by strtoll */ int nch; errno = 0; llin = strtoll(str,...
4
by: GS | last post by:
the procedure when executed from c#, it does update or insert but I got result code of -1 return to c# is not successful execution of stored proc 0 or number rows affected? connectionString...
16
by: sinbao | last post by:
"'copyof.xsl" <?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> ...
10
by: questions | last post by:
# include <stdio.h> # include <math.h> int main() { long int x,y; printf("enter an integer\n"); scanf("%d",&x); y=x%pow(10,3);
0
by: okonita | last post by:
Hi all, I am having a DB2 connectivity problem that I hope someone can help me resolve. I need this to test Replication and such other things. What am I doing wrong here? Any help that I can get...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.