ISPA is a static parser and lexer generator written from scratch in modern C++ (C++23). You describe a grammar once; ISPA compiles it ahead of time into a lexer and parser that build a fully typed AST. Generated C++ targets C++17; Python output is also available.
The wiki covers setup, grammar syntax, generated APIs, algorithms, recovery, external parsers, packages, and debugging.
It is built around one idea: easy to use, without giving up performance, extensibility, or features. In benchmarks it is about 12x faster than ANTLR; see Performance.
The backends lower grammar structure and AST captures to C++ or Python. Support for advanced actions and recovery differs by algorithm; see LR backend status.
For .isc editor diagnostics and navigation, see the ISPA language server, the VS Code extension, and the JetBrains plugin.
Generate and build a parser with the current generator, then run its existing executable under ispadbg:
./ispadbg --purpose matching --purpose ast -b grammar.isc:12 \ --record parser-trace.json -- ./my-parser input.txt ./ispadbg --replay parser-trace.json For a graphical view, run ./ispadbg-gui (or the installed ispadbg-gui). Choose a parser program, enter an input string, then click Run. The input is passed as one command-line argument by default, as in examples/main.cpp; choose Standard input for parsers that read stdin. Use Step, Next, Finish, and Continue while paused. Select any trace row to inspect its variables, including ctx and AST values, in the expandable tree. Open trace and Save trace use the same JSON format as ispadbg --replay and --record. The GUI uses Python's Tkinter and needs a desktop display.
Debug instrumentation is enabled by default when generating parsers. Pass --no-debug-instrumentation to ispa to omit generated source checkpoints, scope events, and value serialization. Pass --debug-instrumentation to explicitly enable them.
Purpose IDs are matching, failure, and ast; failure is the default. The debugger prints the selected IDs at startup. The interactive commands are s (step), n (next), f (finish), c (continue), b file:line (breakpoint), p [name] (inspect a value), ctx, back, forward, and live. back and forward inspect recorded snapshots while the parser is paused; execution resumes from the live pause. Use --no-interactive to record without pausing.
C++ generated code emits rule and production scopes, match outcomes, typed captures, source checkpoints for converted Python statements, and typed AST snapshots. The Python target uses the same v2 event protocol through parser/stdlibs/target/ispa_debug.py; include that directory in PYTHONPATH alongside ispa_std.py when running a generated Python parser. Traces are JSON and can be replayed after the parser exits. Live parser sessions currently require POSIX file descriptors; the Windows ispadbg executable supports offline --replay and help.
ISPA is self-hosting for its own grammar. The .isc grammar that describes ISPA's input language was compiled by ISPA into the parser that ISPA now uses to read grammars, replacing the original hand-written parser. A Python-subset parser and a small module-scanner parser are generated the same way.
The generated bootstrap parser is committed under parser/ispa/bootstrapped_0 and is built with ISPA before the generator processes other grammars.
An external import calls a separately generated parser and captures its original node type:
import extern python ispa_python as python; expr: @ python.expr {@}; Use --dep NAME PREFIX to select an existing parser. PREFIX has no extension; ISPA reads PREFIX.ispa-export for exported symbols and uses PREFIX.h as its public header for C++ output or PREFIX.py for Python output. For example:
ispa -l cpp -a LL --dir parser/ispa/grammar parser/ispa/entry.isc \ --dep python parser/python/bootstrapped/PyRawParser -o build/Parser The generated C++ includes and uses PyRawParser::Types directly. Add the dependency directory to the compiler's include path and link its implementation as a static or shared library. The host does not generate copies of the imported parser's productions or types. Export entry declarations live in the dependency header; their definitions live in its .cpp file.
With --no-dep, ISPA discovers external grammar modules in the supplied --dir directories and generates each dependency beside the host, using the external dependency name as its output prefix. C++ dependencies remain separate .h/.cpp files and must be compiled and linked by the build system. Nested dependencies are generated before their consumers; dependency cycles are diagnosed. Explicit --dep bindings may supply existing libraries while --no-dep builds the rest.
External parser calls currently require LL generation and lazy tokenization. An eager lexer rejects grammars containing external calls with an AMBIGUOUS diagnostic. Lazy calls re-lex the imported span with the target lexer so token payloads match the target parser, then resume the host lexer at the returned source position.
For the Python target, generate with -l python -a LL. Put the generated modules and parser/stdlibs/target on PYTHONPATH so ispa_std is available:
PYTHONPATH=build:parser/stdlibs/target python3 -c 'import Parser; print(Parser.Parser().parse("input"))' Python external imports use the generated dependency module (for example, import Foreign) and its exported parser bindings. Keep dependencies on PYTHONPATH beside the host parser. --dep and --no-dep work as above.
Lex + parse of the same input, compared against flex + bison (LALR(1)) and ANTLR (C++ target). Lower is better; the multiplier is relative to flex + bison without an AST.
Flex + bison figures are steady state over 10 iterations.
See the separate Advanced Rules and Fail Blocks guide.
Install ISPA from a release, install its standard library package, and enable the package exports for future shells:
ispa-pkg install std ispa-pkg --export-permanent Open a new shell. The installed shell helper exposes the include paths and CMake targets; run ispa-pkg --export in that shell whenever you want to refresh them. Then create grammar.isc:
module main -> demo; NUMBER: @ [0-9]+ {@}; main: @ NUMBER {@}; Generate the C++ parser:
ispa -l cpp -a LL grammar.isc -o generated/Parser Use the generated parser in your application and link the installed targets through CMake. In CMakeLists.txt:
cmake_minimum_required(VERSION 3.20) project(demo LANGUAGES CXX) include("$ENV{ISPA_TARGETS_CMAKE}") add_executable(demo main.cpp generated/Parser.cpp) target_link_libraries(demo PRIVATE ISPA::Targets) This target supplies the installed ISPA headers and runtime libraries. See the wiki for a complete installed-user walkthrough, including Python output.
ISPA has prebuilt GitHub Release archives for Linux x86_64, Windows x64, and macOS Apple Silicon (ARM64). macOS Intel is supported by the installer only if its release archive exists. All commands install for the current user, with no administrator privileges needed.
Release installers provide ispa-pkg and ispadbg alongside ispa. For a source checkout, install both Python CLIs with python3 -m pip install . (Python 3.9+ and PyYAML). Tagged releases also publish standalone Nuitka builds named ispa-pkg- and ispadbg- (.tar.gz, or .zip on Windows) for the four supported Linux, Windows, and macOS targets. The ISPA platform archives include both executables, which the installers and updaters activate. The CLI lives in cli/pkg. Libraries are installed under ~/.local/share/ispa/libraries by default on Linux and macOS, or under the ISPA installation directory when launched from an installed release; use ISPA_PKG_ROOT to choose another location for both commands (ispa-pkg --root changes only the package command). ispa searches the matching directory for grammar and import py libraries automatically. It also loads its bundled algorithm and converter plugins beside the executable. The installed package has ispalib/grammar, ispalib/python, ispatarget/ , and ispaalgorithm directories. When compiling generated target code, add its ispatarget/ directory to your compiler or interpreter search path. Installed external parser manifests (NAME.ispa-export beside NAME.h or NAME.py) also provide --dep bindings automatically. A package with one manifest can be referenced by its package name; an explicit --dep wins.
ispa-pkg install std ispa-pkg install owner/repository --ref v1.2.0 ispa-pkg install https://example.org/mylib.tar.gz --name mylib ispa-pkg update ispa-pkg list ispa-pkg catalog update ispa-pkg catalog list Run ispa-pkg --export-permanent once, then open a new bash, zsh, or PowerShell session. This installs a small shell function and loads the exports on startup. In that shell, ispa-pkg --export refreshes the exports in the current session without an eval command. The standalone executable prints shell code when the function is not loaded, because a child process cannot change its parent shell. Exports add C++ header and library directories to compiler and linker search paths, shared library directories to the runtime loader path, and Python target directories to PYTHONPATH. Existing search paths are preserved. The generated ISPA_TARGETS_CMAKE file defines ISPA::Targets with installed headers and libraries for CMake projects. During installation, ispa-pkg compiles each package's ispatarget/cpp/**/*.cpp files as C++17 and archives them in ispatarget/cpp/lib (lib .a, or .lib with MSVC). This requires a C++ compiler and archiver; set CXX, CXXFLAGS, and AR to select the toolchain. Export also builds archives missing from older installations. The archive directory is added to LIBRARY_PATH (or LIB on Windows), and the archive path appears in ISPA_CPP_LIBRARIES and ISPA_TARGETS_CMAKE. For GCC and Clang, the C++ header search variables are CPATH and CPLUS_INCLUDE_PATH; CPLUSPLUS_PATH is not recognized. Generated C++ code and the target runtime build with C++17, for example clang++ -std=c++17 -c Parser.cpp after loading the exports. An already installed ispa-pkg executable and std library package must be updated to receive changes made in this source checkout.
The catalog is ispa-libraries.yaml at the repository root. catalog update fetches the current file from GitHub into the local package root; --catalog FILE selects another YAML catalog. A catalog entry specifies github: owner/repository with optional ref, or archive: URL. Installed GitHub packages update when their commit changes. Archives and local directories update when their contents change. --force reinstalls a package.
Library repositories may provide ispa-package.yaml at their root. The ispa-package.yaml in this repository demonstrates the standard library: its source is parser/stdlibs, with renamed folders mapped to their standard destinations. Without a config, package sources are read from ispalib/grammar, ispalib/python, ispatarget/cpp, ispatarget/python, and ispaalgorithm. A config can also use layout.root for a release directory, or archive: release/library.zip to unpack an archive from the repository before applying the layout. An install list of repository relative .py or shell script paths runs after copying files; scripts receive the staged destination as their first argument. Pass --allow-scripts to install or update a package that declares scripts. Use layout.files to map individual files such as target/ispa_std.py. LL and LR algorithm plugins are bundled with ISPA; they are not part of std.
Review scripts/install.sh, then install with:
curl -fsSL https://raw.githubusercontent.com/Sinfolke/ispa-parser-generator/main/scripts/install.sh | sh This downloads the newest published GitHub Release for your OS and architecture. The binary is linked as ~/.local/bin/ispa. Make sure ~/.local/bin is on your PATH, then run:
ISPA_VERSION=v1.1.0 sh -c "$(curl -fsSL https://raw.githubusercontent.com/Sinfolke/ispa-parser-generator/main/scripts/install.sh)" Windows (PowerShell) Review scripts/install.ps1, then run:
irm https://raw.githubusercontent.com/Sinfolke/ispa-parser-generator/main/scripts/install.ps1 | iex Open a new terminal and run ispa --help. The installer creates %LOCALAPPDATA%\Programs\ISPA\bin\ispa.cmd and adds that directory to your user PATH.
$env:ISPA_VERSION = 'v1.1.0' irm https://raw.githubusercontent.com/Sinfolke/ispa-parser-generator/main/scripts/install.ps1 | iex Change install location On Linux/macOS, set ISPA_INSTALL_DIR and/or ISPA_BIN_DIR before running the installer. On Windows, set the same environment variables in PowerShell before executing the script.
ispa-update To remove ISPA on Linux/macOS (with default paths):
rm -f "$HOME/.local/bin/ispa" rm -rf "${XDG_DATA_HOME:-$HOME/.local/share}/ispa" On Windows (with default paths), remove %LOCALAPPDATA%\Programs\ISPA, and delete that folder's bin entry from your user PATH.
Note: you will not be able to build ISPA with GCC yet. Note: the Clang build is not tested on Windows.
Configure. Change ISPA_SOURCE_DIR to your local path:
export ISPA_SOURCE_DIR=/path/to/ispa-parser export CC=clang-20 export CXX=clang++-20 export CFLAGS="-stdlib=libc++" export CXXFLAGS="-stdlib=libc++" export LDFLAGS="-stdlib=libc++" cmake -B cmake-build-release \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_TOOLCHAIN_FILE=~/vcpkg/scripts/buildsystems/vcpkg.cmake \ -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=$ISPA_SOURCE_DIR/cmake/toolchains/clang-libcxx.cmake \ -DVCPKG_TARGET_TRIPLET=x64-linux-libcxx \ -DVCPKG_OVERLAY_TRIPLETS=$ISPA_SOURCE_DIR/cmake/triplets Build:




