473,624 Members | 2,216 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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").re ad())
ast
Module(None, Stmt([Assign([AssName('RED', 'OP_ASSIGN')], Const('red')), Assign([AssName('BLUE', 'OP_ASSIGN')], Const('blue'))]))
>>compiler.walk (ast, compiler.visito r.ExampleASTVis itor, verbose=10)
<class compiler.visito r.ExampleASTVis itor at 0x831ce3c>
compiler.walk (ast, compiler.visito r.ExampleASTVis itor(), verbose=10)
<compiler.visit or.ExampleASTVi sitor instance at 0x81f0eac>

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

dispatch Module

<compiler.visit or.ExampleASTVi sitor instance at 0x835074c>
compiler.ast.Mo dule
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.getChild Nodes of Module(None, Stmt([Assign([AssName('RED', 'OP_ASSIGN')], Const('red')), Assign([AssName('BLUE', 'OP_ASSIGN')], Const('blue'))]))>
getChildren <bound method Module.getChild ren 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 1537

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

Similar topics

2
2327
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 Python from source, because it also requires a change to Grammar. 1. Edit Python-2.3/Grammar/Grammar and add an alternative to the "listmaker" production: -listmaker: test ( list_for | (',' test)* )
28
2249
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 compiler will simply stop when it is missing an implementation for a procedure or whatever.
102
5646
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 can't tell where a bracket is missing.... a few weeks have past, I requested a feature for the delphi ide/editor "automatic identation of code in begin/end statements etc" and today when I woke up I suddenly released a very simple solution for this...
2
3725
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 the second parameter of the tuple (a list of directories). However, since it is a tuple, you cannot use "filter" on it, since it would mean reassigning it: for dir_tuple in os.walk('/home'):
22
5366
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 previousSibling could be a node which has childNodes and therefore the 'true' previousSibling would be the *deepest* lastChild of the previousSibling... For example, given this graph: 1 myAnchor nodeType 1 2 myAnchorText1 nodeType 3
7
4543
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, files in os.walk('/directory/'): print root # print dirs # print files
45
2261
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 \n",*(address+1)*address); when I compile the code I get this warning from gcc (although it
1
2494
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 a visitor to walk the generated AST: http://docs.python.org/lib/module-compiler.html I can build the AST, but I can't figure out how to write the visitor. The package documentation didn't help me out that much, and I
4
1347
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 question regards the way that the visit callback modifies the names list. Basically, my simple example is: ############################## def listUndottedDirs( d ): dots = re.compile( '\.' )
0
8172
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,...
0
8620
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8335
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,...
0
8474
tracyyun
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...
0
7158
agi2029
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...
1
6110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2605
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
2
1482
bsmnconsultancy
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...

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.