Results 1 to 4 of 4

Thread: well formed parentheses to .dot file

  1. #1
    Join Date
    Apr 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Question well formed parentheses to .dot file

    Hi all,

    I want to generate a .dot file (to graphwiz) from well formed paretheses, but haven't figured yet how can I convert them.
    example:
    Qt Code:
    1. 1 2 3 4 5 6
    2. ( ( ) ( ) )
    3. 1 1 0 1 0 0
    4.  
    5. 1
    6. / \
    7. 2 *7
    8. / \
    9. *3 4
    10. / \
    11. *5 *6
    To copy to clipboard, switch view to plain text mode 
    So the '('s mean 1s and they are nodes. ')' mean 0s and they are leaves. The order is preorder, if i am not wrong.
    My question is, how create from 1100100 to 1--2, 2--*3, 2--4, 4--*5, 4--*6, 1--*7.
    I see the left connections but not the right ones. Left (i,i+1), if i==1.

  2. #2
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: well formed parentheses to .dot file

    I predict that the answer will involve recursion.

    But I don't really understand your example. Your tree contains 4 leaves, but line 3 contains only 3 zeros.

  3. #3
    Join Date
    Apr 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: well formed parentheses to .dot file

    Sorry, I forgot to mention, the well formed parentheses form doesn't contain the last leaf. In this example *7 is the additional leaf.
    and this is a typo: "My question is, how create from 1100100 to .." it is "...from 110100 to.."

  4. #4
    Join Date
    Apr 2011
    Posts
    124
    Thanks
    1
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows Symbian S60

    Default Re: well formed parentheses to .dot file

    Well, let's see. For this simple case, when you see a "(" you create a node, link it to the prior node, and make it the new "prior" node. When you see a ")" you create a leaf node, link it to the "prior" node, but don't make it the new "prior" node.

    But I'm not sure that algorithm works for more complex cases.

Similar Threads

  1. Arabic text rendering; issues with parentheses
    By TropicalPenguin in forum Qt Programming
    Replies: 4
    Last Post: 10th September 2013, 09:53
  2. Replies: 3
    Last Post: 1st November 2010, 16:33
  3. Replies: 3
    Last Post: 28th March 2009, 15:37
  4. Object::connect: Parentheses expected, slot...
    By bnilsson in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2008, 15:02
  5. Replies: 3
    Last Post: 25th May 2007, 07:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.