Strictly speaking, parser is something that separates data into more easily understood chunks. More practically, a parser is the part of a compiler that goes through a program and cuts it into identifiable chunks before translation. Assuming that a parser is written reliably, if the parser cannot parse a program then the program contains syntax errors. Also, we can say that a parser is an algorithm or program to determine the syntactic structure of a sentence or string of symbols in some language. A parser normally takes as input a sequence of tokens output by a lexical analyser and the grammar that defines language under consideration. It may produce some kind of abstract syntax tree as output. One of the best known parser generators is yacc[INSERIR LINK].
The task of the parser to determine if and how the input can be derived from the start symbol within the rules of the formal grammar can be done in essentially two ways:
A parser can start with the input and attempt to rewrite it to the start symbol.
Intuitively, the parser attempts to locate the most basic elements, then the elements containing these, and so on.
- BC (bounded context) parsing
- Canonical LR parser
- CYK parser
- Earley parser
- GLR parser
- LALR parser
- LR parsers
- Precedence parsing
- SLR parser
Another term used for this type of parser is Shift-Reduce parsing.