0%

Syntax Highlighting in Parsing Expression Grammar

What is Parsing Expression Grammar?

Parsing Expression Grammar(PEG) describes a formal languages as a set of rules for recognizing strings in the language.

PEG is somewhat similar to Context Free Grammar(CFG), but the difference is that PEG follows “first match” rule, while CFG is ambiguous.

PEG has a linear-time complexity.

Definition of PEG Parser

Syntax

Somewhat similar to regular expression

  • Sequence e1 e2
  • Choice e1 / e2
  • Zero-or-more e*
  • One-or-more e+
  • Optional e?
  • And-predicate &e
  • Not-predicate !e

How to implement curly-brace blocks like C++ and Java?

How to implement indentation blocks like Python?