| ... | @@ -944,7 +944,7 @@ static PrefixOp ast_parse_prefix_op(ParseContext *pc, int *token_index, bool man | ... | @@ -944,7 +944,7 @@ static PrefixOp ast_parse_prefix_op(ParseContext *pc, int *token_index, bool man |
| 944 | } | 944 | } |
| 945 | | 945 | |
| 946 | /* | 946 | /* |
| 947 | PrefixOpExpression : PrefixOp SuffixOpExpression | SuffixOpExpression | 947 | PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression |
| 948 | */ | 948 | */ |
| 949 | static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, bool mandatory) { | 949 | static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 950 | Token *token = &pc->tokens->at(*token_index); | 950 | Token *token = &pc->tokens->at(*token_index); |
| ... | @@ -952,7 +952,7 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, boo | ... | @@ -952,7 +952,7 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, boo |
| 952 | if (prefix_op == PrefixOpInvalid) | 952 | if (prefix_op == PrefixOpInvalid) |
| 953 | return ast_parse_suffix_op_expr(pc, token_index, mandatory); | 953 | return ast_parse_suffix_op_expr(pc, token_index, mandatory); |
| 954 | | 954 | |
| 955 | AstNode *prefix_op_expr = ast_parse_suffix_op_expr(pc, token_index, true); | 955 | AstNode *prefix_op_expr = ast_parse_prefix_op_expr(pc, token_index, true); |
| 956 | AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, token); | 956 | AstNode *node = ast_create_node(pc, NodeTypePrefixOpExpr, token); |
| 957 | node->data.prefix_op_expr.primary_expr = prefix_op_expr; | 957 | node->data.prefix_op_expr.primary_expr = prefix_op_expr; |
| 958 | node->data.prefix_op_expr.prefix_op = prefix_op; | 958 | node->data.prefix_op_expr.prefix_op = prefix_op; |
| ... | @@ -962,24 +962,26 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, boo | ... | @@ -962,24 +962,26 @@ static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, boo |
| 962 | | 962 | |
| 963 | | 963 | |
| 964 | /* | 964 | /* |
| 965 | CastExpression : PrefixOpExpression token(as) Type | PrefixOpExpression | 965 | CastExpression : CastExpression token(as) Type | PrefixOpExpression |
| 966 | */ | 966 | */ |
| 967 | static AstNode *ast_parse_cast_expression(ParseContext *pc, int *token_index, bool mandatory) { | 967 | static AstNode *ast_parse_cast_expression(ParseContext *pc, int *token_index, bool mandatory) { |
| 968 | AstNode *prefix_op_expr = ast_parse_prefix_op_expr(pc, token_index, mandatory); | 968 | AstNode *operand_1 = ast_parse_prefix_op_expr(pc, token_index, mandatory); |
| 969 | if (!prefix_op_expr) | 969 | if (!operand_1) |
| 970 | return nullptr; | 970 | return nullptr; |
| 971 | | 971 | |
| 972 | Token *as_kw = &pc->tokens->at(*token_index); | 972 | while (true) { |
| 973 | if (as_kw->id != TokenIdKeywordAs) | 973 | Token *as_kw = &pc->tokens->at(*token_index); |
| 974 | return prefix_op_expr; | 974 | if (as_kw->id != TokenIdKeywordAs) |
| 975 | *token_index += 1; | 975 | return operand_1; |
| | 976 | *token_index += 1; |
| 976 | | 977 | |
| 977 | AstNode *node = ast_create_node(pc, NodeTypeCastExpr, as_kw); | 978 | AstNode *node = ast_create_node(pc, NodeTypeCastExpr, as_kw); |
| 978 | node->data.cast_expr.expr = prefix_op_expr; | 979 | node->data.cast_expr.expr = operand_1; |
| 979 | | 980 | |
| 980 | node->data.cast_expr.type = ast_parse_type(pc, *token_index, token_index); | 981 | node->data.cast_expr.type = ast_parse_type(pc, *token_index, token_index); |
| 981 | | 982 | |
| 982 | return node; | 983 | operand_1 = node; |
| | 984 | } |
| 983 | } | 985 | } |
| 984 | | 986 | |
| 985 | static BinOpType tok_to_mult_op(Token *token) { | 987 | static BinOpType tok_to_mult_op(Token *token) { |
| ... | @@ -1009,26 +1011,28 @@ static BinOpType ast_parse_mult_op(ParseContext *pc, int *token_index, bool mand | ... | @@ -1009,26 +1011,28 @@ static BinOpType ast_parse_mult_op(ParseContext *pc, int *token_index, bool mand |
| 1009 | } | 1011 | } |
| 1010 | | 1012 | |
| 1011 | /* | 1013 | /* |
| 1012 | MultiplyExpression : CastExpression MultiplyOperator CastExpression | CastExpression | 1014 | MultiplyExpression : CastExpression MultiplyOperator MultiplyExpression | CastExpression |
| 1013 | */ | 1015 | */ |
| 1014 | static AstNode *ast_parse_mult_expr(ParseContext *pc, int *token_index, bool mandatory) { | 1016 | static AstNode *ast_parse_mult_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 1015 | AstNode *operand_1 = ast_parse_cast_expression(pc, token_index, mandatory); | 1017 | AstNode *operand_1 = ast_parse_cast_expression(pc, token_index, mandatory); |
| 1016 | if (!operand_1) | 1018 | if (!operand_1) |
| 1017 | return nullptr; | 1019 | return nullptr; |
| 1018 | | 1020 | |
| 1019 | Token *token = &pc->tokens->at(*token_index); | 1021 | while (true) { |
| 1020 | BinOpType mult_op = ast_parse_mult_op(pc, token_index, false); | 1022 | Token *token = &pc->tokens->at(*token_index); |
| 1021 | if (mult_op == BinOpTypeInvalid) | 1023 | BinOpType mult_op = ast_parse_mult_op(pc, token_index, false); |
| 1022 | return operand_1; | 1024 | if (mult_op == BinOpTypeInvalid) |
| | 1025 | return operand_1; |
| 1023 | | 1026 | |
| 1024 | AstNode *operand_2 = ast_parse_cast_expression(pc, token_index, true); | 1027 | AstNode *operand_2 = ast_parse_cast_expression(pc, token_index, true); |
| 1025 | | 1028 | |
| 1026 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); | 1029 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); |
| 1027 | node->data.bin_op_expr.op1 = operand_1; | 1030 | node->data.bin_op_expr.op1 = operand_1; |
| 1028 | node->data.bin_op_expr.bin_op = mult_op; | 1031 | node->data.bin_op_expr.bin_op = mult_op; |
| 1029 | node->data.bin_op_expr.op2 = operand_2; | 1032 | node->data.bin_op_expr.op2 = operand_2; |
| 1030 | | 1033 | |
| 1031 | return node; | 1034 | operand_1 = node; |
| | 1035 | } |
| 1032 | } | 1036 | } |
| 1033 | | 1037 | |
| 1034 | static BinOpType tok_to_add_op(Token *token) { | 1038 | static BinOpType tok_to_add_op(Token *token) { |
| ... | @@ -1057,26 +1061,28 @@ static BinOpType ast_parse_add_op(ParseContext *pc, int *token_index, bool manda | ... | @@ -1057,26 +1061,28 @@ static BinOpType ast_parse_add_op(ParseContext *pc, int *token_index, bool manda |
| 1057 | } | 1061 | } |
| 1058 | | 1062 | |
| 1059 | /* | 1063 | /* |
| 1060 | AdditionExpression : MultiplyExpression AdditionOperator MultiplyExpression | MultiplyExpression | 1064 | AdditionExpression : MultiplyExpression AdditionOperator AdditionExpression | MultiplyExpression |
| 1061 | */ | 1065 | */ |
| 1062 | static AstNode *ast_parse_add_expr(ParseContext *pc, int *token_index, bool mandatory) { | 1066 | static AstNode *ast_parse_add_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 1063 | AstNode *operand_1 = ast_parse_mult_expr(pc, token_index, mandatory); | 1067 | AstNode *operand_1 = ast_parse_mult_expr(pc, token_index, mandatory); |
| 1064 | if (!operand_1) | 1068 | if (!operand_1) |
| 1065 | return nullptr; | 1069 | return nullptr; |
| 1066 | | 1070 | |
| 1067 | Token *token = &pc->tokens->at(*token_index); | 1071 | while (true) { |
| 1068 | BinOpType add_op = ast_parse_add_op(pc, token_index, false); | 1072 | Token *token = &pc->tokens->at(*token_index); |
| 1069 | if (add_op == BinOpTypeInvalid) | 1073 | BinOpType add_op = ast_parse_add_op(pc, token_index, false); |
| 1070 | return operand_1; | 1074 | if (add_op == BinOpTypeInvalid) |
| | 1075 | return operand_1; |
| 1071 | | 1076 | |
| 1072 | AstNode *operand_2 = ast_parse_mult_expr(pc, token_index, true); | 1077 | AstNode *operand_2 = ast_parse_mult_expr(pc, token_index, true); |
| 1073 | | 1078 | |
| 1074 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); | 1079 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); |
| 1075 | node->data.bin_op_expr.op1 = operand_1; | 1080 | node->data.bin_op_expr.op1 = operand_1; |
| 1076 | node->data.bin_op_expr.bin_op = add_op; | 1081 | node->data.bin_op_expr.bin_op = add_op; |
| 1077 | node->data.bin_op_expr.op2 = operand_2; | 1082 | node->data.bin_op_expr.op2 = operand_2; |
| 1078 | | 1083 | |
| 1079 | return node; | 1084 | operand_1 = node; |
| | 1085 | } |
| 1080 | } | 1086 | } |
| 1081 | | 1087 | |
| 1082 | static BinOpType tok_to_bit_shift_op(Token *token) { | 1088 | static BinOpType tok_to_bit_shift_op(Token *token) { |
| ... | @@ -1088,7 +1094,7 @@ static BinOpType tok_to_bit_shift_op(Token *token) { | ... | @@ -1088,7 +1094,7 @@ static BinOpType tok_to_bit_shift_op(Token *token) { |
| 1088 | } | 1094 | } |
| 1089 | | 1095 | |
| 1090 | /* | 1096 | /* |
| 1091 | BitShiftOperator : token(BitShiftLeft | token(BitShiftRight) | 1097 | BitShiftOperator : token(BitShiftLeft) | token(BitShiftRight) |
| 1092 | */ | 1098 | */ |
| 1093 | static BinOpType ast_parse_bit_shift_op(ParseContext *pc, int *token_index, bool mandatory) { | 1099 | static BinOpType ast_parse_bit_shift_op(ParseContext *pc, int *token_index, bool mandatory) { |
| 1094 | Token *token = &pc->tokens->at(*token_index); | 1100 | Token *token = &pc->tokens->at(*token_index); |
| ... | @@ -1105,96 +1111,104 @@ static BinOpType ast_parse_bit_shift_op(ParseContext *pc, int *token_index, bool | ... | @@ -1105,96 +1111,104 @@ static BinOpType ast_parse_bit_shift_op(ParseContext *pc, int *token_index, bool |
| 1105 | } | 1111 | } |
| 1106 | | 1112 | |
| 1107 | /* | 1113 | /* |
| 1108 | BitShiftExpression : AdditionExpression BitShiftOperator AdditionExpression | AdditionExpression | 1114 | BitShiftExpression : AdditionExpression BitShiftOperator BitShiftExpression | AdditionExpression |
| 1109 | */ | 1115 | */ |
| 1110 | static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, int *token_index, bool mandatory) { | 1116 | static AstNode *ast_parse_bit_shift_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 1111 | AstNode *operand_1 = ast_parse_add_expr(pc, token_index, mandatory); | 1117 | AstNode *operand_1 = ast_parse_add_expr(pc, token_index, mandatory); |
| 1112 | if (!operand_1) | 1118 | if (!operand_1) |
| 1113 | return nullptr; | 1119 | return nullptr; |
| 1114 | | 1120 | |
| 1115 | Token *token = &pc->tokens->at(*token_index); | 1121 | while (true) { |
| 1116 | BinOpType bit_shift_op = ast_parse_bit_shift_op(pc, token_index, false); | 1122 | Token *token = &pc->tokens->at(*token_index); |
| 1117 | if (bit_shift_op == BinOpTypeInvalid) | 1123 | BinOpType bit_shift_op = ast_parse_bit_shift_op(pc, token_index, false); |
| 1118 | return operand_1; | 1124 | if (bit_shift_op == BinOpTypeInvalid) |
| | 1125 | return operand_1; |
| 1119 | | 1126 | |
| 1120 | AstNode *operand_2 = ast_parse_add_expr(pc, token_index, true); | 1127 | AstNode *operand_2 = ast_parse_add_expr(pc, token_index, true); |
| 1121 | | 1128 | |
| 1122 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); | 1129 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); |
| 1123 | node->data.bin_op_expr.op1 = operand_1; | 1130 | node->data.bin_op_expr.op1 = operand_1; |
| 1124 | node->data.bin_op_expr.bin_op = bit_shift_op; | 1131 | node->data.bin_op_expr.bin_op = bit_shift_op; |
| 1125 | node->data.bin_op_expr.op2 = operand_2; | 1132 | node->data.bin_op_expr.op2 = operand_2; |
| 1126 | | 1133 | |
| 1127 | return node; | 1134 | operand_1 = node; |
| | 1135 | } |
| 1128 | } | 1136 | } |
| 1129 | | 1137 | |
| 1130 | | 1138 | |
| 1131 | /* | 1139 | /* |
| 1132 | BinaryAndExpression : BitShiftExpression token(BinAnd) BitShiftExpression | BitShiftExpression | 1140 | BinaryAndExpression : BitShiftExpression token(BinAnd) BinaryAndExpression | BitShiftExpression |
| 1133 | */ | 1141 | */ |
| 1134 | static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool mandatory) { | 1142 | static AstNode *ast_parse_bin_and_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 1135 | AstNode *operand_1 = ast_parse_bit_shift_expr(pc, token_index, mandatory); | 1143 | AstNode *operand_1 = ast_parse_bit_shift_expr(pc, token_index, mandatory); |
| 1136 | if (!operand_1) | 1144 | if (!operand_1) |
| 1137 | return nullptr; | 1145 | return nullptr; |
| 1138 | | 1146 | |
| 1139 | Token *token = &pc->tokens->at(*token_index); | 1147 | while (true) { |
| 1140 | if (token->id != TokenIdBinAnd) | 1148 | Token *token = &pc->tokens->at(*token_index); |
| 1141 | return operand_1; | 1149 | if (token->id != TokenIdBinAnd) |
| 1142 | *token_index += 1; | 1150 | return operand_1; |
| | 1151 | *token_index += 1; |
| 1143 | | 1152 | |
| 1144 | AstNode *operand_2 = ast_parse_bit_shift_expr(pc, token_index, true); | 1153 | AstNode *operand_2 = ast_parse_bit_shift_expr(pc, token_index, true); |
| 1145 | | 1154 | |
| 1146 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); | 1155 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); |
| 1147 | node->data.bin_op_expr.op1 = operand_1; | 1156 | node->data.bin_op_expr.op1 = operand_1; |
| 1148 | node->data.bin_op_expr.bin_op = BinOpTypeBinAnd; | 1157 | node->data.bin_op_expr.bin_op = BinOpTypeBinAnd; |
| 1149 | node->data.bin_op_expr.op2 = operand_2; | 1158 | node->data.bin_op_expr.op2 = operand_2; |
| 1150 | | 1159 | |
| 1151 | return node; | 1160 | operand_1 = node; |
| | 1161 | } |
| 1152 | } | 1162 | } |
| 1153 | | 1163 | |
| 1154 | /* | 1164 | /* |
| 1155 | BinaryXorExpression : BinaryAndExpression token(BinXor) BinaryAndExpression | BinaryAndExpression | 1165 | BinaryXorExpression : BinaryAndExpression token(BinXor) BinaryXorExpression | BinaryAndExpression |
| 1156 | */ | 1166 | */ |
| 1157 | static AstNode *ast_parse_bin_xor_expr(ParseContext *pc, int *token_index, bool mandatory) { | 1167 | static AstNode *ast_parse_bin_xor_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 1158 | AstNode *operand_1 = ast_parse_bin_and_expr(pc, token_index, mandatory); | 1168 | AstNode *operand_1 = ast_parse_bin_and_expr(pc, token_index, mandatory); |
| 1159 | if (!operand_1) | 1169 | if (!operand_1) |
| 1160 | return nullptr; | 1170 | return nullptr; |
| 1161 | | 1171 | |
| 1162 | Token *token = &pc->tokens->at(*token_index); | 1172 | while (true) { |
| 1163 | if (token->id != TokenIdBinXor) | 1173 | Token *token = &pc->tokens->at(*token_index); |
| 1164 | return operand_1; | 1174 | if (token->id != TokenIdBinXor) |
| 1165 | *token_index += 1; | 1175 | return operand_1; |
| | 1176 | *token_index += 1; |
| 1166 | | 1177 | |
| 1167 | AstNode *operand_2 = ast_parse_bin_and_expr(pc, token_index, true); | 1178 | AstNode *operand_2 = ast_parse_bin_and_expr(pc, token_index, true); |
| 1168 | | 1179 | |
| 1169 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); | 1180 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); |
| 1170 | node->data.bin_op_expr.op1 = operand_1; | 1181 | node->data.bin_op_expr.op1 = operand_1; |
| 1171 | node->data.bin_op_expr.bin_op = BinOpTypeBinXor; | 1182 | node->data.bin_op_expr.bin_op = BinOpTypeBinXor; |
| 1172 | node->data.bin_op_expr.op2 = operand_2; | 1183 | node->data.bin_op_expr.op2 = operand_2; |
| 1173 | | 1184 | |
| 1174 | return node; | 1185 | operand_1 = node; |
| | 1186 | } |
| 1175 | } | 1187 | } |
| 1176 | | 1188 | |
| 1177 | /* | 1189 | /* |
| 1178 | BinaryOrExpression : BinaryXorExpression token(BinOr) BinaryXorExpression | BinaryXorExpression | 1190 | BinaryOrExpression : BinaryXorExpression token(BinOr) BinaryOrExpression | BinaryXorExpression |
| 1179 | */ | 1191 | */ |
| 1180 | static AstNode *ast_parse_bin_or_expr(ParseContext *pc, int *token_index, bool mandatory) { | 1192 | static AstNode *ast_parse_bin_or_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 1181 | AstNode *operand_1 = ast_parse_bin_xor_expr(pc, token_index, mandatory); | 1193 | AstNode *operand_1 = ast_parse_bin_xor_expr(pc, token_index, mandatory); |
| 1182 | if (!operand_1) | 1194 | if (!operand_1) |
| 1183 | return nullptr; | 1195 | return nullptr; |
| 1184 | | 1196 | |
| 1185 | Token *token = &pc->tokens->at(*token_index); | 1197 | while (true) { |
| 1186 | if (token->id != TokenIdBinOr) | 1198 | Token *token = &pc->tokens->at(*token_index); |
| 1187 | return operand_1; | 1199 | if (token->id != TokenIdBinOr) |
| 1188 | *token_index += 1; | 1200 | return operand_1; |
| | 1201 | *token_index += 1; |
| 1189 | | 1202 | |
| 1190 | AstNode *operand_2 = ast_parse_bin_xor_expr(pc, token_index, true); | 1203 | AstNode *operand_2 = ast_parse_bin_xor_expr(pc, token_index, true); |
| 1191 | | 1204 | |
| 1192 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); | 1205 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); |
| 1193 | node->data.bin_op_expr.op1 = operand_1; | 1206 | node->data.bin_op_expr.op1 = operand_1; |
| 1194 | node->data.bin_op_expr.bin_op = BinOpTypeBinOr; | 1207 | node->data.bin_op_expr.bin_op = BinOpTypeBinOr; |
| 1195 | node->data.bin_op_expr.op2 = operand_2; | 1208 | node->data.bin_op_expr.op2 = operand_2; |
| 1196 | | 1209 | |
| 1197 | return node; | 1210 | operand_1 = node; |
| | 1211 | } |
| 1198 | } | 1212 | } |
| 1199 | | 1213 | |
| 1200 | static BinOpType tok_to_cmp_op(Token *token) { | 1214 | static BinOpType tok_to_cmp_op(Token *token) { |
| ... | @@ -1247,26 +1261,28 @@ static AstNode *ast_parse_comparison_expr(ParseContext *pc, int *token_index, bo | ... | @@ -1247,26 +1261,28 @@ static AstNode *ast_parse_comparison_expr(ParseContext *pc, int *token_index, bo |
| 1247 | } | 1261 | } |
| 1248 | | 1262 | |
| 1249 | /* | 1263 | /* |
| 1250 | BoolAndExpression : ComparisonExpression token(BoolAnd) ComparisonExpression | ComparisonExpression | 1264 | BoolAndExpression : ComparisonExpression token(BoolAnd) BoolAndExpression | ComparisonExpression |
| 1251 | */ | 1265 | */ |
| 1252 | static AstNode *ast_parse_bool_and_expr(ParseContext *pc, int *token_index, bool mandatory) { | 1266 | static AstNode *ast_parse_bool_and_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 1253 | AstNode *operand_1 = ast_parse_comparison_expr(pc, token_index, mandatory); | 1267 | AstNode *operand_1 = ast_parse_comparison_expr(pc, token_index, mandatory); |
| 1254 | if (!operand_1) | 1268 | if (!operand_1) |
| 1255 | return nullptr; | 1269 | return nullptr; |
| 1256 | | 1270 | |
| 1257 | Token *token = &pc->tokens->at(*token_index); | 1271 | while (true) { |
| 1258 | if (token->id != TokenIdBoolAnd) | 1272 | Token *token = &pc->tokens->at(*token_index); |
| 1259 | return operand_1; | 1273 | if (token->id != TokenIdBoolAnd) |
| 1260 | *token_index += 1; | 1274 | return operand_1; |
| | 1275 | *token_index += 1; |
| 1261 | | 1276 | |
| 1262 | AstNode *operand_2 = ast_parse_comparison_expr(pc, token_index, true); | 1277 | AstNode *operand_2 = ast_parse_comparison_expr(pc, token_index, true); |
| 1263 | | 1278 | |
| 1264 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); | 1279 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); |
| 1265 | node->data.bin_op_expr.op1 = operand_1; | 1280 | node->data.bin_op_expr.op1 = operand_1; |
| 1266 | node->data.bin_op_expr.bin_op = BinOpTypeBoolAnd; | 1281 | node->data.bin_op_expr.bin_op = BinOpTypeBoolAnd; |
| 1267 | node->data.bin_op_expr.op2 = operand_2; | 1282 | node->data.bin_op_expr.op2 = operand_2; |
| 1268 | | 1283 | |
| 1269 | return node; | 1284 | operand_1 = node; |
| | 1285 | } |
| 1270 | } | 1286 | } |
| 1271 | | 1287 | |
| 1272 | /* | 1288 | /* |
| ... | @@ -1382,26 +1398,28 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token | ... | @@ -1382,26 +1398,28 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token |
| 1382 | } | 1398 | } |
| 1383 | | 1399 | |
| 1384 | /* | 1400 | /* |
| 1385 | BoolOrExpression : BoolAndExpression token(BoolOr) BoolAndExpression | BoolAndExpression | 1401 | BoolOrExpression : BoolAndExpression token(BoolOr) BoolOrExpression | BoolAndExpression |
| 1386 | */ | 1402 | */ |
| 1387 | static AstNode *ast_parse_bool_or_expr(ParseContext *pc, int *token_index, bool mandatory) { | 1403 | static AstNode *ast_parse_bool_or_expr(ParseContext *pc, int *token_index, bool mandatory) { |
| 1388 | AstNode *operand_1 = ast_parse_bool_and_expr(pc, token_index, mandatory); | 1404 | AstNode *operand_1 = ast_parse_bool_and_expr(pc, token_index, mandatory); |
| 1389 | if (!operand_1) | 1405 | if (!operand_1) |
| 1390 | return nullptr; | 1406 | return nullptr; |
| 1391 | | 1407 | |
| 1392 | Token *token = &pc->tokens->at(*token_index); | 1408 | while (true) { |
| 1393 | if (token->id != TokenIdBoolOr) | 1409 | Token *token = &pc->tokens->at(*token_index); |
| 1394 | return operand_1; | 1410 | if (token->id != TokenIdBoolOr) |
| 1395 | *token_index += 1; | 1411 | return operand_1; |
| | 1412 | *token_index += 1; |
| 1396 | | 1413 | |
| 1397 | AstNode *operand_2 = ast_parse_bool_and_expr(pc, token_index, true); | 1414 | AstNode *operand_2 = ast_parse_bool_and_expr(pc, token_index, true); |
| 1398 | | 1415 | |
| 1399 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); | 1416 | AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token); |
| 1400 | node->data.bin_op_expr.op1 = operand_1; | 1417 | node->data.bin_op_expr.op1 = operand_1; |
| 1401 | node->data.bin_op_expr.bin_op = BinOpTypeBoolOr; | 1418 | node->data.bin_op_expr.bin_op = BinOpTypeBoolOr; |
| 1402 | node->data.bin_op_expr.op2 = operand_2; | 1419 | node->data.bin_op_expr.op2 = operand_2; |
| 1403 | | 1420 | |
| 1404 | return node; | 1421 | operand_1 = node; |
| | 1422 | } |
| 1405 | } | 1423 | } |
| 1406 | | 1424 | |
| 1407 | /* | 1425 | /* |