Lexical Analysis - Parser (Syntax analysis|Linter)

> Code - (Programming|Computer) Language > Computer Language - (Compiler|Interpreter) - Language translator

1 - About

A parser takes a token stream (emitted by a lexical analyzer) as input and based on the rules declared in the grammar (which define the syntactic structure of the source) produces a parse tree data structure.

A parser is generally generated from the grammar. See Language - Compiler compilers or (lexer|parser) generators

A parser is the component of a compiler that deals with the recursively nested features such as expressions arithmetic, conditional, and so on). Example of recursive grammatical rule a = a + a

Parsing is done generally at the token level but can be done at the character level when lexer and parser are done in one step: See Scannerless parsing

Syntax analysis is also known as Sentence recognition

Additional step can be added to the parse phase in order to construct an Abstract Syntax Tree (AST) from the parse tree.

The term parsing comes from Latin pars (orationis), meaning part (of speech)

Advertising

3 - Usage

A syntax analyzer would check:

4 - Application

5 - Type

To construct the tree, we have many choices for selecting nodes, which can lead to the leaves to correspond to the input sequence seen so far.

method of construction:

  • LR parsing: a bottom up approach. The tree is build from the leaves.
  • LL parsing: a top down approach. The tree is build from the root.

5.1 - LL

5.2 - LR

6 - Example of parsing algorithm

Advertising

7 - Documentation / Reference