Re: [sv-bc] Ambiguity in comma-separated for loop initializer list

From: Brad Pierce <Brad.Pierce@synopsys.com>
Date: Thu Mar 11 2004 - 16:28:52 PST

I agree with Paul's BNF proposal of Jan. 20 in

     http://www.eda.org/sv-bc/hm/1486.html

for SV-BC issue 172

     http://www.eda.org/sv-bc/display_issue.cgi?issue_num=172

In Syntax 8-5 and A.6.8, REPLACE

   for_initialization ::=
        list_of_variable_assignments
        | data_type list_of_variable_assignments
               { , data_type list_of_variable_assignments }

WITH

    for_initialization ::=
        [data_type] list_of_variable_assignments

AND, as a consequence, in the last example of 8.5.2, REPLACE

    done = 0, int j = 0

WITH

    j = 0

-----Original Message-----
From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org]On Behalf Of Paul
Graham
Sent: Tuesday, January 20, 2004 9:37 AM
To: sv-bc@eda.org
Subject: [sv-bc] Ambiguity in comma-separated for loop initializer list

In view of the syntactic similarity between a reg declaration with an
initializer and the initializer in a for loop, I wonder if the following
loop:

1) for (int i = 1, j = 2; ...

is equivalent to:

2) for (int i = 1, int j = 2; ...

That is, should the construct

3) int i = 1, j = 2;

be interpreted as a reg declaration which declares both i and j, or should
each comma-delimited initializer be treated independently with respect to
declarations? This makes a difference, especially if, say, j is already
declared outside the loop.

The Gnu g++ compiler treats 1) as two declarations, for both i and j. In
fact, g++ disallows the following:

4) for (int i = 1, int j = 2; ...

I suggest that we do the same thing as C++ (or at least the same as g++),
and make it clear that in the case that one index variable is declared in
the scope of the for loop, then all the index variables appearing in the
initializer are declared as part of the same declaration. Right now the
grammar allows example 4), with multiple, possibly different, data types.

So I would suggest changing the grammar from:

    for_initialization ::=
        list_of_variable_assignments
        | data_type list_of_variable_assignments { , data_type
list_of_variable_assignments }

to:

    for_initialization ::=
        [data_type] list_of_variable_assignments

Paul
Received on Thu Mar 11 16:28:55 2004

This archive was generated by hypermail 2.1.8 : Thu Mar 11 2004 - 16:28:59 PST