DEV Community

Ammar-Baig19
Ammar-Baig19

Posted on

What is a Parser?

A parser is a piece of software that, in computer science, uses a formal grammar to evaluate the structure of an input text (often code). A parser generates a parse tree, which describes the syntactic structure of the input, from a stream of tokens as the input.

Types of Parsers

There are two main types of parsers:

Top-down parsers

Starting with the start symbol of the grammar, a top-down parser applies grammatical rules to construct the input string. Because they recursively descend from the root to the leaves of the parse tree, these parsers are also known as recursive descent parsers. LL(1) parsers, which can handle both left-recursive and non-left-recursive grammars, and LL(k) parsers, which can handle ambiguous grammars, are examples of top-down parsers.

Bottom-up parsers

Starting with the input string, a bottom-up parser uses grammar rules to create the start symbol for the grammar. As they shift input tokens onto a stack and reduce them to grammar rules until the start symbol is formed, these parsers are also known as shift-reduction parsers. The LR(0), SLR(1), LALR(1), and LR(1) parsers are examples of bottom-up parsers that can handle left-recursive grammars.

Apache-Age:(https://age.apache.org/)
GitHub:-https://github.com/apache/age

Top comments (0)