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 3 1020
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
En Tue, 20 May 2008 16:22:10 -0300, Joe P. Cool
<jo********@goo glemail.comescr ibió:
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
On 21 Mai, 00:12, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
En Tue, 20 May 2008 16:22:10 -0300, Joe P. Cool
<joe.p.c...@goo glemail.comescr ibió:
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 any preconceived ideas about it. I have
noticed, however, that every programmer I talk to who's aware of Python is
also talking about Ruby. So it seems that Ruby has the potential to compete
with and displace Python. I'm curious on what basis it...
|
by: TheShadow1 |
last post by:
safetyTips - this array is in here.js ...
|
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 line of the
text file.
Please help...thx.
|
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) {
<...>
}
|
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, &endptr, 10);
printf("errno=%d\n", errno);
| |
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 ="....whatever";
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
SqlCommand command = connection.CreateCommand();
|
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>
<SCRIPT LANGUAGE="JavaScript">
<xsl:comment>
<!]>
|
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);
|
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 will be highly appreciated.
First, the error that I am getting when I try to connect to the remote host after performing NODE and database catalog is the following:
SQL1336N The remote host "WINSVR2008R2-2" was not found. SQLSTATE=08001. I...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |