/*******************************************************************
Ast2Dot
1. How to define the data structure of a binary tree in C
2. How to visualize Abstract Syntax Tree operations
COMP9024
*******************************************************************/This project is designed to visualize Abstract Syntax Tree operations.
More details will be discussed in COMP9024/Graphs/Dot2Png.
1 How to download this project in CSE VLAB
Open a terminal (Applications -> Terminal Emulator)
$ git clone https://github.com/sheisc/COMP9024.git
$ cd COMP9024/Trees/Ast2Dot
Ast2Dot$
2 How to start Visual Studio Code to browse/edit/debug a project.
Ast2Dot$ code
Two configuration files (Ast2Dot/.vscode/launch.json and Ast2Dot/.vscode/tasks.json) have been preset.
In the window of Visual Studio Code, please click "File" and "Open Folder",
select the folder "COMP9024/Trees/Ast2Dot", then click the "Open" button.
click Terminal -> Run Build Task
Open src/main.c, and click to add a breakpoint (say, line 67).
Then, click Run -> Start Debugging
├── Makefile defining set of tasks to be executed (the input file of the 'make' command)
|
├── README.md introduction to this tutorial
|
├── src containing *.c and *.h
| |
| ├── error.c reporting an error
| ├── error.h
| ├── expr.c create a tree by parsing an arithmetic expression (e.g., "9000 + (6 * 4)") and evaluate its value
| ├── expr.h
| ├── lex.c lexical analysis for recognizing a token (i.e., a word), such as 9000, +, (, ...
| ├── lex.h
| ├── main.c main()
| └── tokens.txt containing the token kinds and names
|
└── .vscode containing configuration files for Visual Studio Code
|
├── launch.json specifying which program to debug and with which debugger,
| used when you click "Run -> Start Debugging"
|
└── tasks.json specifying which task to run (e.g., 'make' or 'make clean')
used when you click "Terminal -> Run Build Task" or "Terminal -> Run Task"Makefile is discussed in COMP9024/C/HowToMake.
In addition to utilizing VS Code, we can also compile and execute programs directly from the command line interface as follows.
Ast2Dot$ make
Ast2Dot$ ./main
Click on the window of 'feh' or use your mouse scroll wheel to view images.
Ast2Dot$ make view| EvalExpression("3000 + (1000 + 2000) * 2 + 6 * 4") |
|---|
![]() |
Ast2Dot$ make animation| EvalExpression("3000 + (1000 + 2000) * 2 + 6 * 4") |
|---|
![]() |

