473,419 Members | 1,667 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,419 software developers and data experts.

compiler AST

Hi,

I am working on a reverse-engineering system that relies on comments. I
have taken a look at the "compile" module in the Python library. Quite
expectedly, the AST does not contain comment lines. The only exception I
have noticed is the very first comment in the source, which is
interpreted as the module's docstring and is surprisingly also stored in
the AST as a "discardable"-type node. This leaves me with the dismal
task of reading the source on my own, parsing the comments and then
matching them with the AST through the lineno node attribute. Which is a
waste, because the compiler has been there before me. (For my own
reasons, I had rather use comments than resort to such esoteric but
compiler-friendly means as dummy variables etc.)

My question: Is there a way to configure the Python compiler to keep All
comments from the source as AST nodes (e.g. "discardable")?

Avner.
Jul 18 '05 #1
1 1561
The first comment in the source is not the docstring; iff the first
statement in the module is a string, this is the docstring. Comments are
delimited by # and \n. Strings are in quotes.

AST does not parse comments, but it does parse docstrings. There are
available in the .doc attribute of nodes that can have them.

On Sun, Oct 03, 2004 at 05:50:31PM +0200, Avner Ben wrote:
Hi,

I am working on a reverse-engineering system that relies on comments. I
have taken a look at the "compile" module in the Python library. Quite
expectedly, the AST does not contain comment lines. The only exception I
have noticed is the very first comment in the source, which is
interpreted as the module's docstring and is surprisingly also stored in
the AST as a "discardable"-type node. This leaves me with the dismal
task of reading the source on my own, parsing the comments and then
matching them with the AST through the lineno node attribute. Which is a
waste, because the compiler has been there before me. (For my own
reasons, I had rather use comments than resort to such esoteric but
compiler-friendly means as dummy variables etc.)

My question: Is there a way to configure the Python compiler to keep All
comments from the source as AST nodes (e.g. "discardable")?

Jul 18 '05 #2

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

Similar topics

2
by: Jeff Epler | last post by:
Hello. Recently, Generator Comprehensions were mentioned again on python-list. I have written an implementation for the compiler module. To try it out, however, you must be able to rebuild...
13
by: Bryan Parkoff | last post by:
You may notice that switch (...) is much faster than function that can gain a big improved performance because it only use JMP instruction however function is required to use CALL, PUSH, and POP...
10
by: Bjorn | last post by:
I'm using interfaces in C++ by declaring classes with only pure virtual methods. If then someone wants to implement the interface they needs to inherit from the class. If the implementing class...
7
by: Tao Wang | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, I saw cuj's conformance roundup, but the result is quite old. I think many people like me want to know newer c++ standard conformance test...
14
by: joshc | last post by:
I'm writing some C to be used in an embedded environment and the code needs to be optimized. I have a question about optimizing compilers in general. I'm using GCC for the workstation and Diab...
16
by: pj | last post by:
(Was originally, probably wrongly, posted to the vc subgroup.) (This doesn't appear to be a c# problem, but a problem with a bug in the Visual Studio c# compiler, but, any help will be welcome...)...
0
by: rollasoc | last post by:
Hi, I seem to be getting a compiler error Internal Compiler Error (0xc0000005 at address 535DB439): likely culprit is 'BIND'. An internal error has occurred in the compiler. To work around...
3
by: Mark Rockman | last post by:
------ Build started: Project: USDAver2, Configuration: Debug .NET ------ Preparing resources... Updating references... Performing main compilation... error CS0583: Internal Compiler Error...
6
by: toton | last post by:
Hi, Anyone have a link to comparative study of different C++ compilers and how much they conform to C++ language standard? Most of the big platforms I know have GCC which well supports C++...
41
by: Miroslaw Makowiecki | last post by:
Where can I download Comeau compiler as a trial version? Thanks in advice.
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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...
1
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.