headerphoto

ABNF and APG Grammars

APG was originally written to fulfill a need for a parser generator that would generate parsers directly from ABNF grammars as defined by the IETF in RFC 4234. Since then the grammar syntax for APG has evolved from that standard to a) generate unambiguous parsers and to b) add capabilities beyond the class of context-free-languages. The differences between RFC 4234 grammars and SABNF are summarized here:

  1. The <prose-val> element is not supported.
  2. Incremental Alternatives - Rule1 =/ Rule2 - are not supported.
  3. Prioritized-choice is used to disambiguate the grammars. That is, alternates are tried as they appear in the grammar rule definitions from left to right. The first alternate to successfully match a phrase is accepted and all other alternates are ignored.
  4. Repetitions always consume the longest string possible with no alternative being considered.
  5. APG accepts the syntactic predicate operators AND(&) and NOT(!).
  6. Java APG accepts User-Defined Terminals (UDTs). UDTs appear in rule expressions just like rule names, except that the names must begin with u_ or e_ (see the UDT naming conventions). The underscore insures that there will never be a name conflict with a rule name. No rule name definition is given for the UDTs.

Because of items 5. and 6. above the APG grammars are called SABNF (superset ABNF). ABNF and SABNF will often be used interchangably in this document.