A Python PyQt GUI application for scanning and parsring TINY Language code (as defined in Compiler Construction: Principles and Practice) and displaying the syntax tree of the given code sample.
The instructions will assume that you're using a Linux distributions based on Debian due to to the dependency on Pygraphviz which fails when being built by Pip on Windows.
- Install the OS dependencies by running
apt-get install graphviz libgraphviz-dev python3-tk
. - Set up a Python virtual enviroment with Pip and install the Python dependencies by running
pip install -r requirements.txt
in the project root directory. - Run
python __main__.py
in the project root directory.
Given the following TINY Language sample:
read x;
if 0<x then
fact:=1;
repeat
fact:=fact*x;
x:=x-1
until x=0;
write fact
end
After pasting this code snippet in the text box and clicking on Parse, the following sequence of steps is executed:
- The source code is scanned to extract the tokens.
- The extracted tokens are passed to a recursive-descent predictive parser which generates the syntax tree using a tree data structure.
- With the help of the used graphing libraries, the syntax tree is then plotted.
The application is based on muhakh's implementation. A modified data structure is used for storing the syntax tree as well as using additional graphing libraries to provide a more precise and verbose visualization.