Changeset 1a8b17a


Ignore:
Timestamp:
Oct 13, 2024, 12:22:26 PM (12 days ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
1a7203d
Parents:
0766399
Message:

add C23 attributes, require comma terminator for nullary and unary tuple (optional terminator for Nary tuples), change designator to C syntax using equal rather than colon

Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/lex.ll

    r0766399 r1a8b17a  
    1010 * Created On       : Sat Sep 22 08:58:10 2001
    1111 * Last Modified By : Peter A. Buhr
    12  * Last Modified On : Mon Sep 23 22:45:33 2024
    13  * Update Count     : 792
     12 * Last Modified On : Sun Oct 13 10:03:28 2024
     13 * Update Count     : 869
    1414 */
    1515
     
    147147                                // character escape sequence, GCC: \e => esc character
    148148simple_escape "\\"[abefnrtv'"?\\]
    149                                 // ' stop editor highlighting
     149                                // " stop editor highlighting
    150150octal_escape "\\"{octal}("_"?{octal}){0,2}
    151151hex_escape "\\""x""_"?{hex_digits}
     
    155155
    156156                                // display/white-space characters
    157 h_tab [\011]
    158 form_feed [\014]
    159 v_tab [\013]
    160 c_return [\015]
    161 h_white [ ]|{h_tab}
     157h_tab "\t"
     158form_feed "\f"
     159v_tab "\v"
     160new_line "\n"
     161c_return "\r"
     162h_white " "|{h_tab}
     163v_white {v_tab}|{c_return}|{form_feed}
     164hv_white {h_white}|{v_tab}|{new_line}|{c_return}|{form_feed}
    162165
    163166                                // overloadable operators
     
    171174                                // op_binary_not_over "?"|"->"|"."|"&&"|"||"|"@="
    172175                                // operator {op_unary_pre_post}|{op_binary_over}|{op_binary_not_over}
     176
     177                                // C23 attributes
     178attr_string "\""[^\"]*"\""
     179attr_arg_opt ({hv_white}*"("{hv_white}*{attr_string}{hv_white}*")")?
     180attributes "deprecated"{attr_arg_opt}|"fallthrough"|"nodiscard"{attr_arg_opt}|"maybe_unused"|"noreturn"|"_Noreturn"|"unsequenced"|"unused"|"reproducible"|{identifier}{hv_white}*"::"{hv_white}*{identifier}
    173181
    174182%x COMMENT
     
    212220
    213221                                /* ignore whitespace */
    214 {h_white}+              { WHITE_RETURN(' '); }
    215 ({v_tab}|{c_return}|{form_feed})+ { WHITE_RETURN(' '); }
    216 ({h_white}|{v_tab}|{c_return}|{form_feed})*"\n" { NEWLINE_RETURN(); }
     222({h_white}|{v_white})+ { WHITE_RETURN(' '); }                   // do nothing
     223"\n"                    { NEWLINE_RETURN(); }                                   // reset column counter
    217224
    218225                                /* keywords */
     
    373380}
    374381
     382                                /* C23 attributes */
     383"[["{hv_white}*{attributes}({hv_white}*","{hv_white}*{attributes})*{hv_white}*"]]" {
     384        strtext = new string( &yytext[2], yyleng - 4 );         // remove [[]]
     385        RETURN_STR(C23_ATTRIBUTE);
     386}
     387
    375388                                /* numeric constants */
    376389{binary_constant} { NUMERIC_RETURN(INTEGERconstant); }
    377390{octal_constant} { NUMERIC_RETURN(INTEGERconstant); }
    378391{decimal_constant} { NUMERIC_RETURN(INTEGERconstant); }
    379 {hex_constant}  { NUMERIC_RETURN(INTEGERconstant); }
    380 {floating_decimal}      { NUMERIC_RETURN(FLOATING_DECIMALconstant); } // must appear before floating_constant
     392{hex_constant} { NUMERIC_RETURN(INTEGERconstant); }
     393{floating_decimal} { NUMERIC_RETURN(FLOATING_DECIMALconstant); } // must appear before floating_constant
    381394{floating_fraction}     { NUMERIC_RETURN(FLOATING_FRACTIONconstant); } // must appear before floating_constant
    382395{floating_constant}     { NUMERIC_RETURN(FLOATINGconstant); }
  • src/Parser/parser.yy

    r0766399 r1a8b17a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Sep 30 09:40:28 2024
    13 // Update Count     : 6776
     12// Last Modified On : Sun Oct 13 12:18:15 2024
     13// Update Count     : 6845
    1414//
    1515
     
    392392%token<tok> TIMEOUT                     WAND    WOR             CATCH                   RECOVER                 CATCHRESUME             FIXUP           FINALLY         // CFA
    393393%token<tok> INTEGERconstant     CHARACTERconstant       STRINGliteral
    394 %token<tok> DIRECTIVE
     394%token<tok> DIRECTIVE           C23_ATTRIBUTE
    395395// Floating point constant is broken into three kinds of tokens because of the ambiguity with tuple indexing and
    396396// overloading constants 0/1, e.g., x.1 is lexed as (x)(.1), where (.1) is a factional constant, but is semantically
     
    11691169                // CFA, one assignment_expression is factored out of comma_expression to eliminate a shift/reduce conflict with
    11701170                // comma_expression in cfa_identifier_parameter_array and cfa_abstract_array
    1171 //      '[' ']'
    1172 //              { $$ = new ExpressionNode( build_tuple() ); }
    1173 //      '[' assignment_expression ']'
    1174 //              { $$ = new ExpressionNode( build_tuple( $2 ) ); }
    1175         '[' ',' tuple_expression_list ']'
    1176                 { $$ = new ExpressionNode( build_tuple( yylloc, (new ExpressionNode( nullptr ))->set_last( $3 ) ) ); }
    1177         | '[' assignment_expression ',' tuple_expression_list ']'
     1171        '[' ',' ']'
     1172                { $$ = new ExpressionNode( build_tuple( yylloc, nullptr ) ); }
     1173        | '[' assignment_expression ',' ']'
     1174                { $$ = new ExpressionNode( build_tuple( yylloc, $2 ) ); }
     1175        | '[' '@' comma_opt ']'
     1176                { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; }
     1177        | '[' assignment_expression ',' tuple_expression_list comma_opt ']'
    11781178                { $$ = new ExpressionNode( build_tuple( yylloc, $2->set_last( $4 ) ) ); }
     1179        | '[' '@' ',' tuple_expression_list comma_opt ']'
     1180                { SemanticError( yylloc, "Eliding tuple element with '@' is currently unimplemented." ); $$ = nullptr; }
    11791181        ;
    11801182
     
    30503052
    30513053designation:
    3052         designator_list ':'                                                                     // C99, CFA uses ":" instead of "="
    3053         | identifier_at ':'                                                                     // GCC, field name
     3054        designator_list '='                                                                     // C99, CFA uses ":" instead of "="
     3055        | identifier_at ':'                                                                     // GCC, field name, obsolete since GCC 2.5
    30543056                { $$ = new ExpressionNode( build_varref( yylloc, $1 ) ); }
    30553057        ;
     
    30593061        | designator_list designator
    30603062                { $$ = $1->set_last( $2 ); }
    3061         //| designator_list designator                                          { $$ = new ExpressionNode( $1, $2 ); }
    30623063        ;
    30633064
     
    30653066        '.' identifier_at                                                                       // C99, field name
    30663067                { $$ = new ExpressionNode( build_varref( yylloc, $2 ) ); }
    3067         | '[' assignment_expression ']'                                         // C99, single array element
    3068                 // assignment_expression used instead of constant_expression because of shift/reduce conflicts with tuple.
     3068        | '[' constant_expression ']'                                           // C99, single array element
    30693069                { $$ = $2; }
    30703070        | '[' subrange ']'                                                                      // CFA, multiple array elements
     
    35133513        | ATTR '(' attribute_name_list ')'                                      // CFA
    35143514                { $$ = $3; }
     3515        | C23_ATTRIBUTE
     3516                { $$ = DeclarationNode::newAttribute( $1 ); }
    35153517        ;
    35163518
Note: See TracChangeset for help on using the changeset viewer.