Skip to main content

Parser for the Universal Variability Language (UVL) with conversion support to CNF/SMT

Project description

uvllang

A Python parser for the Universal Variability Language (UVL) with support for both Lark (default) and ANTLR parsers. In addition, uvllang supports conversion of UVL to CNF / SMT.

Installation

# Install with Lark parser (default, pure Python)
pip install uvllang

# Install with both Lark and ANTLR parsers
pip install uvllang[antlr]

Usage

Basic Usage

from uvllang import UVL

# Parse a UVL file with Lark (default)
model = UVL(from_file="examples/automotive01.uvl")

# Or use ANTLR parser
model = UVL(from_file="examples/automotive01.uvl", use_antlr = True)

# Access features
print(f"Number of features:", len(model.features))

# Access constraints
print("All constraints:", len(model.constraints))
print("Boolean constraints:", len(model.boolean_constraints))
print("Arithmetic constraints:", len(model.arithmetic_constraints))

CNF Conversion

Convert feature models to Conjunctive Normal Form (CNF) for SAT solvers:

from uvllang import UVL

# Parse UVL file
model = UVL(from_file="model.uvl")

# Convert to CNF (returns PySAT CNF object)
cnf = model.to_cnf()
cnf.to_file("output.dimacs")

SMT-LIB 2 Conversion

Convert feature models to SMT-LIB 2 format for SMT solvers (supports arithmetic constraints, types, and aggregates):

from uvllang import UVL

# Parse UVL file with arithmetic constraints
model = UVL(from_file="model.uvl")

# Convert to SMT-LIB 2 format
smt_content = model.to_smt()

# Save to file
with open("output.smt2", "w") as f:
    f.write(smt_content)

# Or use Z3 directly
import z3

solver = z3.Solver()
solver.from_string(smt_content)
result = solver.check()

print(result)  # sat, unsat, or unknown

SMT-LIB 2 Features:

  • Boolean feature selection constraints
  • Arithmetic constraints with integer and real types
  • String features and length constraints
  • Aggregate functions: sum(attr), avg(attr), len(feature)
  • Feature attributes and typed declarations

Command Line Interface

# Basic conversion (uses Lark)
uvl2cnf model.uvl

# Specify output file
uvl2cnf model.uvl output.dimacs

# Verbose mode (lists ignored non-Boolean constraints)
uvl2cnf model.uvl -v

# Use ANTLR parser (requires: pip install uvllang[antlr])
uvl2cnf model.uvl --antlr

SMT-LIB 2 conversion:

# Basic conversion (uses Lark)
uvl2smt model.uvl

# Specify output file
uvl2smt model.uvl output.smt2

# Verbose mode (shows model statistics)
uvl2smt model.uvl -v

# Use ANTLR parser
uvl2smt model.uvl --antlr

# Solve with Z3
uvl2smt model.uvl model.smt2 && z3 model.smt2

Dependencies

Core dependencies (always installed):

  • lark: Lark parser
  • sympy: Symbolic mathematics for Boolean constraint processing
  • python-sat: SAT solver library for CNF handling

Optional dependencies:

  • antlr4-python3-runtime: ANTLR4 parser runtime (install with: pip install uvllang[antlr])
  • z3-solver: Z3 SMT solver for solving SMT-LIB 2 constraints (install with: pip install z3-solver)

Both parsers provide identical functionality. Lark is used by default for easier installation and pure Python compatibility.

Testing

# Install development dependencies
pip install -e .[dev]

# Run tests
python -m pytest tests/

Development

# Generate parsers from grammar files (ANTLR)
python generate_parsers.py

# Build
python -m build

Citation

If you use UVL in your research, please cite:

@article{UVL2024,
  title     = {UVL: Feature modelling with the Universal Variability Language},
  journal   = {Journal of Systems and Software},
  volume    = {225},
  pages     = {112326},
  year      = {2025},
  doi       = {https://doi.org/10.1016/j.jss.2024.112326},
  author    = {David Benavides and Chico Sundermann and Kevin Feichtinger and José A. Galindo and Rick Rabiser and Thomas Thüm}
}

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uvllang-0.2.tar.gz (47.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uvllang-0.2-py3-none-any.whl (44.3 kB view details)

Uploaded Python 3

File details

Details for the file uvllang-0.2.tar.gz.

File metadata

  • Download URL: uvllang-0.2.tar.gz
  • Upload date:
  • Size: 47.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for uvllang-0.2.tar.gz
Algorithm Hash digest
SHA256 f97ba0b72110613d6a41c6fe098ecab4d43446081d7dbc83ffca9fd8650c4492
MD5 aaa4ec8d40f9db91f699518abca3d912
BLAKE2b-256 4b8264676095518a3efdcdda85493605ec1eac58edc1bd6819fee05833585515

See more details on using hashes here.

File details

Details for the file uvllang-0.2-py3-none-any.whl.

File metadata

  • Download URL: uvllang-0.2-py3-none-any.whl
  • Upload date:
  • Size: 44.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for uvllang-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 96c9bc217ead0c5bef76abcfaff1956f26ee5208a22ede009fda8b95ddcf8633
MD5 0a43a9786a48a0a5e0274f17f167df28
BLAKE2b-256 fe7d6b0350116257abec40171c76300965c65238af258441d49395150aed89ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page