What is the role of empty production for PEG?

Empty production rule

nonterminal -> epsilon

useful in lex-yacc LR parser generators (e.g. PLY).

In what context should empty derivatives be used in PEG parsers, for example. pyraring?

+5
source share
1 answer

BNFs are often used empty as an alternative, effectively making the generic expression optional:

leading_sign ::= + | - | empty
integer ::= leading_sign digit...

This is not necessary in pyparsing, since pyparsing includes an extra class for this:

# no empty required
leading_sign = Optional(oneOf("+ -"))
integer = leading_sign + Word(nums)

Empty can be useful for certain purposes related to pyraming:

- pyparsing , CharsNotIn restOfLine. , , , :

"Key 1" value of Key 1
"Key 2" value of Key 2

:

quotedString + restOfLine

" 1" " 2" . Pyparsing empty , :

quotedString + empty + restOfLine

.

- originalTextFor, . , originalTextFor .

, . empty , ( ). :

OneOrMore(empty)

.

empty | "A" | "B" | "C"

, MatchFirsts .

+4

All Articles