Post-order traverse expression trees
(self, expr)
| 169 | cond_expr, then_stmts, else_stmts) |
| 170 | |
| 171 | def _Expr(self, expr): |
| 172 | 'Post-order traverse expression trees' |
| 173 | if isinstance(expr, lark.Token): |
| 174 | if expr.type == 'IDENTIFIER': |
| 175 | return self.builder.BuildIdentifier(str(expr)) |
| 176 | elif expr.type == 'INTEGER': |
| 177 | return self.builder.BuildInteger(str(expr)) |
| 178 | else: |
| 179 | return self.builder.BuildString(str(expr)) |
| 180 | if expr.data == 'par_expr': |
| 181 | return self.builder.BuildParenthesizedOperation( |
| 182 | self._Expr(*expr.children)) |
| 183 | if expr.data not in OPS: |
| 184 | raise UnsupportedOperation( |
| 185 | f'The operator "{expr.data}" is not supported') |
| 186 | if len(expr.children) == 1: |
| 187 | return self._UnaryExpr(expr.data, *expr.children) |
| 188 | if len(expr.children) == 2: |
| 189 | return self._BinaryExpr(expr.data, *expr.children) |
| 190 | raise UnsupportedOperation(f'Unsupported arity {len(expr.children)}') |
| 191 | |
| 192 | def _UnaryExpr(self, op, right): |
| 193 | right = self._Expr(right) |
no test coverage detected