ldthomas / apg-7.0

APG - ABNF Parser Generator. C version with many new features. Partially-Predictive Parsing Tables increases parsing speed. Phrase-Matching Engine with more features and more power than regex. Lots of cool utilities and many examples of use.
Other
17 stars 4 forks source link

## APG Version 7.0

Overview
Documentation
Applications
Libraries
Installation
License

Update: The installation has been updated to include cmake files and scripts to automate the generation of executables and IDE project files for apg and its examples.

Overview

APG is an acronym for ABNF Parser Generator. It was originally designed to generate recursive-descent parsers directly from the ABNF grammar defining the sentences or phrases to be parsed. The approach was to recognize that ABNF defines a tree with seven types of nodes and that each node represents an operation that can guide a depth-first traversal of the tree – that is, a recursive-descent parse of the tree.

However, it was quickly realized that this method of defining a tree of node operations did not in any way require that the nodes correspond to the ABNF-defined operators. They could be expanded and enhanced in any way that might be convenient for the problem at hand. The first expansion was to add the "look ahead" nodes. That is, operations that look ahead for a specific phrase and then continue or not depending on whether the phrase is found. Next, nodes with user-defined operations were introduced. That is, a node operation that is hand-written by the user for a specific phrase-matching problem. Finally, to develop an ABNF-based pattern-matching engine similar to regex, a number of new node operations have been added: look behind, back referencing, and begin and end of string anchors.

These additional node operations enhance the original ABNF set but do not change them. Rather they form a superset of ABNF, or as is referred to here, SABNF.

Previous versions of APG have been developed to generate parsers in C/C++, Java and JavaScript. Version 7.0 is a complete re-write in C adding a number of new features.

Documentation

The documentation is included in the code as doxygen comments. To generate the documentation, install Graphviz and doxygen.

$sudo apt update
$sudo apt install graphviz
$sudo apt install doxygen
$doxygen

The documentation can then be found at

./documentation/index.html

Or view it at the sanbf.com website.

Note: It is recommened that before beginning an application using APG, at a minimum, Appendix A. Coding Conventions (especially Exceptions and Objects), and the basic parser application example in Appendix B. Examples in the documentation be consulted.

Applications

This repository consists of several applications and libraries, each being in its own directory. The applications are detailed here. The libraries in the next section. ./ indicates the repository directory.

Libraries

The library directories contain source code that is shared with many of the applications.

Note that these libraries cannot be conveniently built once and for all and used as static or dynamic-linked libraries. Each application is built, in general, with a different set of compiler directives. Therefore, the necessary libraries must be built from source along with the application that uses them.

Installation

cmake files, CMakeLists.txt, exist in the apg application directory as well as in each of the example application directories. These can be used to simplify the building of both the application executables and IDE project files for editing and debugging. The bash script, build.sh simplifies this for the case of Unix Makefiles and the Eclipse C/C++ IDE. For usage and suggestions for other build systems and IDEs run

$./build.sh --help

The installation document gives detailed instructions for creating Eclipse projects for apg and all of the examples both manually and using the ./build.sh script .

The script, run.sh is available to execute any of the applications that have been built. For usage execute:

$./run.sh --help

For example

$./build -r target
$./run.sh target

will execute any of the target applications. For the apg application note:

  1. If you will be needing this for other projects it may be convenient to move it to a PATH directory, e.g.
    $sudo cp Release/apg/apg70 /usr/local/bin.
  2. The reason for naming it apg70 is to distinguish it from the Automated Password Generator application, apg, which comes preinstalled on some systems.

For the example applications note that many of them require that a directory ./examples/output exists. The files that go here are transitory and available only for inspection and verification that the example is working correctly. A good usage might be

$ln -s /tmp ./examples/output

If the ./examples/output directory does not exist, the script build.sh will create it the first time it is run.

These cmake files and scripts have been tested on Linux Ubuntu 20.04 and Eclipse C/C++, version 4.16. Hopefully, they will also prove helpful for your favorite OS and IDE as well.

I want to thank hhaoao for suggesting the advantages of cmake. His CMakeLists.txt file in issue #2 was the model I used for all of the projects here.

License

APG Version 7.0 is licensed under the permissive, Open Source Initiative-approved 2-clause BSD license.