473,387 Members | 1,549 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.

compiler.walk() what am I missing?

Here's a trivial little Python session which attempts to use compiler.walk
(mostly unsuccessfully):

% python
Python 2.4.2 (#1, Feb 23 2006, 12:48:31)
[GCC 3.4.1] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>import compiler
ast = compiler.parse(open("a.py").read())
ast
Module(None, Stmt([Assign([AssName('RED', 'OP_ASSIGN')], Const('red')), Assign([AssName('BLUE', 'OP_ASSIGN')], Const('blue'))]))
>>compiler.walk(ast, compiler.visitor.ExampleASTVisitor, verbose=10)
<class compiler.visitor.ExampleASTVisitor at 0x831ce3c>
compiler.walk(ast, compiler.visitor.ExampleASTVisitor(), verbose=10)
<compiler.visitor.ExampleASTVisitor instance at 0x81f0eac>

I did manage to get a verbose print the first time I executed this:
>>compiler.walk(ast, compiler.visitor.ExampleASTVisitor(), walker=compiler.visitor.ExampleASTVisitor(), verbose=10)
which emitted nice verbose stuff like

dispatch Module

<compiler.visitor.ExampleASTVisitor instance at 0x835074c>
compiler.ast.Module
asList <bound method Module.asList of Module(None, Stmt([Assign([AssName('RED', 'OP_ASSIGN')], Const('red')), Assign([AssName('BLUE', 'OP_ASSIGN')], Const('blue'))]))>
doc None
getChildNode <bound method Module.getChildNodes of Module(None, Stmt([Assign([AssName('RED', 'OP_ASSIGN')], Const('red')), Assign([AssName('BLUE', 'OP_ASSIGN')], Const('blue'))]))>
getChildren <bound method Module.getChildren of Module(None, Stmt([Assign([AssName('RED', 'OP_ASSIGN')], Const('red')), Assign([AssName('BLUE', 'OP_ASSIGN')], Const('blue'))]))>
lineno None
...

but successive calls just yielded the more electron-conserving:

dispatch Module
dispatch Stmt
dispatch Assign
dispatch AssName
dispatch Const
dispatch Assign
dispatch AssName
dispatch Const

What am I doing wrong?

Thanks,

Skip
Jul 11 '06 #1
0 1528

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...
28
by: Skybuck Flying | last post by:
Hi, I think I understand now a bit better what the difference is between a c compiler and a pascal compiler. For example: When compiling source code with a pascal compiler. The pascal...
102
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
2
by: Ministeyr | last post by:
Hello, os.walk doc: http://www.python.org/doc/2.4/lib/os-file-dir.html#l2h-1625 When walking top to bottom, it allows you to choose the directories you want to visit dynamically by changing...
22
by: delraydog | last post by:
It's quite simple to walk to the DOM tree going forward however I can't figure out a nice clean way to walk the DOM tree in reverse. Checking previousSibling is not sufficient as the...
7
by: KraftDiner | last post by:
The os.walk function walks the operating systems directory tree. This seems to work, but I don't quite understand the tupple that is returned... Can someone explain please? for root, dirs,...
45
by: alertjean | last post by:
Or may be I am stubborn or dumb ... of not putting in a * in the typecast. This is code I am worrying about long long b=1; int *address ; address=(int)&b; printf ("%x %x...
1
by: Efrat Regev | last post by:
Hello, I'm trying to write something that will translate Python code to pseudo-code (for teaching purposes). Googling around indicated that the compiler module is pertinent, especially creating...
4
by: Joe Ardent | last post by:
Good day, everybody! From what I can tell from the archives, this is everyone's favorite method from the standard lib, and everyone loves answering questions about it. Right? :) Anyway, my...
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
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.