%token IDENT HASH_IDENT CT_IDENT CONST_IDENT
%token TYPE_IDENT CT_TYPE_IDENT
%token AT_TYPE_IDENT AT_IDENT CT_INCLUDE
%token STRING_LITERAL INTEGER
%token INC_OP DEC_OP SHL_OP SHR_OP LE_OP GE_OP EQ_OP NE_OP
%token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
%token SUB_ASSIGN SHL_ASSIGN SHR_ASSIGN AND_ASSIGN
%token XOR_ASSIGN OR_ASSIGN VAR NUL ELVIS NEXTCASE ANYFAULT
%token MODULE IMPORT DEF EXTERN
%token CHAR SHORT INT LONG FLOAT DOUBLE CONST VOID USZ ISZ UPTR IPTR ANY
%token ICHAR USHORT UINT ULONG BOOL INT128 UINT128 FLOAT16 FLOAT128 BFLOAT16
%token TYPEID BITSTRUCT STATIC BANGBANG AT_CONST_IDENT HASH_TYPE_IDENT
%token STRUCT UNION ENUM ELLIPSIS DOTDOT BYTES
%token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR CONTINUE BREAK RETURN FOREACH_R FOREACH
%token FN FAULT MACRO CT_IF CT_ENDIF CT_ELSE CT_SWITCH CT_CASE CT_DEFAULT CT_FOR CT_FOREACH CT_ENDFOREACH
%token CT_ENDFOR CT_ENDSWITCH BUILTIN IMPLIES INITIALIZE FINALIZE CT_ECHO CT_ASSERT CT_EVALTYPE CT_VATYPE
%token TRY CATCH SCOPE DEFER LVEC RVEC OPTELSE CT_TYPEFROM CT_TYPEOF TLOCAL
%token CT_VASPLAT INLINE DISTINCT CT_VACONST CT_NAMEOF CT_VAREF CT_VACOUNT CT_VAARG
%token CT_SIZEOF CT_STRINGIFY CT_QNAMEOF CT_OFFSETOF CT_VAEXPR
%token CT_EXTNAMEOF CT_EVAL CT_DEFINED CT_CHECKS CT_ALIGNOF ASSERT
%token ASM CHAR_LITERAL REAL TRUE FALSE CT_CONST_IDENT
%token LBRAPIPE RBRAPIPE HASH_CONST_IDENT
: primary_expr param_path
| string_expr STRING_LITERAL
: LBRAPIPE opt_stmt_list RBRAPIPE
| ct_call '(' flat_path ')'
| ct_analyse '(' expr ')'
| CT_CHECKS '(' expression_list ')'
| lambda_decl compound_statement
: range_loc DOTDOT range_loc
| range_loc ':' range_loc
| call_inline_attributes AT_IDENT
| '(' call_arg_list ')' call_inline_attributes
| call_invocation compound_statement
| call_stmt_expr call_trailing
| call_expr call_trailing
| mult_expr mult_op unary_expr
| mult_stmt_expr mult_op unary_expr
| shift_expr shift_op mult_expr
| shift_stmt_expr shift_op mult_expr
| bit_expr bit_op shift_expr
| bit_stmt_expr bit_op shift_expr
| additive_expr additive_op bit_expr
| additive_stmt_expr additive_op bit_expr
| relational_expr relational_op additive_expr
| relational_stmt_expr relational_op additive_expr
| lambda_decl IMPLIES relational_expr
| and_expr AND_OP relational_expr
| and_stmt_expr AND_OP relational_expr
| or_stmt_expr OR_OP and_expr
| or_expr '?' expr ':' ternary_expr
| or_expr_with_suffix ELVIS ternary_expr
| or_expr_with_suffix OPTELSE ternary_expr
| lambda_decl implies_body
: or_stmt_expr_with_suffix
| or_stmt_expr '?' expr ':' ternary_expr
| or_stmt_expr_with_suffix ELVIS ternary_expr
| or_stmt_expr_with_suffix OPTELSE ternary_expr
| lambda_decl implies_body
| unary_expr assignment_op assignment_expr
| unary_stmt_expr assignment_op assignment_expr
: FN maybe_optional_type fn_parameter_list opt_attributes
| '[' expr DOTDOT expr ']'
| param_path param_path_element
arg : param_path '=' expr
| CT_VASPLAT '(' range_expr ')'
| arg_list ';' parameters
| enum_constants ',' enum_constant
| CONST_IDENT '(' arg_list ')'
| CONST_IDENT '(' arg_list ',' ')'
| identifier_list ',' IDENT
| CT_TYPEFROM '(' constant_expr ')'
| CT_VATYPE '(' constant_expr ')'
| CT_EVALTYPE '(' constant_expr ')'
| type '[' constant_expr ']'
| type LVEC constant_expr RVEC
| CT_IDENT '=' constant_expr
| IDENT opt_attributes '=' expr
| optional_type local_decl_after_type
| VAR CT_TYPE_IDENT '=' type
: '{' opt_arg_list_trailing '}'
: CT_CASE constant_expr ':' opt_stmt_list
| CT_CASE type ':' opt_stmt_list
| CT_DEFAULT ':' opt_stmt_list
| ct_switch_body ct_case_stmt
: CT_FOR '(' for_cond ')' opt_stmt_list CT_ENDFOR
: CT_FOREACH '(' CT_IDENT ':' expr ')' opt_stmt_list CT_ENDFOREACH
| CT_FOREACH '(' CT_IDENT ',' CT_IDENT ':' expr ')' opt_stmt_list CT_ENDFOREACH
: CT_SWITCH '(' constant_expr ')'
: ct_switch ct_switch_body CT_ENDSWITCH
| decl_stmt_after_type ',' local_decl_after_type
| local_decl_storage optional_type decl_stmt_after_type ';'
| optional_type decl_stmt_after_type ';'
| catch_unwrap_list ',' relational_expr
: CATCH catch_unwrap_list
| CATCH IDENT '=' catch_unwrap_list
| CATCH type IDENT '=' catch_unwrap_list
| TRY IDENT '=' rel_or_lambda_expr
| TRY type IDENT '=' rel_or_lambda_expr
| try_unwrap_chain AND_OP try_unwrap
| try_unwrap_chain AND_OP rel_or_lambda_expr
: DEFAULT ':' opt_stmt_list
: CASE expr ':' opt_stmt_list
| CASE expr DOTDOT expr ':' opt_stmt_list
| CASE type ':' opt_stmt_list
| switch_body default_stmt
| cond_repeat ',' decl_or_expr
| cond_repeat ',' try_unwrap_chain
| cond_repeat ',' catch_unwrap
| ELSE compound_statement
: IF optional_label paren_cond '{' switch_body '}'
| IF optional_label paren_cond '{' switch_body '}' else_part
| IF optional_label paren_cond statement
| IF optional_label paren_cond compound_statement else_part
: expr_list_eos cond_eos expression_list
: FOR optional_label '(' for_cond ')' statement
: WHILE optional_label paren_cond statement
: DO optional_label compound_statement WHILE '(' expr ')' ';'
| DO optional_label compound_statement ';'
: CONTINUE optional_label_target ';'
: BREAK optional_label_target ';'
: NEXTCASE CONST_IDENT ':' expr ';'
| NEXTCASE CONST_IDENT ':' type ';'
: optional_type '&' IDENT
| foreach_var ',' foreach_var
: FOREACH optional_label '(' foreach_vars ':' expr ')' statement
: FOREACH_R optional_label '(' foreach_vars ':' expr ')' statement
: CT_IF constant_expr ':' opt_stmt_list CT_ENDIF
| CT_IF constant_expr ':' opt_stmt_list CT_ELSE opt_stmt_list CT_ENDIF
: ASSERT '(' assert_expr ')' ';'
| ASSERT '(' assert_expr ',' expr ')' ';'
| asm_expr additive_op asm_expr
| asm_expr additive_op asm_expr '*' INTEGER
| asm_expr additive_op asm_expr '*' INTEGER additive_op INTEGER
| asm_expr additive_op asm_expr shift_op INTEGER
| asm_expr additive_op asm_expr additive_op INTEGER
: asm_instr asm_exprs ';'
/* Order here matches compiler */
| statement_list statement
: SWITCH optional_label '{' switch_body '}'
| SWITCH optional_label '{' '}'
| SWITCH optional_label paren_cond '{' switch_body '}'
| SWITCH optional_label paren_cond '{' '}'
| expression_list ',' decl_or_expr
: CT_ASSERT constant_expr ':' constant_expr ';'
| CT_ASSERT constant_expr ';'
| CT_ERROR constant_expr ';'
: CT_INCLUDE string_expr ';'
: CT_ECHO constant_expr ';'
: BITSTRUCT TYPE_IDENT ':' type opt_attributes bitstruct_body
| '{' bitstruct_simple_defs '}'
| bitstruct_defs bitstruct_def
| bitstruct_simple_defs base_type IDENT ';'
: base_type IDENT ':' constant_expr DOTDOT constant_expr ';'
| base_type IDENT ':' constant_expr ';'
: STATIC INITIALIZE opt_attributes compound_statement
| STATIC FINALIZE opt_attributes compound_statement
: attribute_operator_expr
| attribute_param_list ',' attr_param
| attribute_name '(' attribute_param_list ')'
| attribute_list attribute
| AT_IDENT '(' parameters ')'
| parameters ';' trailing_block_param
| ';' trailing_block_param
: MACRO macro_header '(' macro_params ')' opt_attributes macro_func_body
: struct_or_union TYPE_IDENT opt_attributes struct_body
: '{' struct_declaration_list '}'
| struct_declaration_list struct_member_decl
| enum_params ',' enum_param_decl
: type identifier_list opt_attributes ';'
| struct_or_union IDENT opt_attributes struct_body
| struct_or_union opt_attributes struct_body
| BITSTRUCT ':' type opt_attributes bitstruct_body
| BITSTRUCT IDENT ':' type opt_attributes bitstruct_body
| INLINE type IDENT opt_attributes ';'
| INLINE type opt_attributes ';'
: ':' type enum_param_list
: ENUM TYPE_IDENT enum_spec opt_attributes '{' enum_list '}'
: FAULT TYPE_IDENT opt_attributes '{' faults '}'
| FAULT TYPE_IDENT opt_attributes '{' faults ',' '}'
: optional_type type '.' func_macro_name
| optional_type func_macro_name
| type '.' func_macro_name
| parameters ',' parameter
| parameters ',' parameter '=' expr
: type IDENT opt_attributes
| type ELLIPSIS IDENT opt_attributes
| type ELLIPSIS opt_attributes
| type HASH_IDENT opt_attributes
| type '&' IDENT opt_attributes
| '&' IDENT opt_attributes
| HASH_IDENT opt_attributes
| IDENT ELLIPSIS opt_attributes
: FN func_header fn_parameter_list opt_attributes ';'
| FN func_header fn_parameter_list opt_attributes macro_func_body
: CONST CONST_IDENT opt_attributes '=' expr ';'
| CONST type CONST_IDENT opt_attributes '=' expr ';'
: FN optional_type fn_parameter_list
| generic_parameters ',' bit_expr
| generic_parameters ',' type
| type opt_generic_parameters
| multi_declaration ',' IDENT
: global_storage optional_type IDENT opt_attributes ';'
| global_storage optional_type IDENT multi_declaration opt_attributes ';'
| global_storage optional_type IDENT opt_attributes '=' expr ';'
: CT_CASE constant_expr ':' opt_tl_stmts
| CT_CASE type ':' opt_tl_stmts
| CT_DEFAULT ':' opt_tl_stmts
| tl_ct_switch_body tl_ct_case
: AT_TYPE_IDENT '(' parameters ')' opt_attributes '=' '{' opt_attributes '}'
| AT_TYPE_IDENT opt_attributes '=' '{' opt_attributes '}'
: '<' generic_parameters '>'
: IDENT '=' path_ident opt_generic_parameters
| CONST_IDENT '=' path_const opt_generic_parameters
| AT_IDENT '=' path_at_ident opt_generic_parameters
| DEF define_attribute ';'
| DEF TYPE_IDENT opt_attributes '=' opt_distinct_inline typedef_type ';'
: CT_IF constant_expr ':' opt_tl_stmts CT_ENDIF
| CT_IF constant_expr ':' opt_tl_stmts CT_ELSE opt_tl_stmts CT_ENDIF
: ct_switch tl_ct_switch_body CT_ENDSWITCH
| module_params ',' module_param
: MODULE path_ident opt_attributes ';'
| MODULE path_ident '<' module_params '>' opt_attributes ';'
| path_ident ',' path_ident
: IMPORT import_paths opt_attributes ';'
| top_level_statements top_level
| opt_extern func_definition
| opt_extern const_declaration
| opt_extern global_declaration
printf("\n%*s\n%*s\n", column, "^", column, s);
int main(int argc, char *argv[])