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.