headerphoto

Recent News

04/15/10: A bug was found in the algorithm for rule attributes.
S = (S/"") "s" / "y" is left-recursive but went undetected due to the empty string alternative. This case has been fixed.
more…

12/02/09: A new Interactive APG web service for ABNF grammar development has been added to the site. At the same time APG Version 6.1 has been released.
more…

06/25/09: Congratulations to Thomas Miesch on the completion of his Open Source project SmallMGC. SmallMGC is a Media Gateway Controller for access and residential gateways.
more…

06/23/09: Thanks again to Sebastian Pipping (http://www.hartwork.org/) for creating a Gentoo package for APG 6.0. more…

06/17/09: APG 6.0 has just been released. Version 6.0 updates APG 5.x with some significant new features.
more…

Interactive APG Tutorials

Just click on the links below and follow the instructions on the tutorial page. When you are done, return to this page and continue on with the next example.

Tutorial 1 – Grammar Syntax Checking

This first exercise will walk you through the basics of grammar syntax checking. Many common errors will be presented and corrected.

Tutorial 2 – Configuring the Input Mode

The input strings to the parser are not limited to ASCII. Any byte from 0 to 255 is allowed, depending on the grammar. This example will demonstrate how to present non-ASCII strings to the browser interface.

Tutorial 3 – Configuring the Display Mode

Similarly, the parser's output will sometimes be non-ASCII strings as well. This example will demonstrate the formats used for the display of non-ASCII output and how they are controlled.

Tutorial 4 – Configuring the Parser Trace

When something goes wrong, examining the trace – a chronological record of the parser's pathway through the syntax tree – is the primary tool for error discovery. The trace will tell us which nodes the parser visited, which visits failed, which were successful and what phrases were discovered at each successful visit. However, there are often thousands, even millions, of node visits in a typical parse. Filtering the problem nodes out from the total is often like finding a needle in a haystack. APG provides fine-grained control over which node visits actually get recorded and displayed. Tutorials 4 and 5 are designed to walk you through the filtering controls.

Tutorial 5 – Configuring the Trace Display

The Parser Trace, during the parsing process, filters the node visits for a subset to actually be saved for later examination. The Trace Display, during the record display process, further filters from the saved records an even smaller subset to actually be displayed. The Trace Display controls are only slightly different from the Parser Trace controls and this tutorial will demonstrate the differences.

Tutorial 6 – Working with the Prioritized-Choice Rule

Ambiguities arise when one or more alternative choices in the grammar lead to a successful parse. Multiple parse trees exist, giving multiple phrasing interpretations of a single language sentence. An "exhaustive" parser will generate all possible parse trees. (e.g. See the Earley algorithm and it implementations.) While advantagous to some applications, in general it adds the additional process of selecting the proper parse tree for the application - a choice requiring some semantic interpretations.

APG, like PEG, which coined the phrase, uses a "prioritized-choice" disambiguation rule to avoid this parse tree selection problem. When writing a new grammar, I find that the prioritized-choice rule is often very helpful in quickly achieving an accurate grammar, true to the specification. However, the way many Context-Free Grammars (CFGs) are written, exhaustive parsing is required to match the specification. In these cases, some grammar rules will often need to be rewritten to get the correct interpretation with the prioritized-choice rule. Usually, with a little ingenuity, this is possible, though by no means guaranteed. This tutorial examines a few typical cases.

[top]