LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Why does compiler accepts the following structure

typedef struct dc{

char name[32];

int value;
ine scaling;

} dataContainer ;

dataContainer mylist[]= { {“test1”,0,1},
{“test2”,0,1},
{“test3”,0,1},
};

From the abouve code, why does the compiler accepts the ,
at the end of the list "test3".

Perhaps there must a change in the anci-c grammer..?
0 Kudos
Message 1 of 3
(3,150 Views)
Hi Monky,
   nice tip!!!!!

   Have a look to this, from ansi c standard:

    6.7.2.1 Structure and union specifiers
       Syntax
1 struct-or-union-specifier:
     struct-or-union identifieropt { struct-declaration-list }
     struct-or-union identifier
struct-or-union:
     struct
     union
struct-declaration-list:
    struct-declaration
    struct-declaration-list struct-declaration
struct-declaration:
    specifier-qualifier-list struct-declarator-list ;
specifier-qualifier-list:
    type-specifier specifier-qualifier-listopt
    type-qualifier specifier-qualifier-listopt
struct-declarator-list:
   struct-declarator
   struct-declarator-list , struct-declarator
struct-declarator:
   declarator
   declaratoropt : constant-expression

According to this, you seems to be right!!!

Anyway, Dev-Cpp (a C++ compiler, actually...) performs as CVI.....






0 Kudos
Message 2 of 3
(3,137 Views)
When i wrote a compiler, i alwaya had a tedious trouble with the comma separated lists.
still, we have a nice solution with the LALR(1) grammers by defining immaginary terminals.
If we construct a seprate node for structure and we must ommit the comma separated list in concrete parse tree and we can
define a dummy terminal as an identifier for the end of the list. This can be recognaized in abstract syntax tree
finally it can be retrived as a last element or id in the abstract syntax tree.
 
Not only for structure it happend foe the array as well....!
 
So i can say the most lower level of the concrete parse tree and abstract syntax tree has to be changed...
Well, in this case it will be very complecated shift reduce conflicts cán occur because of the Identifier, but some
Advanced LALR(1) parsers have such a imaginary terminal as solution.....
 
finally it is possible to edit that grammer....
0 Kudos
Message 3 of 3
(3,124 Views)