Thread: draw tree graph of yacc parsing

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    69

    draw tree graph of yacc parsing

    I'm trying to display a tree graph of my lex / yacc / bison parsing, but really have no idea where to start. This is my first time using lex / yacc, and all the generated files (like calc.yacc_tab.c) are filled with so many #defines and #ifndefs that I don't know where to begin.

    The parsing is done and working, and now I just need to somehow display the pathing it takes while tracing through the parsing process. Can anybody give me a starting point for this? I assume recursion is used throughout the process (since it's supposed to be a recursive descent parser), but I don't see where the recursion happens, or where the functions are called from. I'll link the rar file of all the code, and hopefully someone can help!

    http://www.talz13.com/downloads/other/project.rar

    I'd really like to be able to draw something like the samples on this page, but that is all about ruby, and I don't know how the inner workings of the yacc process go.

    TIA,
    talz13

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    69
    Does anybody know how to turn out a kind of graph like this from a yacc parsing? Not from the base grammar, but from the path that the parsing follows?
    Code:
              12           
         .----' `----.     
        20          15     
      .-' `-.     .-' `-.  
     29    23    17    22  
    /  \  /  \  /          
    35 40 26 51 19

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I assume recursion is used throughout the process (since it's supposed to be a recursive descent parser)
    So pick a point in your parse code which you think is recursively called, and put a breakpoint there in your debugger.
    Then see if it is called recursively.

    Unless you call back into the yacc parse function from your yacc rules, then the answer is probably no recursion is used.

    My guess is you need to track the recursion via your yacc input files. Say for example when you see an opening brace, you increment a count, and when you see a closing brace, you decrement the count.

    I was also ignoring you because I've no way to decode your compression format.
    If you're going to just dump your entire project for someone else to sort out (not recommended), at least pick a format everyone should be able to decode.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Tree Search
    By C++Newbie in forum C++ Programming
    Replies: 7
    Last Post: 04-05-2011, 01:17 AM
  2. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM