In this article we will study the concept and uses of Parse Tree in Compiler Design. First, let us check out two terms :
- Parse : It means to resolve (a sentence) into its component parts and describe their syntactic roles or simply it is an act of parsing a string or a text.
- Tree : A tree may be a widely used abstract data type that simulates a hierarchical tree structure, with a root value and sub-trees of youngsters with a parent node, represented as a group of linked nodes.
Parse Tree :
- Parse tree is the hierarchical representation of terminals or non-terminals.
- These symbols (terminals or non-terminals) represent the derivation of the grammar to yield input strings.
- In parsing, the string springs using the beginning symbol.
- The starting symbol of the grammar must be used as the root of the Parse Tree.
- Leaves of parse tree represent terminals.
- Each interior node represents productions of grammar.
Rules to Draw a Parse Tree :
- All leaf nodes need to be terminals.
- All interior nodes need to be non-terminals.
- In-order traversal gives original input string.
Let us take an example of a Grammar (Production Rules).
S -> sAB A -> a B -> b
The input string is “sab”, then the Parse Tree is :
S -> AB A -> c/aA B -> d/bB
The input string is “acbd”, then the Parse Tree is :
- It helps in making syntax analysis by reflecting the syntax of the input language.
- It uses an in-memory representation of the input with a structure that conforms to the grammar.
- The advantages of using parse trees rather than semantic actions: you’ll make multiple passes over the info without having to re-parse the input.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Incremental Compiler in Compiler Design
- Difference between Native compiler and Cross compiler
- Introduction to Syntax Analysis in Compiler Design
- Why FIRST and FOLLOW in Compiler Design?
- Runtime Environments in Compiler Design
- Syntax Directed Translation in Compiler Design
- Intermediate Code Generation in Compiler Design
- Peephole Optimization in Compiler Design
- Code Optimization in Compiler Design
- Introduction of Object Code in Compiler Design
- Introduction of Compiler Design
- Compiler Design | Syntax Directed Definition
- Error Handling in Compiler Design
- Compiler Design | Detection of a Loop in Three Address Code
- Labeling Algorithm in Compiler Design
- Transition diagram for Identifiers in Compiler Design
- Input Buffering in Compiler Design
- Bootstrapping in Compiler Design
- Loop Optimization in Compiler Design
- Types of Parsers in Compiler Design
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.