This project is an example on how to use parol-pygen in
praxis. The used input grammar description pascal.par uses %grammar_type 'LALR(1)'
directive to instruct parol to use an LR parser algorithm.
This project shows a scaffolded parser project generated by parol-pygen init.
This project requires Python 3.10+ and uses a local virtual environment in .venv.
Script variants are available for both platforms:
- PowerShell:
scripts/*.ps1 - Bash:
scripts/*.sh
-
Install Python
>=3.10. -
Install uv (recommended).
-
Verify tools are available:
python --version uv --version
On Windows a global python installation may also be accessible via
pylauncher utility which is sufficient for our purpose.py --version
From the repository root:
If you are on Linux/macOS, make scripts executable once:
chmod +x ./scripts/*.sh-
Bootstrap the local environment:
./scripts/bootstrap.ps1
./scripts/bootstrap.sh
This script:
- creates
.venv(if missing) viauv venv .venv - installs dependencies via
uv sync - resolves
parol-pygenfrom PyPI according topyproject.toml
- creates
-
Activate the virtual environment (optional but convenient for manual commands):
.\.venv\Scripts\Activate.ps1
source .venv/bin/activate -
Generate parser code:
./scripts/generate-parser.ps1
./scripts/generate-parser.sh
-
Run the proof/example parser:
./scripts/run-proof.ps1 .\basics.pas
./scripts/run-proof.sh ./basics.pas
You can also run tools through uv without activating the environment, for example:
uv run python .\proof_runner.py .\basics.pasuv run python ./proof_runner.py ./basics.pasIf you cannot use uv, you can still set up a working environment manually:
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -e .-
Generate the export JSON
pascal_export.jsonusing Parol CLI:parol export -f .\pascal.par -o .\pascal_export.json --prettyTo be able to use the Parol CLI, you should additionally install Parol, e.g. using
cargo:cargo install parol -
Run
./scripts/bootstrap.ps1or./scripts/bootstrap.sh -
Run
./scripts/generate-parser.ps1or./scripts/generate-parser.sh -
Run
./scripts/run-proof.ps1or./scripts/run-proof.sh
Example:
PowerShell: ./scripts/run-proof.ps1 .\basics.pas
Bash: ./scripts/run-proof.sh ./basics.pas
- Package name:
pascal_py - Entry parser class:
pascal_py.Parser - User semantic action base:
pascal_py.UserActions