5

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?

martas
  • 51
  • 2

2 Answers2

3

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

BRPocock
  • 13,638
  • 3
  • 31
  • 50
1

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
Yang Jk
  • 577
  • 6
  • 9
  • Notwithstanding the upvotes for the answer you cite, which was never accepted, I don't think it actually answers the question, which requests a graphical representation of a syntax tree (for a parsed input), not of the parse automaton. Some parser generators can provide this (see, for example, the Antlr test harness) but it's not implemented by Bison. – rici Jan 06 '22 at 18:17
  • I use the Windows Version of the DOT-Tool in 64-Bit Mode from the listed Download Page/Link above. In my Environment (I use **MinGW** - in both 32-Bit, and 64-Bit Mode) I get with the necessary Tool's an other File, so the command `dot pascal.dot -T png -o pascal.png` ends up with `pascal.gv` instead `pascal.dot` File. This is just a Note to the Answer above (in helping for "searching" confusion - why the File pascal.dot can not be found). Thanks for reading. – Jens Jun 03 '23 at 18:18