opencrbasic
A native re-implementation of Campbell Scientific's CRBasic pre-compilers for the CR6, CR1000X,
CR300 and CR350 dataloggers (CR6Comp.exe, cr1000xcomp.exe, cr300comp.exe, cr350comp.exe),
with a language server. It runs on Linux, macOS and Windows with only Python 3.15+, no Wine and no
Windows binaries. It is MIT licensed and not affiliated with, endorsed by or derived from code of
Campbell Scientific; provenance and what this repository deliberately leaves out are in the
legal notes. It checks programs; it is not the reference compiler, so keep
Campbell's compiler as the gate before flashing hardware.
Install
pip install opencrbasic # crbc, the compiler
pip install "opencrbasic[lsp]" # also crbc-lsp, the language server (adds pygls)
# or, with uv:
uv tool install opencrbasic # uv tool install "opencrbasic[lsp]" for the language server
Requires Python 3.15 or newer. The compiler has no runtime dependencies.
Related projects
- open-crbasic-vsix: VS Code extension
(Marketplace:
OttodeVisserUU.opencrbasic), the client forcrbc-lsp. - open-crbasic-rs: a Rust port of the
verdict path (crate
opencrbasic, binarycrbc), equal to this package on all fixtures. - open-loggernet: a LoggerNet-free client
and
olncommand line for the loggers; it uses opencrbasic as its compiler whenCR6COMP=opencrbasicis set.
Supported loggers
| Logger | --logger |
File extension | Status |
|---|---|---|---|
| CR6 | cr6 (default) |
.CR6 |
gated against CR6Comp.exe |
| CR1000X | cr1000x |
.CR1X |
gated against cr1000xcomp.exe |
| CR300 | cr300 |
.CR300 |
best effort |
| CR350 | cr350 |
.CR350 |
best effort |
"Gated" means the reference verdict, execution mode and first error for realistic mistakes are
compared with the real compiler on every release; "best effort" means measured and kept, not gated.
Per-logger differences: docs/loggers.md.
Limitations
- Not the reference compiler. Measured against the real compilers on the CRBasic help examples,
a field station's programs and fuzzed mutations, not exhaustively. A small number of false accepts
(programs opencrbasic accepts and Campbell's compiler rejects) are known and listed in the
release record. In the gated area one is known: a
Subname that is also another routine's parameter, used as a value. - Diagnostics after the first error may differ in order, wording or cascade from the reference.
The first error is fixed when it comes from a realistic mistake
(
docs/first-error-review.md). - Not implemented: the CDM binary image of
-b(an empty file is written for programs that use CDM hardware);-mis accepted and does nothing;-tcovers only the oracle-fitted instruction set. CR1000X, CR300 and CR350 table definition files (-z) use the CR6 Status table (best effort). Outputs and what is best effort per profile:docs/artifacts.md. - Editor: the editor features were host-tested in VS Code on macOS only; Windows and Linux are not claimed, and the check and coverage-notice display has not been host-tested.
- No hardware tests: compiling and comparing says nothing about runtime behaviour on a logger.
Three channels
Every finding belongs to one channel (PLAN):
- Reference diagnostics: what the reference compiler reports. Default
crbcstdout, the message file and the exit status carry only these, socrbcstays a drop-in. - opencrbasic checks (
OCB001-OCB007): likely defects the reference accepts, each with evidence, controls and a default severity;crbc --strict(stderr, exit 3 on a check error),--report,opencrbasic.toml, and the editor (sourceopencrbasic (check)). Seedocs/checker.md"opencrbasic checks OCB002-OCB007 (M3)". - Coverage notices: CR6 reference rules opencrbasic is known not to model, from the
evidence inventory;
--reportand, when enabled, editor hints. Information, never a verdict.
Accepted differences
In the differential tools, equal means equal exit status and equal stdout after whitespace
normalization (line endings, trailing spaces); the artifact matrix compares bytes. Differences in the order,
wording or cascade of diagnostics after the first error are accepted;
differences in the first error are fixed when they come from a realistic mistake and otherwise
recorded in docs/first-error-review.md. Runner failures and
reference crashes are never counted as verdicts.
Versions
- The package version (
pyproject.toml) andopencrbasic.__version__are one number (tests/test_versions.py). Major: a change to the drop-in contract or a gated verdict policy; minor: new checks, notices or features; patch: fixes. The VS Code extension, in its own repository, has its own version. analysis.API_VERSION(now 2) versions the editor facade; the language server refuses to start with another (docs/lsp-api.md).checks.SCHEMA_VERSION(now 2) versions the--reportJSON. Each is bumped only on an incompatible change.
Usage
crbc is a drop-in for CR6Comp.exe (docs/cli.md):
crbc [options] program [messagefile]
-s also print ProgSignature
-z FILE write the binary table definition file (TDF)
-l FILE write the text table list (also -c)
-p FILE / -i FILE write the preprocessed source (-i also expands Include/IncludeSection)
-u add "declared but not used" warnings
-t the [Times] section (oracle-fitted instruction set only)
-b FILE CDM binary image (not implemented; see Limitations)
-v / -d print version (then compile / and exit)
--logger L cr6 | cr1000x | cr300 | cr350 (default: from the file extension
.CR6/.CR1X/.CR300/.CR350, else cr6)
--no-message-file do not write the message file (CR6cmple.xxx, CR1000Xcmple.xxx, ...)
--strict also run opencrbasic checks (likely defects the reference accepts) on stderr;
exit 3 when the program compiles but a check reports an error
(exit 4: invalid opencrbasic.toml)
--report FILE write a JSON report (reference verdict and diagnostics, check findings)
--config FILE use this opencrbasic.toml (default: nearest ancestor of the program)
--check CODE=SEVERITY set a check severity (error|warning|info|off); repeatable
--expand FILE expand #Define/#Macro macros into FILE, then compile FILE instead
#Define and #Macro are an opencrbasic extension, not CRBasic: the reference compilers reject
them. --expand writes plain CRBasic (definitions commented out, uses expanded inline) that
CR6Comp.exe accepts and that is the file to send to the logger; write it next to the source so
its Includes resolve. The language server expands them the same way, so the editor reports
the expansion's diagnostics on the line of each use. Syntax and rules:
macros.py.
#Define LOGD(msg) DebugMsg = msg ' release build: #Define LOGD(msg)
#Macro LOGV(name, value)
DebugMsg = name & "=" & value
CallTable Debug
#EndMacro
Check configuration and the report schema: docs/checker.md "Check configuration and report file".
Output follows the exe's format: Program.CR6 -- Compiled in SequentialMode. (CR300/CR350:
-- Compiled OK.), Warning: ... lines, or -- Compile Failed! followed by line N: message
lines; the same text goes to <LOGGER>cmple.xxx (for example CR6cmple.xxx) with CRLF line
endings; exit status 0 or 1.
As a library:
from pathlib import Path
from opencrbasic import profiles
from opencrbasic.compiler import compile_file
result = compile_file(Path("Main.CR6"), profiles.get("cr6"))
result.ok, result.mode, result.signature
[d.cr6comp() for d in result.diagnostics.items]
result.tables # list of tdf.TdfTable (Status, DataTables, DataTableInfo, ConstTable, Public)
parser.parse_file() gives the syntax tree (syntax.py) for other tools.
openloggernet uses opencrbasic when
CR6COMP=opencrbasic is set.
Editor support
crbc-lsp (python -m opencrbasic.lsp) is a language server for CRBasic programs; the logger
setting selects the CR6 profile (default) or CR1000X, CR300 or CR350. It reports the compiler's
diagnostics and offers hover, completion, signature help, outline, folding, go to definition,
references, highlighting, rename, formatting and quick fixes. Its highlighting names are the CR6 ones.
The VS Code client is open-crbasic-vsix. Setup, settings, feature limits and the
host-tested status are in docs/lsp-user-guide.md. It also shows the
opencrbasic checks and, with opencrbasic.coverageNotices, the coverage notices. The editor features
were host-tested in VS Code on macOS (T-01 to T-18, LSP_TO_BE_TESTED.md); the check and notice display
(M6) has not been host-tested yet, and Windows and Linux are not claimed.
Development
Python dependencies are managed with uv. The package itself has
no runtime dependencies; the dev group adds pytest, pefile (for the reverse-engineering tools),
pygls, pyrefly and pre-commit.
uv sync # environment from uv.lock
uv run pre-commit install # ruff, pyrefly and file hygiene on every commit
uv run pytest -q -n auto # tests
uv run crbc Program.CR6 # compile with the checkout
uv tool install . # optional: `crbc` on PATH outside the project
Contributor and agent conventions: AGENTS.md.
How it was built
The exe is the logger's own compiler built for Windows. Its instruction, function and
predefined-symbol tables were extracted from the binary (tools/extract_tables.py), its
behaviour was studied with Ghidra and with thousands of runs of the real exe under Wine, and
everything is checked differentially:
| Tool | Checks |
|---|---|
tools/oracle.py |
runs the real exe under Wine (cached) |
tools/difftest.py --logger L |
normalized output vs the exe over repository programs and 507 CHM help examples |
tools/tdftest.py |
-z TDF and -l table list, byte for byte |
tools/fuzz.py, tools/fuzz_replay.py |
mutated programs, differential; reproducers in tests/corpus/fuzz/ |
tools/artifact_matrix.py |
every output file per profile and option set, with a baseline gate |
tools/inventory.py |
the CR6 evidence inventory and the coverage-notice table |
uv run pytest -q |
unit tests, corpus parse tests, TDF fixtures |
The tools that run the real compilers need them in a local, git-ignored compiler/ directory
(copy CR6Comp.exe, cr1000xcomp.exe, cr300comp.exe and cr350comp.exe from a CRBasic Editor
install) and Wine on macOS and Linux.
Differential and replay runs default to reporting differences without failing on known gaps. Use the gates when a nonzero exit is required:
uv run tools/difftest.py --logger cr6 --gate no-regressions
uv run tools/difftest.py --logger cr6 --gate exact
uv run tools/fuzz_replay.py --gate no-regressions --json replay.json
uv run tools/fuzz_replay.py --gate exact --json replay.json
no-regressions fails for a false rejection, opencrbasic crash or hang (and both tools
fail for an oracle error). exact fails for any result that does not match the normalized
reference output. Replay's --json FILE writes summary counts and individual result rows for CI
and later triage. See PLAN.md for how remaining differences
are measured and fixed.
Reverse-engineering notes: docs/binary.md (exe layout), docs/cli.md, docs/type-codes.md
(parameter kinds), docs/frontend.md (language quirks), docs/checker.md and
docs/instructions.md (diagnostic rules), docs/modes.md (Sequential/Pipeline),
docs/tdf-rules.md (table definitions), docs/loggers.md (per-logger differences),
docs/fuzz-findings.md. Provenance and licensing questions: docs/legal.md.
Layout
src/opencrbasic/
lexer.py source.py consteval.py parser.py syntax.py front end
checker/ semantic checks and diagnostics
mode.py tables.py tdf.py signature.py outputs
profiles.py data/<logger>/*.json per-logger tables and rules
compiler.py cli.py driver and crbc
tools/ oracle, difftest, tdftest, fuzzing, table extraction, Ghidra script
tests/ unit tests, corpora, fixtures
docs/ behaviour of the original compilers, with evidence
Releasing
Every push to dev that passes CI is published to TestPyPI as <version>.dev<run number>. A push
to main publishes to PyPI when version in pyproject.toml (and opencrbasic.__version__) has
not been released yet. Publishing uses PyPI trusted publishing from the pypi and testpypi GitHub
environments; no API token is stored in the repository.
License
MIT, copyright 2026 Utrecht University. Campbell Scientific, CRBasic, CR6, CR1000X, CR300, CR350 and LoggerNet are trademarks of their owners; this project is independent of them.
Metadata
Release files for opencrbasic 1.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opencrbasic-1.3.0.tar.gz | 659.9 kB | With provenance | Details for opencrbasic-1.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opencrbasic-1.3.0-py3-none-any.whl | Python 3 | none | any | Details for opencrbasic-1.3.0-py3-none-any.whl |
Total release size: 1.4 MB
Release files / opencrbasic-1.3.0.tar.gz
| Download URL | opencrbasic-1.3.0.tar.gz |
|---|---|
| Size | 659.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b6b753c2af5e8d4e09e24e8a736b76e8779024a0a07aecfc10017a5815a67a71
|
|
BLAKE2b-256 checksum How to use checksums |
dc25ef230c1b62706fec60a02c9c202ce31e35e26987f4c4d95a30f33c5562e9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logRelease files / opencrbasic-1.3.0-py3-none-any.whl
| Download URL | opencrbasic-1.3.0-py3-none-any.whl |
|---|---|
| Size | 705.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8c19272d04ab055c9c5123651b61be2df34b4a0787acc80823cea62628b2bf7
|
|
BLAKE2b-256 checksum How to use checksums |
97445d2957d2b5e3730502359ba85635f216fcdcf6311e426d8facfba32f1673
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logSecurity for opencrbasic 1.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for opencrbasic-1.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.