shift_expr[expr_ty]:
| a=shift_expr '<<' b=sum { _PyAST_BinOp(a, LShift, b, EXTRA) }
| a=shift_expr '>>' b=sum { _PyAST_BinOp(a, RShift, b, EXTRA) }
- | invalid_arithmetic
| sum
# Arithmetic operators
sum[expr_ty]:
| a=sum '+' b=term { _PyAST_BinOp(a, Add, b, EXTRA) }
| a=sum '-' b=term { _PyAST_BinOp(a, Sub, b, EXTRA) }
+ | invalid_arithmetic
| term
term[expr_ty]:
| a=term '//' b=factor { _PyAST_BinOp(a, FloorDiv, b, EXTRA) }
| a=term '%' b=factor { _PyAST_BinOp(a, Mod, b, EXTRA) }
| a=term '@' b=factor { CHECK_VERSION(expr_ty, 5, "The '@' operator is", _PyAST_BinOp(a, MatMult, b, EXTRA)) }
- | invalid_factor
| factor
factor[expr_ty] (memo):
| '-' a=factor { _PyAST_UnaryOp(USub, a, EXTRA) }
| '~' a=factor { _PyAST_UnaryOp(Invert, a, EXTRA) }
| power
+ | invalid_factor
power[expr_ty]:
| a=await_primary '**' b=factor { _PyAST_BinOp(a, Pow, b, EXTRA) }
#define invalid_tstring_replacement_field_type 1271
#define invalid_tstring_conversion_character_type 1272
#define invalid_string_tstring_concat_type 1273
-#define invalid_arithmetic_type 1274
+#define invalid_arithmetic_type 1274 // Left-recursive
#define invalid_factor_type 1275
#define invalid_type_params_type 1276
#define invalid_bitwise_and_type 1277 // Left-recursive
}
// Left-recursive
-// shift_expr: shift_expr '<<' sum | shift_expr '>>' sum | invalid_arithmetic | sum
+// shift_expr: shift_expr '<<' sum | shift_expr '>>' sum | sum
static expr_ty shift_expr_raw(Parser *);
static expr_ty
shift_expr_rule(Parser *p)
D(fprintf(stderr, "%*c%s shift_expr[%d-%d]: %s failed!\n", p->level, ' ',
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "shift_expr '>>' sum"));
}
- if (p->call_invalid_rules) { // invalid_arithmetic
- if (p->error_indicator) {
- p->level--;
- return NULL;
- }
- D(fprintf(stderr, "%*c> shift_expr[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_arithmetic"));
- void *invalid_arithmetic_var;
- if (
- (invalid_arithmetic_var = invalid_arithmetic_rule(p)) // invalid_arithmetic
- )
- {
- D(fprintf(stderr, "%*c+ shift_expr[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_arithmetic"));
- _res = invalid_arithmetic_var;
- goto done;
- }
- p->mark = _mark;
- D(fprintf(stderr, "%*c%s shift_expr[%d-%d]: %s failed!\n", p->level, ' ',
- p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_arithmetic"));
- }
{ // sum
if (p->error_indicator) {
p->level--;
}
// Left-recursive
-// sum: sum '+' term | sum '-' term | term
+// sum: sum '+' term | sum '-' term | invalid_arithmetic | term
static expr_ty sum_raw(Parser *);
static expr_ty
sum_rule(Parser *p)
D(fprintf(stderr, "%*c%s sum[%d-%d]: %s failed!\n", p->level, ' ',
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "sum '-' term"));
}
+ if (p->call_invalid_rules) { // invalid_arithmetic
+ if (p->error_indicator) {
+ p->level--;
+ return NULL;
+ }
+ D(fprintf(stderr, "%*c> sum[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_arithmetic"));
+ void *invalid_arithmetic_var;
+ if (
+ (invalid_arithmetic_var = invalid_arithmetic_rule(p)) // invalid_arithmetic
+ )
+ {
+ D(fprintf(stderr, "%*c+ sum[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_arithmetic"));
+ _res = invalid_arithmetic_var;
+ goto done;
+ }
+ p->mark = _mark;
+ D(fprintf(stderr, "%*c%s sum[%d-%d]: %s failed!\n", p->level, ' ',
+ p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_arithmetic"));
+ }
{ // term
if (p->error_indicator) {
p->level--;
// | term '//' factor
// | term '%' factor
// | term '@' factor
-// | invalid_factor
// | factor
static expr_ty term_raw(Parser *);
static expr_ty
D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ',
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "term '@' factor"));
}
- if (p->call_invalid_rules) { // invalid_factor
- if (p->error_indicator) {
- p->level--;
- return NULL;
- }
- D(fprintf(stderr, "%*c> term[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_factor"));
- void *invalid_factor_var;
- if (
- (invalid_factor_var = invalid_factor_rule(p)) // invalid_factor
- )
- {
- D(fprintf(stderr, "%*c+ term[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_factor"));
- _res = invalid_factor_var;
- goto done;
- }
- p->mark = _mark;
- D(fprintf(stderr, "%*c%s term[%d-%d]: %s failed!\n", p->level, ' ',
- p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_factor"));
- }
{ // factor
if (p->error_indicator) {
p->level--;
return _res;
}
-// factor: '+' factor | '-' factor | '~' factor | power
+// factor: '+' factor | '-' factor | '~' factor | power | invalid_factor
static expr_ty
factor_rule(Parser *p)
{
D(fprintf(stderr, "%*c%s factor[%d-%d]: %s failed!\n", p->level, ' ',
p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "power"));
}
+ if (p->call_invalid_rules) { // invalid_factor
+ if (p->error_indicator) {
+ p->level--;
+ return NULL;
+ }
+ D(fprintf(stderr, "%*c> factor[%d-%d]: %s\n", p->level, ' ', _mark, p->mark, "invalid_factor"));
+ void *invalid_factor_var;
+ if (
+ (invalid_factor_var = invalid_factor_rule(p)) // invalid_factor
+ )
+ {
+ D(fprintf(stderr, "%*c+ factor[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "invalid_factor"));
+ _res = invalid_factor_var;
+ goto done;
+ }
+ p->mark = _mark;
+ D(fprintf(stderr, "%*c%s factor[%d-%d]: %s failed!\n", p->level, ' ',
+ p->error_indicator ? "ERROR!" : "-", _mark, p->mark, "invalid_factor"));
+ }
_res = NULL;
done:
_PyPegen_insert_memo(p, _mark, factor_type, _res);
return _res;
}
+// Left-recursive
// invalid_arithmetic: sum ('+' | '-' | '*' | '/' | '%' | '//' | '@') 'not' inversion
static void *
invalid_arithmetic_rule(Parser *p)