Langage Parser

Parser type comparison

  • How to create your onwn programming language (2011)

  • Top-down parsing is a parsing strategy where one first looks at the highest level of the parse tree and works down the parse tree by using the rewriting rules of a formal grammar. Top-down parsing can be viewed as an attempt to find left-most derivations of an input-stream by searching for parse-trees using a top-down expansion of the given formal grammar rules.

  • Recursive descent parser a recursive descent parser is a kind of top-down parser built from a set of mutually recursive procedures (or a non-recursive equivalent) where each such procedure implements one of the nonterminals of the grammar. Thus the structure of the resulting program closely mirrors that of the grammar it recognizes.

A predictive parser is a recursive descent parser that does not require backtracking.[2] Predictive parsing is possible only for the class of LL(k) grammars, which are the context-free grammars for which there exists some positive integer k that allows a recursive descent parser to decide which production to use by examining only the next k tokens of input.

  • Parsing Expression Grammar (PEG) PEGs cannot be ambiguous; if a string parses, it has exactly one valid parse tree. It is conjectured that there exist context-free languages that cannot be recognized by a PEG, but this is not yet proven.[1] 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.

PEG are recursive-descent parser with limited backtracking, written in a special language. Using the ”memoization” or ”packrat” technologydescribed in [2,3], it works in linear time. The parser does not require a separate ”lexer” to preprocessthe input, and the limited backtracking lifts the LL(1) restriction usually imposed by top-down parsers.These properties are useful in many applications. However, PEG is not well understood as a languagespecification tool. - FromEBNFtoPEG∗ - treetop

  • Parser combinator Parser combinators, like all recursive descent parsers, are not limited to the context-free grammars and thus do no global search for ambiguities in the LL(k) parsing Firstk and Followk sets. Thus, ambiguities are not known until run-time if and until the input triggers them. In such cases, the recursive descent parser may default (perhaps unknown to the grammar designer) to one of the possible ambiguous paths, resulting in semantic confusion (aliasing) in the use of the language.
    • [When to use a Parser Combinator? When to use a Parser Generator?][https://softwareengineering.stackexchange.com/questions/338665/when-to-use-a-parser-combinator-when-to-use-a-parser-generator/338888#338888)ruby
Written on July 11, 2020, Last update on July 11, 2020
lang parser ruby scala combinators