B-OCL: An Object Constraint Language Interpreter in Python
Fitash Ul Haq, Jordi Cabot
TL;DR
The paper presents B-OCL, a Python-based Object Constraint Language interpreter designed to augment Python modeling work by providing an end-to-end parser and evaluator for OCL constraints within the BESSER/B-UML ecosystem. Built on an ANTLR-generated grammar, the parser creates a syntax tree from OCL constraints while the evaluator applies these constraints to an optional object model, yielding true/false results. The approach emphasizes openness and extensibility, with substantial portions of the OCL metamodel supported and a clear path for adding more constructs, formal verification via Z3, SHACL translation, and code generation. This work enables tighter integration of precise constraint specifications in Python-centric model-driven development and AI-assisted engineering workflows.
Abstract
The Object Constraint Language (OCL) has been widely used in the modeling community to complement software models for precisely defining constraints and business rules for the modeled systems. There is a limited number of tools supporting the definition and interpretation of OCL constraints, even less for a Python-based modelling approaches. In this paper, we introduce an OCL interpreter for Python. The interpreter has two components: parser and evaluator. We implement the OCL metamodel as a set of Python classes and design the grammar for the parser using the state-of-the-art ANTLR parser generator. The parser generates the syntax tree, that conforms with the OCL metamodel, after parsing each part of the OCL constraint. The evaluator then interprets the constraints using this syntax tree and the object diagram. In the end, the interpreter reports the result for all the constraints.
