Changeset 6c3744e for translator/Parser


Ignore:
Timestamp:
Jan 19, 2015, 6:29:10 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
f7f6785
Parents:
0b8cd722
Message:

add list initializer, formatting changes

Location:
translator/Parser
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • translator/Parser/TypeData.cc

    r0b8cd722 r6c3744e  
    696696            } else {
    697697                switch ( ret ) {
     698                  case BasicType::LongLongSignedInt:    // PAB
     699                    ret = BasicType::LongLongUnsignedInt;
     700                    break;
     701                  case BasicType::LongSignedInt:
     702                    ret = BasicType::LongUnsignedInt;
     703                    break;
    698704                  case BasicType::SignedInt:
    699705                  case BasicType::ShortSignedInt:
     
    715721            } else {
    716722                switch ( ret ) {
     723                  case BasicType::LongLongSignedInt:    // PAB
     724                    ret = BasicType::LongLongUnsignedInt;
     725                    break;
    717726                  case BasicType::LongSignedInt:
    718727                    ret = BasicType::LongUnsignedInt;
  • translator/Parser/cfa.y

    r0b8cd722 r6c3744e  
    1010 * Created On       : Sat Sep  1 20:22:55 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Wed Jan  7 09:19:57 2015
    13  * Update Count     : 906
     12 * Last Modified On : Sat Jan 17 09:23:45 2015
     13 * Update Count     : 908
    1414 */
    1515
    16 /* This grammar is based on the ANSI99 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on the
    17    C grammar by James A. Roskind, specifically parts of DECLARATIONS and EXTERNAL DEFINITIONS.  While parts
    18    have been copied, important changes have been made in all sections; these changes are sufficient to
     16/* This grammar is based on the ANSI99/11 C grammar, specifically parts of EXPRESSION and STATEMENTS, and on
     17   the C grammar by James A. Roskind, specifically parts of DECLARATIONS and EXTERNAL DEFINITIONS.  While
     18   parts have been copied, important changes have been made in all sections; these changes are sufficient to
    1919   constitute a new grammar.  In particular, this grammar attempts to be more syntactically precise, i.e., it
    2020   parses less incorrect language syntax that must be subsequently rejected by semantic checks.  Nevertheless,
    21    there are still several semantic checks required and many are noted in the grammar. Finally, the grammar
    22    is extended with GCC and CFA language extensions. */
     21   there are still several semantic checks required and many are noted in the grammar. Finally, the grammar is
     22   extended with GCC and CFA language extensions. */
    2323
    2424/* Acknowledgments to Richard Bilson, Glen Ditchfield, and Rodolfo Gabriel Esteves who all helped when I got
    2525   stuck with the grammar. */
    2626
    27 /* The root language for this grammar is ANSI99 C. All of ANSI99 is parsed, except for:
     27/* The root language for this grammar is ANSI99/11 C. All of ANSI99/11 is parsed, except for:
    2828
    2929   1. designation with '=' (use ':' instead)
    3030
    31    Most of the syntactic extensions from ANSI90 to ANSI99 C are marked with the comment "ANSI99". This grammar
     31   Most of the syntactic extensions from ANSI90 to ANSI11 C are marked with the comment "C99/C11". This grammar
    3232   also has two levels of extensions. The first extensions cover most of the GCC C extensions, except for:
    3333
     
    4040   Cforall (CFA), which fixes several of C's outstanding problems and extends C with many modern language
    4141   concepts. All of the syntactic extensions for CFA C are marked with the comment "CFA". As noted above,
    42    there is one unreconcileable parsing problem between ANSI99 and CFA with respect to designators; this is
     42   there is one unreconcileable parsing problem between C99 and CFA with respect to designators; this is
    4343   discussed in detail before the "designation" grammar rule. */
    4444
     
    6767%token TYPEDEF
    6868%token AUTO EXTERN REGISTER STATIC
    69 %token INLINE                                           /* ANSI99 */
    70 %token FORTRAN                                          /* ANSI99, extension ISO/IEC 9899:1999 Section J.5.9(1) */
     69%token INLINE                                           /* C99 */
     70%token FORTRAN                                          /* C99, extension ISO/IEC 9899:1999 Section J.5.9(1) */
    7171%token CONST VOLATILE
    72 %token RESTRICT                                         /* ANSI99 */
     72%token RESTRICT                                         /* C99 */
    7373%token FORALL LVALUE                                    /* CFA */
    7474%token VOID CHAR SHORT INT LONG FLOAT DOUBLE SIGNED UNSIGNED
    75 %token BOOL COMPLEX IMAGINARY                           /* ANSI99 */
     75%token BOOL COMPLEX IMAGINARY                           /* C99 */
    7676%token TYPEOF LABEL                                     /* GCC */
    7777%token ENUM STRUCT UNION
    7878%token TYPE FTYPE DTYPE CONTEXT                         /* CFA */
    7979%token SIZEOF
    80 %token ALIGNOF ATTRIBUTE EXTENSION                      /* GCC */
     80%token ATTRIBUTE EXTENSION                              /* GCC */
    8181%token IF ELSE SWITCH CASE DEFAULT DO WHILE FOR BREAK CONTINUE GOTO RETURN
    8282%token CHOOSE FALLTHRU TRY CATCH FINALLY THROW          /* CFA */
    83 %token ASM                                              /* ANSI99, extension ISO/IEC 9899:1999 Section J.5.10(1) */
     83%token ASM                                              /* C99, extension ISO/IEC 9899:1999 Section J.5.10(1) */
     84%token ALIGNAS ALIGNOF ATOMIC GENERIC NORETURN STATICASSERT THREADLOCAL /* C11 */
    8485
    8586/* names and constants: lexer differentiates between identifier and typedef names */
     
    362363                { $$ = new CompositeExprNode(new OperatorNode(OperatorNode::DecrPost), $1); }
    363364                /* GCC has priority: cast_expression */
    364         | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' /* ANSI99 */
     365        | '(' type_name_no_function ')' '{' initializer_list comma_opt '}' /* C99 */
    365366                { $$ = 0; }
    366367        ;
     
    642643          push push
    643644          label_declaration_opt                         /* GCC, local labels */
    644           block_item_list pop '}'                       /* ANSI99, intermix declarations and statements */
     645          block_item_list pop '}'                       /* C99, intermix declarations and statements */
    645646                { $$ = new CompoundStmtNode( $5 ); }
    646647        ;
    647648
    648 block_item_list:                                        /* ANSI99 */
     649block_item_list:                                        /* C99 */
    649650        block_item
    650651        | block_item_list push block_item
     
    773774        comma_expression_opt pop ';' comma_expression_opt ';' comma_expression_opt
    774775                                                { $$ = new ForCtlExprNode($1, $4, $6); }
    775         | declaration comma_expression_opt ';' comma_expression_opt /* ANSI99 */
     776        | declaration comma_expression_opt ';' comma_expression_opt /* C99 */
    776777                /* Like C++, the loop index can be declared local to the loop. */
    777778                                                { $$ = new ForCtlExprNode($1, $2, $4); }
     
    12441245        | STATIC
    12451246                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Static ); }
    1246         | INLINE                                        /* ANSI99 */
     1247        | INLINE                                        /* C99 */
    12471248                /* INLINE is essentially a storage class specifier for functions, and hence, belongs here. */
    12481249                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Inline ); }
    1249         | FORTRAN                                       /* ANSI99 */
     1250        | FORTRAN                                       /* C99 */
    12501251                { $$ = DeclarationNode::newStorageClass( DeclarationNode::Fortran ); }
    12511252        ;
     
    12701271        | VOID
    12711272                { $$ = DeclarationNode::newBasicType( DeclarationNode::Void ); }
    1272         | BOOL                                          /* ANSI99 */
     1273        | BOOL                                          /* C99 */
    12731274                { $$ = DeclarationNode::newBasicType( DeclarationNode::Bool ); }
    1274         | COMPLEX                                       /* ANSI99 */
     1275        | COMPLEX                                       /* C99 */
    12751276                { $$ = DeclarationNode::newBasicType( DeclarationNode::Complex ); }
    1276         | IMAGINARY                                     /* ANSI99 */
     1277        | IMAGINARY                                     /* C99 */
    12771278                { $$ = DeclarationNode::newBasicType( DeclarationNode::Imaginary ); }
    12781279        ;
     
    16421643        ;
    16431644
    1644 /* There is an unreconcileable parsing problem between ANSI99 and CFA with respect to designators. The problem
     1645/* There is an unreconcileable parsing problem between C99 and CFA with respect to designators. The problem
    16451646   is use of '=' to separator the designator from the initializer value, as in:
    16461647
     
    16531654
    16541655designation:
    1655         designator_list ':'                             /* ANSI99, CFA uses ":" instead of "=" */
     1656        designator_list ':'                             /* C99, CFA uses ":" instead of "=" */
    16561657        | no_attr_identifier_or_typedef_name ':'        /* GCC, field name */
    16571658                                                        { $$ = new VarRefNode( $1 ); }
    16581659        ;
    16591660
    1660 designator_list:                                        /* ANSI99 */
     1661designator_list:                                        /* C99 */
    16611662        designator
    16621663        | designator_list designator                    { $$ = (ExpressionNode *)($1->set_link( $2 )); }
     
    16641665
    16651666designator:
    1666         '.' no_attr_identifier_or_typedef_name          /* ANSI99, field name */
     1667        '.' no_attr_identifier_or_typedef_name          /* C99, field name */
    16671668                                                        { $$ = new VarRefNode( $2 ); }
    1668         | '[' push assignment_expression pop ']'        /* ANSI99, single array element */
     1669        | '[' push assignment_expression pop ']'        /* C99, single array element */
    16691670                /* assignment_expression used instead of constant_expression because of shift/reduce conflicts
    16701671                   with tuple. */
     
    22572258
    22582259/* This pattern parses a declaration for a parameter variable or function prototype that is not redefining a
    2259    typedef name and allows the ANSI99 array options, which can only appear in a parameter list.  The pattern
     2260   typedef name and allows the C99 array options, which can only appear in a parameter list.  The pattern
    22602261   precludes declaring an array of functions versus a pointer to an array of functions, and returning arrays
    22612262   and functions versus pointers to arrays and functions. */
     
    23032304        int f( int foo ); // redefine typedef name in new scope
    23042305
    2305    and allows the ANSI99 array options, which can only appear in a parameter list.  In addition, the pattern
     2306   and allows the C99 array options, which can only appear in a parameter list.  In addition, the pattern
    23062307   handles the special meaning of parenthesis around a typedef name:
    23072308
     
    24202421        '[' push assignment_expression pop ']'
    24212422                { $$ = DeclarationNode::newArray( $3, 0, false ); }
    2422         | '[' push '*' pop ']'                          /* ANSI99 */
     2423        | '[' push '*' pop ']'                          /* C99 */
    24232424                { $$ = DeclarationNode::newVarArray( 0 ); }
    24242425        | multi_array_dimension '[' push assignment_expression pop ']'
    24252426                { $$ = $1->addArray( DeclarationNode::newArray( $4, 0, false ) ); }
    2426         | multi_array_dimension '[' push '*' pop ']'    /* ANSI99 */
     2427        | multi_array_dimension '[' push '*' pop ']'    /* C99 */
    24272428                { $$ = $1->addArray( DeclarationNode::newVarArray( 0 ) ); }
    24282429        ;
     
    24932494                { $$ = DeclarationNode::newArray( 0, 0, false ); }
    24942495        // multi_array_dimension handles the '[' '*' ']' case
    2495         | '[' push type_qualifier_list '*' pop ']'      /* remaining ANSI99 */
     2496        | '[' push type_qualifier_list '*' pop ']'      /* remaining C99 */
    24962497                { $$ = DeclarationNode::newVarArray( $3 ); }
    24972498        | '[' push type_qualifier_list pop ']'
     
    25512552
    25522553/* This pattern parses a new-style declaration for a parameter variable or function prototype that is either
    2553    an identifier or typedef name and allows the ANSI99 array options, which can only appear in a parameter
     2554   an identifier or typedef name and allows the C99 array options, which can only appear in a parameter
    25542555   list. */
    25552556
     
    26072608
    26082609new_array_parameter_1st_dimension:
    2609         '[' push type_qualifier_list '*' pop ']'        /* remaining ANSI99 */
     2610        '[' push type_qualifier_list '*' pop ']'        /* remaining C99 */
    26102611                { $$ = DeclarationNode::newVarArray( $3 ); }
    26112612        | '[' push type_qualifier_list assignment_expression pop ']'
  • translator/Parser/lex.l

    r0b8cd722 r6c3744e  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Wed Dec  3 13:37:52 2014
    13  * Update Count     : 317
     12 * Last Modified On : Sat Jan 17 09:15:03 2015
     13 * Update Count     : 318
    1414 */
    1515
     
    180180
    181181        /* keywords */
     182_Alignas                { KEYWORD_RETURN(ALIGNAS); }    // C11
     183_Alignof                { KEYWORD_RETURN(ALIGNOF); }    // C11
    182184__alignof               { KEYWORD_RETURN(ALIGNOF); }    // GCC
    183185__alignof__             { KEYWORD_RETURN(ALIGNOF); }    // GCC
     
    185187__asm                   { KEYWORD_RETURN(ASM); }        // GCC
    186188__asm__                 { KEYWORD_RETURN(ASM); }        // GCC
     189_Atomic                 { KEYWORD_RETURN(ATOMIC); }     // C11
    187190__attribute             { KEYWORD_RETURN(ATTRIBUTE); }  // GCC
    188191__attribute__           { KEYWORD_RETURN(ATTRIBUTE); }  // GCC
     
    217220fortran                 { KEYWORD_RETURN(FORTRAN); }
    218221ftype                   { KEYWORD_RETURN(FTYPE); }      // CFA
     222_Generic                { KEYWORD_RETURN(GENERIC); }    // C11
    219223goto                    { KEYWORD_RETURN(GOTO); }
    220224if                      { KEYWORD_RETURN(IF); }
     
    229233long                    { KEYWORD_RETURN(LONG); }
    230234lvalue                  { KEYWORD_RETURN(LVALUE); }     // CFA
     235_Noreturn               { KEYWORD_RETURN(NORETURN); }   // C11
    231236register                { KEYWORD_RETURN(REGISTER); }
    232237restrict                { KEYWORD_RETURN(RESTRICT); }   // C99
     
    240245sizeof                  { KEYWORD_RETURN(SIZEOF); }
    241246static                  { KEYWORD_RETURN(STATIC); }
     247_Static_assert          { KEYWORD_RETURN(STATICASSERT); } // C11
    242248struct                  { KEYWORD_RETURN(STRUCT); }
    243249switch                  { KEYWORD_RETURN(SWITCH); }
     250_Thread_local           { KEYWORD_RETURN(THREADLOCAL); } // C11
    244251throw                   { KEYWORD_RETURN(THROW); }      // CFA
    245252try                     { KEYWORD_RETURN(TRY); }        // CFA
Note: See TracChangeset for help on using the changeset viewer.