Summary
In computer science, a parsing expression grammar (PEG) is a type of analytic formal grammar, i.e. it describes a formal language in terms of a set of rules for recognizing strings in the language. The formalism was introduced by Bryan Ford in 2004 and is closely related to the family of top-down parsing languages introduced in the early 1970s. Syntactically, PEGs also look similar to context-free grammars (CFGs), but they have a different interpretation: the choice operator selects the first match in PEG, while it is ambiguous in CFG. This is closer to how string recognition tends to be done in practice, e.g. by a recursive descent parser. Unlike CFGs, PEGs cannot be ambiguous; a string has exactly one valid parse tree or none. It is conjectured that there exist context-free languages that cannot be recognized by a PEG, but this is not yet proven. PEGs are well-suited to parsing computer languages (and artificial human languages such as Lojban), but not natural languages where the performance of PEG algorithms is comparable to general CFG algorithms such as the Earley algorithm. Formally, a parsing expression grammar consists of: A finite set N of nonterminal symbols. A finite set Σ of terminal symbols that is disjoint from N. A finite set P of parsing rules. An expression eS termed the starting expression. Each parsing rule in P has the form A ← e, where A is a nonterminal symbol and e is a parsing expression. A parsing expression is a hierarchical expression similar to a regular expression, which is constructed in the following fashion: An atomic parsing expression consists of: any terminal symbol, any nonterminal symbol, or the empty string ε. Given any existing parsing expressions e, e1, and e2, a new parsing expression can be constructed using the following operators: Sequence: e1 e2 Ordered choice: e1 / e2 Zero-or-more: e* One-or-more: e+ Optional: e? And-predicate: &e Not-predicate: !e Group: (e) Operator priorities are as follows, based on Table 1 in: The fundamental difference between context-free grammars and parsing expression grammars is that the PEG's choice operator is ordered.
About this result
This page is automatically generated and may contain information that is not correct, complete, up-to-date, or relevant to your search query. The same applies to every other page on this website. Please make sure to verify the information with EPFL's official sources.