Syntactic Analysis
Learn how a parser parses code and generates an abstract syntax tree.
We'll cover the following...
Syntactic analysis
Syntactic analysis, also known as parsing, is the second stage in compiler construction. Its main goal is to convert the stream of tokens generated by the lexical analysis stage into a tree-like structure called an abstract syntax tree (AST) that represents the program’s structure.
Abstract syntax tree (AST)
An abstract syntax tree (AST) is a widely adopted choice for representing the syntactic structure of programming code during syntax analysis for several compelling reasons:
Hierarchical structure: An abstract syntax tree (AST) naturally mirrors the hierarchical structure of programming languages. It captures relationships between constructs, such as expressions, statements, and declarations, in a tree-like format, making it an ideal representation for the nested and structured nature of code syntax.
Simplified representation: ASTs abstract away many of the syntactic details found in the original source code, such as parentheses, semicolons, and other punctuation marks. This simplification makes ...