Decl Struct -- Dichiarazione delle Strutture e Union


Le strutture e le union permettono di deinire un layout di memoria. La grammatica prevista è la seguente.

declaration: struct_decl_stm
struct_decl_stm: struct_decl ';'
struct_decl: struct_type comment(?) struct_body
struct_body: '{' struct_item(s) '}'
struct_item: simple_item
           | decl_item
           | anon_item
simple_item: type variable_block
decl_item: struct_decl variable_block
anon_item: struct_tag comment(?) struct_body variable_block
variable_block: variable_inter(s?) variable_last
variable_last: variable ';' comment(?)
variable_inter: variable ',' comment(?)
variable: IDENTIFIER array_decl(s?)
array_decl: '[' NUMBER ']'
type: arlib_type
    | struct_type
    | simple_type
simple_type: CHAR
           | UCHAR
           | SHORT
           | USHORT
           | INT
           | UINT
           | LONG
           | ULONG
           | DTJUL
           | FLOAT
           | DOUBLE
struct_type: struct_tag IDENTIFIER
arlib_type: 'clock_s'
struct_tag: 'struct'
          | 'union'
CHAR:       'char'
UCHAR:      'uchar'
SHORT:      'short'
USHORT:     'ushort'
INT:        'int'
UINT:       'uint'
LONG:       'long'
ULONG:      'ulong'
DTJUL:      'dtjul'
LDTJUL:     'ldtjul'
FLOAT:      'float'
DOUBLE:     'double'
UCHAR:      /unsigned\s+char/
USHORT:     /unsigned\s+short/
UINT:       /unsigned\s+int/
ULONG:      /unsigned\s+long/
comment: line_comment(s?) block_comment(s?)
line_comment: / \/ \/ .*? $/xm
block_comment: /\s* \/ \* .*? \* \/ /xms

Un esempio di codice.

struct tglaind                          // Indirizzo
                                        /* Il tracciato contiene tutti i campi di un indirizzo
                                           questi campi sono da trattare con le pinze */
    {
    char            c_ang[10];          // FT_CODEX c_ang non va
    char            t_ind;              // t_ind non mi piace
                                        /* che cosa non va? */
    ushort          progr,              // FT_USHORT(3) campo progr
                                        /* Questo campo conta ...
                                           ... conta ...
                                           fino alla fine del mondo */
                    numr;               // campo numr
    char            ind[3][36];         // FT_TEXTV Indirizzo
    char            local[36];          // FT_TEXTV Località
    char            cap[10];            // FT_CODEN Codice di avviamento Postale
    char            prov[6];            // FT_CODEX Provincia
    char            c_naz[6];           // FT_CODEX Nazione
    ...
    };
dsg.tag.decl.struct • LastModified: 14-9-2007 • John Peter Arnold