473,289 Members | 1,929 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,289 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 997
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.