An Abstract Syntax Tree (AST) is a condensed form of a parse tree used as an intermediate representation in compiler design, where operators and keywords are moved to become internal nodes rather than leaves, and chains of single productions are collapsed to retain only the essential structural information of the programming language construct.
Abstract Syntax Trees in Compiler Design | GATE CS Concepts
Added:hello friends in this class we are going to talk about abstract syntax tree which is nothing but condensed form of parse tree welcome again and uh here we are you know talking about abstract syntax tree and the reason i'm discussing this over here is because this is a one of the application okay so this is uh one of the application of one of the application of syntax directed translation so you may ask that which construct like one of the one of the let's say practical construct was a declaration of variable uh postfix expression is one of the practical concept now this is also one of the practical concept that we want to create abstract the syntax tree okay and this syntax tree is one of the way uh one syntax tree is one of intermediate representation okay so that is also there it is one kind of intermediate uh code representation or intermediate you can say representation okay so that is also one of the very practical application of this this syntax directed translation okay so now uh this is a new term maybe a abstract syntax tree but they are it is uh our syntax tree what this is very closely related with our standard term that was what parse tree okay so there is a very subtle or let's say very trivial difference so let's read out the definition and then we'll talk about how to construct a b abstract syntax tree okay and abstract syntax tree is a condensed form of the part string so what we are doing we are we are just condensing it this parts tree and we are getting this syntax tree these are useful for representing the programming language construct in syntax tree these are the this is the key point operator and keywords do not appear as leads okay operator and keywords okay so operator and keywords do not appear as leave so that is one of the important point okay operators and keywords do not appear as leaves okay but rather associated as interior node or internal node that would have been parent of those leaves in the parse tree okay so what we are going to do we are going to move or shift okay we are going to move or shift operator or keyword which one operator or keyword where we'll move this one we move this one operator and keyword to their parent okay okay we will move this one to their parent node also simplification found all simplification found in syntax tree is that a chain of single production may be collapsed okay so this is another simplification that operator and keyword will become the parent and chain of single production so sometime we have seen that e derives t t derive f and f derived let's say i d finally okay so this is what this is nothing but this we call it as a chain of single production okay so chain of single production and what we can do we can simply collapse it in this section we will be uh okay we are okay so this is the definition so what exactly does it mean let me give you a very simple example and then we can go for this this functions uh suppose i give you a grammar expression grammar that we have seen earlier many times and see exp the the one with expr so that we have seen many times so e x p r derive let's say e x b r okay both are both smaller plus term and let me just one more time let's say e x b plus term and expire to turn and turn to let's say number number let's say 5 and 6 and 7. okay so now what we are going to do we are going to collapse this chain and we take this keyword this operator or keyword and shift it to the root so this will be shifting towards the root and this will become here uh 7 will be here 6 will be here and 5 will be here and this will be here so finally what it will look like is look like this plus 7 plus five and then this is six okay this we called it as a center straight okay so this is the syntax tree and this is what what is the meaning that we are more condensing it okay so we are only keeping the condensedness what we want the the the core part of it or the useful part of it rest is uh condensing when when we condense it only useful part remains and then rest is gone like if you keep on you know boiling the milk again and again so finally the thing that we left is the condensed milk okay and that tastes very good so only the useful part is there the rest is gone so this we call it as a condensate condensed form of uh parse tree okay so we are not interested in non-terminal and terminal we are not bothered about them we are only bothered about that what is your operator and what is your keyword okay that's all so that is your uh syntax tree and here in this uh there are three functions are there that we are going to use uh for syntax tree that make node which is an operator left and right okay so create an operator with level op and two fields containing pointer to the left pointer to the right so if i say make node a plus left and right like a tree structure then it will have a plus operator and then an address to the left and address to the right make leave contains an identifier node with a label id and the field containing entry a pointer to the symbol table okay what is the pointer pointer to the symbol table so if you say let's say a to the a and the name will be a and this will point to symbol table pointer to okay pointer to symbol table right so that is make leaf and another make leaf is a num and value so creates a number node with the label num and the field containing bell uh the value of the number so like i can create a five six seven i can create abc okay so there are make node with left and right pointer make leaf with the pointer that id value and pointer to the symbol table num and create a number node with label num and the field containing value okay so number or a field containing num creates a number node with the label label num and containing the value of the number so very simple functions are there and now we'll use this function and we'll create the syntax tree so what we'll see here is as next is a more description of it and then finally go for sdt okay so that's all for this session thank you you
Up Next

C++ Memory Management: Stack vs Heap Allocation Explained
@TheCherno
648.4K views•2017-12-10

BitTorrent Protocol Explained: Piece Selection & Peer Choking
@StevenGordonAU
481 views•2013-02-22

HTTP Requests Explained: GET, POST, PUT, DELETE
@codecademy
103.1K views•2021-10-07

Enigma Machine Mechanics: WWII Encryption Explained
@JaredOwen
13.2M views•2021-12-11
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Computer Science







































