mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 03:51:18 +00:00
Updates to grammar
This commit is contained in:
@@ -887,6 +887,7 @@ statement
|
|||||||
| asm_block_stmt
|
| asm_block_stmt
|
||||||
| ct_echo_stmt
|
| ct_echo_stmt
|
||||||
| ct_assert_stmt
|
| ct_assert_stmt
|
||||||
|
| ct_error_stmt
|
||||||
| ct_if_stmt
|
| ct_if_stmt
|
||||||
| ct_switch_stmt
|
| ct_switch_stmt
|
||||||
| ct_foreach_stmt
|
| ct_foreach_stmt
|
||||||
@@ -927,14 +928,35 @@ optional_label
|
|||||||
| empty
|
| empty
|
||||||
;
|
;
|
||||||
|
|
||||||
|
ct_assert_expr_list
|
||||||
|
: ',' constant_expr
|
||||||
|
| ct_assert_expr_list ',' constant_expr
|
||||||
|
;
|
||||||
|
|
||||||
ct_assert_stmt
|
ct_assert_stmt
|
||||||
: CT_ASSERT constant_expr ':' constant_expr ';'
|
: CT_ASSERT constant_expr ':' constant_expr ';'
|
||||||
|
| CT_ASSERT constant_expr ':' constant_expr ct_assert_expr_list ';'
|
||||||
| CT_ASSERT constant_expr ';'
|
| CT_ASSERT constant_expr ';'
|
||||||
| CT_ERROR constant_expr ';'
|
;
|
||||||
|
|
||||||
|
ct_error_stmt
|
||||||
|
: CT_ERROR constant_expr ';'
|
||||||
|
| CT_ERROR constant_expr ct_assert_expr_list ';'
|
||||||
;
|
;
|
||||||
|
|
||||||
ct_include_stmt
|
ct_include_stmt
|
||||||
: CT_INCLUDE string_expr ';'
|
: CT_INCLUDE constant_expr opt_attributes ';'
|
||||||
|
;
|
||||||
|
|
||||||
|
ct_exec_list
|
||||||
|
: constant_expr
|
||||||
|
| ct_exec_list ',' constant_expr
|
||||||
|
;
|
||||||
|
|
||||||
|
ct_exec_stmt
|
||||||
|
: CT_EXEC '(' string_expr ')' opt_attributes ';'
|
||||||
|
| CT_EXEC '(' string_expr ',' '{' ct_exec_list opt_comma '}' ')' opt_attributes ';'
|
||||||
|
| CT_EXEC '(' string_expr ',' '{' ct_exec_list opt_comma '}' ',' constant_expr ')' opt_attributes ';'
|
||||||
;
|
;
|
||||||
|
|
||||||
ct_echo_stmt
|
ct_echo_stmt
|
||||||
@@ -1077,7 +1099,7 @@ faults
|
|||||||
| faults ',' CONST_IDENT opt_attributes
|
| faults ',' CONST_IDENT opt_attributes
|
||||||
;
|
;
|
||||||
|
|
||||||
fault_declaration
|
faultdef_declaration
|
||||||
: FAULTDEF faults ';'
|
: FAULTDEF faults ';'
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -1215,13 +1237,17 @@ opt_generic_parameters
|
|||||||
|
|
||||||
define_ident
|
define_ident
|
||||||
: IDENT opt_attributes '=' path_ident opt_generic_parameters
|
: IDENT opt_attributes '=' path_ident opt_generic_parameters
|
||||||
|
| IDENT opt_attributes '=' MODULE path_ident opt_generic_parameters
|
||||||
| CONST_IDENT opt_attributes '=' path_const opt_generic_parameters
|
| CONST_IDENT opt_attributes '=' path_const opt_generic_parameters
|
||||||
| AT_IDENT opt_attributes '=' path_at_ident opt_generic_parameters
|
| AT_IDENT opt_attributes '=' path_at_ident opt_generic_parameters
|
||||||
;
|
;
|
||||||
|
|
||||||
define_declaration
|
attrdef_declaration
|
||||||
|
: ATTRDEF define_attribute ';'
|
||||||
|
;
|
||||||
|
|
||||||
|
alias_declaration
|
||||||
: ALIAS define_ident ';'
|
: ALIAS define_ident ';'
|
||||||
| ATTRDEF define_attribute ';'
|
|
||||||
| ALIAS TYPE_IDENT opt_attributes '=' typedef_type opt_attributes ';'
|
| ALIAS TYPE_IDENT opt_attributes '=' typedef_type opt_attributes ';'
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -1245,7 +1271,7 @@ interface_declaration_name
|
|||||||
| TYPE_IDENT ':' interface_parents
|
| TYPE_IDENT ':' interface_parents
|
||||||
;
|
;
|
||||||
|
|
||||||
distinct_declaration
|
typedef_declaration
|
||||||
: TYPEDEF TYPE_IDENT opt_interface_impl opt_attributes '=' opt_inline type ';'
|
: TYPEDEF TYPE_IDENT opt_interface_impl opt_attributes '=' opt_inline type ';'
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -1274,46 +1300,44 @@ import_decl
|
|||||||
;
|
;
|
||||||
|
|
||||||
translation_unit
|
translation_unit
|
||||||
: top_level_statements
|
: module top_level_after_module
|
||||||
|
| top_level_no_module
|
||||||
| empty
|
| empty
|
||||||
;
|
;
|
||||||
|
|
||||||
top_level_statements
|
top_level_decl
|
||||||
: top_level
|
: import_decl
|
||||||
| top_level_statements top_level
|
| func_definition
|
||||||
;
|
| EXTERN func_definition
|
||||||
|
| const_declaration
|
||||||
opt_extern
|
| EXTERN const_declaration
|
||||||
: EXTERN
|
| global_declaration
|
||||||
| empty
|
| EXTERN global_declaration
|
||||||
;
|
|
||||||
|
|
||||||
exec_decl
|
|
||||||
: CT_EXEC '(' expr ')' opt_attributes ';'
|
|
||||||
| CT_EXEC '(' expr ',' initializer_list ')' opt_attributes ';'
|
|
||||||
| CT_EXEC '(' expr ',' initializer_list ',' expr ')' opt_attributes ';'
|
|
||||||
;
|
|
||||||
|
|
||||||
top_level
|
|
||||||
: module
|
|
||||||
| import_decl
|
|
||||||
| exec_decl
|
|
||||||
| opt_extern func_definition
|
|
||||||
| opt_extern const_declaration
|
|
||||||
| opt_extern global_declaration
|
|
||||||
| ct_assert_stmt
|
| ct_assert_stmt
|
||||||
| ct_echo_stmt
|
| ct_echo_stmt
|
||||||
| ct_include_stmt
|
| ct_include_stmt
|
||||||
|
| ct_exec_stmt
|
||||||
| struct_declaration
|
| struct_declaration
|
||||||
| fault_declaration
|
| faultdef_declaration
|
||||||
| enum_declaration
|
| enum_declaration
|
||||||
| macro_declaration
|
| macro_declaration
|
||||||
| define_declaration
|
| alias_declaration
|
||||||
|
| attrdef_declaration
|
||||||
| bitstruct_declaration
|
| bitstruct_declaration
|
||||||
| distinct_declaration
|
| typedef_declaration
|
||||||
| interface_declaration
|
| interface_declaration
|
||||||
;
|
;
|
||||||
|
|
||||||
|
top_level_after_module
|
||||||
|
: top_level_decl
|
||||||
|
| top_level_after_module top_level_decl
|
||||||
|
;
|
||||||
|
|
||||||
|
top_level_no_module
|
||||||
|
: top_level_decl
|
||||||
|
| top_level_after_module top_level_decl
|
||||||
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
void yyerror(YYLTYPE * yylloc_param , yyscan_t yyscanner, const char *yymsgp)
|
void yyerror(YYLTYPE * yylloc_param , yyscan_t yyscanner, const char *yymsgp)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ typedef enum FunctionParse_
|
|||||||
static inline Decl *parse_func_definition(ParseContext *c, AstId contracts, FunctionParse parse_kind);
|
static inline Decl *parse_func_definition(ParseContext *c, AstId contracts, FunctionParse parse_kind);
|
||||||
static inline bool parse_bitstruct_body(ParseContext *c, Decl *decl);
|
static inline bool parse_bitstruct_body(ParseContext *c, Decl *decl);
|
||||||
static inline bool parse_enum_param_list(ParseContext *c, Decl*** parameters_ref, ArrayIndex *inline_index);
|
static inline bool parse_enum_param_list(ParseContext *c, Decl*** parameters_ref, ArrayIndex *inline_index);
|
||||||
static Decl *parse_include(ParseContext *c);
|
static Decl *parse_ct_include(ParseContext *c);
|
||||||
static Decl *parse_exec(ParseContext *c);
|
static Decl *parse_exec(ParseContext *c);
|
||||||
static bool parse_attributes_for_global(ParseContext *c, Decl *decl);
|
static bool parse_attributes_for_global(ParseContext *c, Decl *decl);
|
||||||
INLINE bool parse_decl_initializer(ParseContext *c, Decl *decl);
|
INLINE bool parse_decl_initializer(ParseContext *c, Decl *decl);
|
||||||
@@ -3139,7 +3139,7 @@ static bool parse_contracts(ParseContext *c, AstId *contracts_ref)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Decl *parse_include(ParseContext *c)
|
static Decl *parse_ct_include(ParseContext *c)
|
||||||
{
|
{
|
||||||
SourceSpan loc = c->span;
|
SourceSpan loc = c->span;
|
||||||
Decl *decl = decl_new(DECL_CT_INCLUDE, NULL, loc);
|
Decl *decl = decl_new(DECL_CT_INCLUDE, NULL, loc);
|
||||||
@@ -3323,7 +3323,7 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **context_out)
|
|||||||
return NULL;
|
return NULL;
|
||||||
case TOKEN_CT_INCLUDE:
|
case TOKEN_CT_INCLUDE:
|
||||||
if (contracts) goto CONTRACT_NOT_ALLOWED;
|
if (contracts) goto CONTRACT_NOT_ALLOWED;
|
||||||
decl = parse_include(c);
|
decl = parse_ct_include(c);
|
||||||
break;
|
break;
|
||||||
case TOKEN_CT_EXEC:
|
case TOKEN_CT_EXEC:
|
||||||
if (contracts) goto CONTRACT_NOT_ALLOWED;
|
if (contracts) goto CONTRACT_NOT_ALLOWED;
|
||||||
|
|||||||
Reference in New Issue
Block a user