0

Hi, I'm having a major problem with an algorithm for Java. I am building a program that recursively parses a simple programming language that follows obvious production grammars. My main issue is nesting. For instance, the pattern might be something like this:

   Create Jpanel1:{
         Create JButton1
         Create JPanel2:{
              Create JButton2
              Create JButton3
         }
         Create JTextField1
         Create JPanel3:{
             Create JPanel4:{
                  Create JButton4
             }
         }
   } 

By now you've probably got an idea of what I'm talking about. In order to add JButton1 to JPanel1 I have to teach JButton1 who it's parent is (JPanel1 of course). You'll also notice that JButton1 is a terminal node and that the recursion comes from the existence of these other JPanel nodes that then lead to some terminal node. In any case, every one of these guy's must know who it's immediate parent is so it can be added to it's parent with the GUI's add(element) method.

3
Contributors
2
Replies
43
Views
3 Years
Discussion Span
Last Post by iamthwee
0

That's not enough info for anyone to understand where or why you are having difficulty. How far have you got - is there any code or documented design yet? Have you got as far as pushing each non-terminal node onto a stack and popping it when you finish processing its children?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.