QapGen Installation, Usage, and Getting Started Guide
How to Install and Run QapGen
- Clone the repository:
git clone https://github.com/adler3d/QapGen- Go to the stable build directory:
cd QapGen/stable- Make the build script executable:
chmod +x build.sh- Run the build script:
./build.sh- Navigate to the Release folder:
cd Release- Run QapGen with your grammar file:
./QapGen.elf your_grammar_file.qapdsl.hpp dontoptimize_polymorphs
6223
> output.inlIf everything works correctly, the file output.inl will be generated.
Integrate output.inl into Your Project
You can integrate the generated output.inl file into your own project.
A simple example project is the Simple Calculator, available here:
https://github.com/adler3d/QapGen/tree/master/src/SimpleCalcSteps to use output.inl with SimpleCalc:
- Open the file:
QapGen/src/SimpleCalc/SimpleCalc/SimpleCalc.cpp - Replace the line:
#include "t_simple_calc.inl"with#include "output.inl" - Place the
output.inlfile in the same directory asSimpleCalc.cpp. - Remove the class
t_simple_calc_evaluatorfrom the project. - Modify the
main_2021function to the following minimal example:
string input = "your_script_or_code_or_text";
t_your_root_lexer root_lexer;
auto ok = load_obj(root_lexer, input);
if (!ok) return;
// Then traverse the tree stored in root_lexer using visitorsBuild and Run the SimpleCalc Project
To build and run on Linux/macOS:
g++ -O2 -std=c++17 SimpleCalc.cpp -o SimpleCalc.elf
./SimpleCalc.elfFor Windows Users
There is a Visual Studio 2017 solution file SimpleCalc.sln and a build batch script build.bat located in:
QapGen/src/SimpleCalc
Open the solution in MS Visual Studio 2017 and build the project there.
Summary
- Clone and build QapGen.
- Generate
output.inlfrom your grammar file. - Integrate
output.inlinto your project (e.g., SimpleCalc). - Adjust your main code to load and traverse the parsed tree.
- Build and run your project.
This will help you quickly start working with QapGen-generated parsers and lexers.