headerphoto

APG Version 5.0 - Tables

Table 3. SABNF operators as PEG operators. R, E are SABNF rule names and expressions, respectively. A, e are PEG non-terminals and expressions, respectively. (1)

SABNF Operator PEG Operator SABNF Description
%dn [] character class single character
%dn-m [] character class range of characters
%dx.y… " " literal string binary string
"abc" e1 e2 e3 (2) literal string
R A named expression
(E) (e) unnamed expression
[E] e? optional expression
!E !e not, syntactic predicate
&E &e and, syntactic predicate
*E e* repetition
n*mE (3) repetition
E1 E2 e1 e2 concatenation
E1 / E2 e1 / e2 alternation

(1) SABNF rule names, R, are defined with an identifier followed by "=". PEG non-terminals, A, are identifiers followed by "<-".

(2) One way to represent the ABNF case-insensitive literal string, not necessarily the best, is to define a set of PEG expressions, one for each non-alpha character and one prioritized choice of the upper and lower cases for each alpha character. The PEG equivalent of the SABNF literal string would then require a sequence of the so-defined expressions.

(3) The case (n, m) != (0, ∞) can be represented as sequences on a case-by-case basis. eg. 2*3E = e e e / e e, or 2*E = e e e*, etc.

Table 4. PEG operators as SABNF operators. E = SABNF expression. e = PEG expression.

PEG Operator SABNF Operator PEG Description
' ' %dx.y…, binary string literal string
" " %dx.y…, binary string literal string
[ ] %dn-m / %dx-y / … (1) character class
. %d0-N (2) any character
(e) (E) grouping
e? [E] optional
e* *E zero or more
e+ 1*E one or more
&e &E and-predicate
!e !E not-predicate
e1 e2 E1 E2 sequence
e1 / e2 E1 / E2 prioritized choice

(1) An alternation of characters and character ranges.

(2) N + 1 is the number of characters in the symbol alphabet.