martas
martas

Reputation: 51

How to show abstract syntax tree of a grammar in bison?

I am writing a grammar for a simple Pascal compiler in bison and I would like to visualize the parse tree for my grammar which I specified in pascal.y. Is it possible to graphically show the syntax tree based on my pascal.y file?

Upvotes: 5

Views: 2073

Answers (2)

Yang Jk
Yang Jk

Reputation: 687

Base on BRPocock's answer in details.

  1. Generate .dot file by bison pascal.y --graph. Now you will get pascal.dot
  2. Make sure you have installed graphviz. Download page
  3. Generate png picture file by dot pascal.dot -T png -o pascal.png
  4. Now you will get pascal.png for a graphical rendering of the parser

Upvotes: 2

BRPocock
BRPocock

Reputation: 13934

Bison's --graph option produces a source file that you can render with dot from graphviz.

Upvotes: 2

Related Questions