473,657 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Nested compound statements.

The docs say:

A suite can be one or more semicolon-separated simple statements on
the same line as the header, following the header's colon, or it can
be one or more indented statements on subsequent lines. Only the
latter form of suite can contain nested compound statements; the
following is illegal, mostly because it wouldn't be clear to which if
clause a following else clause would belong:

if test1: if test2: print x

What's the rest of the reason? Is it an LL(1) parser limitation?

The error came to my attention through:

with nested(open(arg s[0], "rb"),
open(args[1], "rb")) as (banner, pfaids):
if outfile_path is None:
report(sys.stdo ut, reconcile(banne r, pfaids))
else: with open(outfile_pa th, "w") as outfile:
report(outfile, reconcile(banne r, pfaids))

Instead I must write:

with nested(open(arg s[0], "rb"),
open(args[1], "rb")) as (banner, pfaids):
if outfile_path is None:
report(sys.stdo ut, reconcile(banne r, pfaids))
else:
with open(outfile_pa th, "w") as outfile:
report(outfile, reconcile(banne r, pfaids))

There's nothing terribly wrong with it, I guess, but it does look
"hairier" when really it isn't.

Moreover, "invalid syntax" is a bit terse--but probably it's not worth
it to complicate the grammar just for a better error message.

Finally, any ideas for a prettier version of the above snippet?

--
Neil Cerutti <mr************ ***@gmail.com>
Feb 1 '08 #1
0 1283

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

Similar topics

3
2335
by: Nils Grimsmo | last post by:
hi, i'm having some trouble nesting functions. consider the following: def h(): x = 1 def g(): print x # ok, x is taken from h g()
11
2627
by: Khaled Afiouni | last post by:
Hello, How can I stop/prevent SQL server from running compound SQL statements. I do not want the server to run multiple update/delete/insert/select statements as a batch. Is there an option? /Kaf www.afiouni.com
0
2961
by: Dmitry Tolpeko | last post by:
Hello, Could anybody please explain me why DB2 z/OS 8.1 fails on the simple procedure below: Error: DSNHSMS2 LINE 12 COL 6 NESTED COMPOUND STATEMENTS NOT ALLOWED It failes on DECLARE EXIT HANDLER FOR SQLEXCEPTION
18
7635
by: Rhino | last post by:
I am having a problem with a nested SQL Procedure on DB2 V8.2.1 on Windows. This simple-looking proc is giving me this error message when I try to build it in the Development Center: RHINO.CALLED01: 18: SQL0104N An unexpected token "<cursor declaration>" was found following "". Expected tokens may include: "<SQL statement>". LINE NUMBER=18 SQLSTATE=42601 Here is the source code for the proc; line 18 is the line that begins
46
9911
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are already in a loop." Then he goes on to portray a contrived example that doesn't tell me under what conditions a nested loop might be favoured as a solution? i.e. what are nested loops useful for? What kinds of algorithms are served by nested loops?...
10
3220
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our complexity analyzer tool supposedly does not pick it up. Is it really more efficient? Personally I find this coding style extremely cryptic, misleading and error-prone. I believe that I have removed all traces of proprietary-ness from this coding...
3
2048
by: Jake Emerson | last post by:
I'm attempting to build a process that helps me to evaluate the performance of weather stations. The script below operates on an MS Access database, brings back some data, and then loops through to pull out statistics. One such stat is the frequency of reports from the stations ('char_freq'). I have a collection of methods that operate on the data to return the 'char_freq' and this works great. However, when the process goes to insert the...
25
2236
by: GY2 | last post by:
I writing some documentation and I want to describe a common code structure which is used to step through all the items in a collection (e.g. each file in a subdirectory) while applying more and more restrictive filters so that only the desired items can fall all the way through. This method is so obvious and common it must have a name. What is it or at least, what is the best (short) way to describe it? For Each In If Then If Then
14
19408
by: Jan Schmidt | last post by:
Hi, in a nested do-while-loop structure I would like to "continue" the outer loop. With goto this should be no problem in while-loops. However, for do-while I cannot get it to work (without a strange workaround construct): -- do { // ...
0
8324
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
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
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
8617
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...
1
6176
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
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
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
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
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.