ANTLR4 grammars for McStas and McXtrace
Project description
Monte Carlo Particle Ray Tracing compiler via ANTLR4
Implementing the mccode-3 language and targeting the mcstas and mcxtrace runtimes.
Installation
Install the latest development version from GitHub with
$ python -m pip install git+https://github.com/mccode-dev/mccode-antlr.git
or the latest release from PyPI with
$ python -m pip install mccode_antlr
Use
The mccode-antlr package provides a command-line interface to the McCode language parsers
and translators. To avoid shadowing the McCode-3 translators, the command-line interface
are suffixed with -antlr.
$ mcstas-antlr --help
$ mcxtrace-antlr --help
A local cache is used for storing instrument component files and
runtime library files obtained from the McCode repository.
The cache and configuration parameters for the whole mccode-antlr module can be
accessed via a third command-line interface:
$ mccode-antlr --help
Language parsing with ANTLR4
The traditional McCode lex|flex tokenizer and yacc|bison parser
included in-rule code to implement some language features and called
the code-generator to construct the intermediate instrument source file.
The mixture of language parsing and multiple layers of generated functionality
made understanding the program operation, and debugging introduced errors,
difficult.
Worst of all, there is no easy-to-use tooling available to help the programmer
identify syntax errors on-the-fly.
This project reimplements the McCode languages using ANTLR4
which both tokenizes and parses the language into a recursive descent parse tree.
ANTLR can include extra in-rule parsing code, but since it can produce output
suited for multiple languages (and the extra code must be in the targeted language)
this feature is not implemented in this project.
Other benefits of ANTLR4 include integration with Integrated Development Environments,
including the freely available Community edition of PyCharm from JetBrains.
IDE integration can identify syntax mistakes in the language grammar files,
plus help to understand and debug language parsing.
McCode languages
Traditionally, McCode identifies as a single language able to read, parse, and construct
programs to perform single particle statistical ray tracing.
While McCode-3 uses a single language.l and language.y file pair for lexing and parsing,
it actually implemented at least two related languages: one for component definitions in .comp files,
one for instrument definitions in .instr files,
plus arguably more for other specialised tasks.
Notably the mcdisplay utilities of McCode make use of a special runtime output mode
to identify the positions and shapes of components, and the paths of particles, which
is then read by an independent ply parser to generated visualizations.
This project makes use of ANTLR's language dependency feature to separate the languages
into McComp for components and McInstr for instruments, with common language features
defined in a McCommon grammar.
Language translation
For use with the McCode runtimes (McStas and McXtrace), the input languages must be
translated to C following the C99 standard.
This translation was previously performed in C since the lex|flex, yacc|bison
workflow produced programs written in C.
The C programming language is a very good choice where execution speed is important,
as in the McCode runtimes, but less so if speed is not the main goal and memory safety
or cross-platform development is important.
The McCode-3 translators do not always deallocate memory used in their runtime,
and newly developed features are likely to introduce unallocated, out-of-bounds, or double-free
memory errors which are then difficult to track down.
ANTLR4 is a Java program, but produces parse-trees in multiple languages.
This project uses the Python target so that language-translation can proceed in a language
which is well suited to new-feature development, while removing memory handling issues and
making cross-platform development significantly easier.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mccode_antlr-0.18.5.tar.gz.
File metadata
- Download URL: mccode_antlr-0.18.5.tar.gz
- Upload date:
- Size: 470.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
575cb88e0c3dbde2e1cdde4097727ecb7fc2179ed993fab26db293029c011cbd
|
|
| MD5 |
569ce96a348b151cac75763a5c65dea6
|
|
| BLAKE2b-256 |
40ec2a45044a60d998cb2680686ad17f82c196326691daece00d6ec1548af8d2
|
Provenance
The following attestation bundles were made for mccode_antlr-0.18.5.tar.gz:
Publisher:
wheels.yml on mccode-dev/mccode-antlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mccode_antlr-0.18.5.tar.gz -
Subject digest:
575cb88e0c3dbde2e1cdde4097727ecb7fc2179ed993fab26db293029c011cbd - Sigstore transparency entry: 1011709024
- Sigstore integration time:
-
Permalink:
mccode-dev/mccode-antlr@4a22af9617c0a75e6e4435e0813283fef96dc66e -
Branch / Tag:
refs/tags/v0.18.5 - Owner: https://github.com/mccode-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@4a22af9617c0a75e6e4435e0813283fef96dc66e -
Trigger Event:
release
-
Statement type:
File details
Details for the file mccode_antlr-0.18.5-py3-none-any.whl.
File metadata
- Download URL: mccode_antlr-0.18.5-py3-none-any.whl
- Upload date:
- Size: 391.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd870a7df792ff25b4b3784933e016d8acf628db3189069bcf4e5a1d4a20b147
|
|
| MD5 |
ce42d1e59bfc1156dc0abf61de6237a6
|
|
| BLAKE2b-256 |
2a3cb88b57c1e45f3982145b85cf61fe9a9775f7bff7e517485c6a0dc626e49d
|
Provenance
The following attestation bundles were made for mccode_antlr-0.18.5-py3-none-any.whl:
Publisher:
wheels.yml on mccode-dev/mccode-antlr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mccode_antlr-0.18.5-py3-none-any.whl -
Subject digest:
bd870a7df792ff25b4b3784933e016d8acf628db3189069bcf4e5a1d4a20b147 - Sigstore transparency entry: 1011709091
- Sigstore integration time:
-
Permalink:
mccode-dev/mccode-antlr@4a22af9617c0a75e6e4435e0813283fef96dc66e -
Branch / Tag:
refs/tags/v0.18.5 - Owner: https://github.com/mccode-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
wheels.yml@4a22af9617c0a75e6e4435e0813283fef96dc66e -
Trigger Event:
release
-
Statement type: