Lexical Analysis - (Syntax analysis|Parsing|Parser)
Table of Contents
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
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
In the process, the syntax will be checked.
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)
2 - Articles Related
3 - Type
3.1 - LL
An LL(k) parser :
- is a top-down parser
- that parses from left to right,
- constructs a leftmost derivation of the input
- and looks ahead k tokens when selecting between the grammar rule alternatives)
The * means any number of lookahead tokens.
LL parsers can't handle left-recursive rules.
The LL grammars is easier to understand than LR grammars.
3.2 - LR
LR(k) means: Left to right, Rightmost derivation parser.
- a bottom-up parser
- that parses from left to right
- and constructs a rightmost derivation of the input.