Parsing Expression Grammar - Advantages

Advantages

Compared to pure regular expressions (i.e. without back-references), PEGs are strictly more powerful, but require significantly more memory. For example, a regular expression inherently cannot find an arbitrary number of matched pairs of parentheses, because it is not recursive, but a PEG can. However, a PEG will require an amount of memory proportional to the length of the input, while a regular expression matcher will require only a constant amount of memory.

Any PEG can be parsed in linear time by using a packrat parser, as described above.

Parsers for languages expressed as a CFG, such as LR parsers, require a separate tokenization step to be done first, which breaks up the input based on the location of spaces, punctuation, etc. The tokenization is necessary because of the way these parsers use lookahead to parse CFGs that meet certain requirements in linear time. PEGs do not require tokenization to be a separate step, and tokenization rules can be written in the same way as any other grammar rule.

Many CFGs contain ambiguities, even when they're intended to describe unambiguous languages. The "dangling else" problem in C, C++, and Java is one example. These problems are often resolved by applying a rule outside of the grammar. In a PEG, these ambiguities never arise, because of prioritization.

Read more about this topic:  Parsing Expression Grammar

Famous quotes containing the word advantages:

    To say that a man is your Friend, means commonly no more than this, that he is not your enemy. Most contemplate only what would be the accidental and trifling advantages of Friendship, as that the Friend can assist in time of need by his substance, or his influence, or his counsel.... Even the utmost goodwill and harmony and practical kindness are not sufficient for Friendship, for Friends do not live in harmony merely, as some say, but in melody.
    Henry David Thoreau (1817–1862)

    If we help an educated man’s daughter to go to Cambridge are we not forcing her to think not about education but about war?—not how she can learn, but how she can fight in order that she might win the same advantages as her brothers?
    Virginia Woolf (1882–1941)

    The advantages found in history seem to be of three kinds, as it amuses the fancy, as it improves the understanding, and as it strengthens virtue.
    David Hume (1711–1776)