@@ -352,31 +352,42 @@ def process_equation(self, ctx: UVLPythonParser.EquationContext) -> Node:
352352 self .process_expression (ctx .expression (1 )))
353353
354354 def process_expression (self , ctx : Any ) -> Node :
355- """Handle Additive, Multiplicative y Primary Expressions"""
356- # Binary expressions (arithmetics)
357- # 1. Handle Arithmetic Binary Expressions
358- arithmetic_ops = {
359- UVLPythonParser .AddExpressionContext : ASTOperation .ADD ,
360- UVLPythonParser .SubExpressionContext : ASTOperation .SUB ,
361- UVLPythonParser .MulExpressionContext : ASTOperation .MUL ,
362- UVLPythonParser .DivExpressionContext : ASTOperation .DIV ,
363- }
364-
365- ctx_type = type (ctx )
366- if ctx_type in arithmetic_ops :
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 )
376-
377- # 3. Delegate leaves to a specialized helper to reduce complexity
355+ """Handle Additive, Multiplicative and Primary Expressions"""
356+ # Top-level expression rule (expression: additiveExpression)
357+ if isinstance (ctx , UVLPythonParser .ExpressionContext ):
358+ return self .process_expression (ctx .additiveExpression ())
359+ # Binary arithmetic operations (Add, Sub, Mul, Div)
360+ if isinstance (ctx , (UVLPythonParser .AddExpressionContext ,
361+ UVLPythonParser .SubExpressionContext ,
362+ UVLPythonParser .MulExpressionContext ,
363+ UVLPythonParser .DivExpressionContext )):
364+ return self ._process_binary_expression (ctx )
365+ # Pass-through: additiveExpression -> multiplicativeExpression
366+ if isinstance (ctx , UVLPythonParser .MultiplicativeExprContext ):
367+ return self .process_expression (ctx .multiplicativeExpression ())
368+ # Pass-through: multiplicativeExpression -> primaryExpression
369+ if isinstance (ctx , UVLPythonParser .PrimaryExpressionExpressionContext ):
370+ return self .process_expression (ctx .primaryExpression ())
378371 return self ._process_expression_leaves (ctx )
379372
373+ def _process_binary_expression (self , ctx : Any ) -> Node :
374+ """Handle binary arithmetic operations: Add, Sub, Mul, Div."""
375+ if isinstance (ctx , UVLPythonParser .AddExpressionContext ):
376+ return Node (ASTOperation .ADD ,
377+ self .process_expression (ctx .additiveExpression ()),
378+ self .process_expression (ctx .multiplicativeExpression ()))
379+ if isinstance (ctx , UVLPythonParser .SubExpressionContext ):
380+ return Node (ASTOperation .SUB ,
381+ self .process_expression (ctx .additiveExpression ()),
382+ self .process_expression (ctx .multiplicativeExpression ()))
383+ if isinstance (ctx , UVLPythonParser .MulExpressionContext ):
384+ return Node (ASTOperation .MUL ,
385+ self .process_expression (ctx .multiplicativeExpression ()),
386+ self .process_expression (ctx .primaryExpression ()))
387+ return Node (ASTOperation .DIV ,
388+ self .process_expression (ctx .multiplicativeExpression ()),
389+ self .process_expression (ctx .primaryExpression ()))
390+
380391 def _process_expression_leaves (self , ctx : Any ) -> Node :
381392 """Helper to process literal leaves and primary expressions."""
382393 if isinstance (ctx , UVLPythonParser .FloatLiteralExpressionContext ):
0 commit comments