Abstract Syntax Tree in Compiler Design

Abstract Syntax Tree in Compiler Design
Slide Note
Embed
Share

The Abstract Syntax Tree (AST) is a fundamental data structure in compiler design that represents the syntactic structure of source code in a programming language. The AST is constructed bottom-up, with each node representing a construct from the source code. This abstract representation facilitates various operations and transformations on the code during compilation processes.

  • Compiler Design
  • Syntax Tree
  • Programming Language
  • Data Structure

Uploaded on Mar 04, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. COMP 442 / 6421 Compiler Design A b s t r a c t S y n t a x Tr e e ( A S T ) paquet@cse.concordia.ca hamed.jafarpour@concordia.ca vmarhwal97@gmail.com Instructor: TAs: Dr.JoeyPaquet Hamed Jafarpour Vashisht Marhwal 1

  2. Outline Abstract Syntax Tree (AST) AST Data Structure DOT files Gephi Platform 2

  3. Abstract Syntax Tree (AST) AST is a tree representation of the abstract syntactic structure of source code written in a programming language. Each node of the tree denotes a construct occurring in the source code. The AST structure is constructed bottom-up. 3

  4. Abstract Syntax Tree (AST) An abstract syntax tree for the following code: while b 0 if a > b a := a b else b := b a return a 4

  5. AST Data Structure Each node needs connection to: Parent Parent: to migrate information upwards in the tree Link to parent Siblings Siblings: to iterate through (1) a list of operands or (2) members of a group, e.g. members of a class, or statements in a statement block. Link to right sibling (thus creating a linked list of siblings) Link to leftmost sibling (in case one needs to traverse the list as a sibling is being processed). Children Children: to generate/traverse the tree Link to leftmost child (who represents the head of the linked list of children, which are each other s siblings). 5

  6. Parent Connection for Each Node 6

  7. Siblings Siblings Connection for Each Node Siblings Siblings Link to right sibling (thus creating a linked list of siblings) (Blue Arrows) Link to leftmost sibling (in case one needs to traverse the list as a sibling is being processed). (Red Arrows)

  8. Children Children Connection for Each Node Children Children: to generate/traverse the tree Link to leftmost child (who represents the head of the linked list of children, which are each other s siblings).

  9. AST Data Structure Methods: makeNode(): A method that creates a node. x.makeSiblings(y): A method that inserts a new sibling node y in the list of siblings of node x. x.adpotChidren(y): A method that adopts node y and all its siblings under the parent x. makeFamily (Prnt, kid1, kid2, , kidn): generates a family with n children under a parent Prnt. In fact, with this function you can find sub-tree. 9

  10. DOT Files: DOT is a graph description language. DOT graphs are files with the filename extension gv or dot. DOT can be used to describe an undirected or directed graph 10

  11. DOT Files: Undirected graphs: graph graphName { a -- b -- c; b -- d; } Note: The graph name and the semicolons are optional 11

  12. DOT Files: Directed graphs: digraph graphName { a -> b -> c; b -> d; } 12

  13. DOT Files: Directed graphs: B -> {C D} is equivalent to B -> C B -> D Note: For mor information about DOT file, visit the bellow link: https://graphviz.org/doc/info/lang.html 13

  14. Gephi Platform Gephi is the leading visualization and exploration software for all kinds of graphs and networks. Gephi is open-source and free. Download Gephi Platform 14

  15. Gephi Platform Gephi is the leading visualization and exploration software for all kinds of graphs and networks. Gephi is open-source and free. Download Gephi Platform 15

  16. Gephi Platform digraph name { } A[label="program"] B[label="class list"] C[label="class: LINEAR"] D[label="class: QUADRATIC"] A->B B->C B->D 16

  17. Gephi Platform 17

  18. Gephi Platform 18

  19. Gephi Platform 19

  20. Gephi Platform ( a piece of a file) digraph name { 0[label="program"] 0->1 1[label="class list"] 1->2 2[label="class"] 2->3 3[label="InheritedUtility"] 2->4 4[label="inheritance list"] 2->5 5[label="var+func decl list"] 5->6 20

  21. Gephi Platform 21

  22. Gephi Platform 22

  23. Thanks! 23

More Related Content