@@ -356,30 +356,23 @@ def process_expression(self, ctx: Any) -> Node:
356356 # Binary expressions (arithmetics)
357357 # 1. Handle Arithmetic Binary Expressions
358358 arithmetic_ops = {
359- UVLPythonParser .AddExpressionContext : (ASTOperation .ADD ,
360- 'additiveExpression' ,
361- 'multiplicativeExpression' ),
362- UVLPythonParser .SubExpressionContext : (ASTOperation .SUB ,
363- 'additiveExpression' ,
364- 'multiplicativeExpression' ),
365- UVLPythonParser .MulExpressionContext : (ASTOperation .MUL ,
366- 'multiplicativeExpression' ,
367- 'primaryExpression' ),
368- UVLPythonParser .DivExpressionContext : (ASTOperation .DIV ,
369- 'multiplicativeExpression' ,
370- 'primaryExpression' ),
359+ UVLPythonParser .AddExpressionContext : ASTOperation .ADD ,
360+ UVLPythonParser .SubExpressionContext : ASTOperation .SUB ,
361+ UVLPythonParser .MulExpressionContext : ASTOperation .MUL ,
362+ UVLPythonParser .DivExpressionContext : ASTOperation .DIV ,
371363 }
372364
373365 ctx_type = type (ctx )
374366 if ctx_type in arithmetic_ops :
375- op , left_attr , right_attr = arithmetic_ops [ctx_type ]
376- return Node (op , self .process_expression (getattr (ctx , left_attr )()),
377- self .process_expression (getattr (ctx , right_attr )()))
378-
379- # 2. Handle grammar fall-through (recursive descent)
380- for attr in ['additiveExpression' , 'multiplicativeExpression' , 'primaryExpression' ]:
381- if hasattr (ctx , attr ):
382- return self .process_expression (getattr (ctx , attr )())
367+ op = arithmetic_ops [ctx_type ]
368+ return Node (op , self .process_expression (ctx .expression (0 )),
369+ self .process_expression (ctx .expression (1 )))
370+
371+ # 2. Handle single-child expression (grammar fall-through)
372+ if hasattr (ctx , 'expression' ) and callable (ctx .expression ):
373+ child = ctx .expression ()
374+ if child is not None :
375+ return self .process_expression (child )
383376
384377 # 3. Delegate leaves to a specialized helper to reduce complexity
385378 return self ._process_expression_leaves (ctx )
0 commit comments