Results 1 to 5 of 5

Thread: Parse tree

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149

    Parse tree

    Im working on an assignment and was confused so I was looking for some help not just answers cause I need to understand (test).

    I have these rules:
    1. Expression -> Term | Expression Add_op Term
    2. Term -> Factor | Term Mult_op Factor
    3. Factor -> id | number | '-' Factor | '('Expression')'
    4. Add_op -> '+' | '-'
    5. Mult_op - > '*' | '/'

    I need to draw a parse tree for this:
    5-(3+4)*5

    Here is what I have (its not a perfect tree):
    Code:
                        -------------------E---------------------
                        |                    |                    |      
                  E   A   T                   T   A   T            E      A      T
                  
            (3+4)   -    5                   3   +   4           (3+4)      *     5
    Is anything wrong?

    Thanx
    Last edited by abcdefg; Feb 16th, 2004 at 06:09 PM.

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Yes, you didn't use code tags, so your ASCII art was not preserved. Sorry, can't examine it this way.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149
    it has code tags now, but isnt perfect. Im thinking the Expression on far left and right need to be broken down further, but Not sure how.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    So I assume your starting rule is E?

    To get this right, you need to be a parser yourself. You need to take a look at the rule and see how it can apply. I've attached the full parse tree. It's slightly shortened at the end because I ran out of space.
    Attached Images Attached Images  
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Posts
    149

    parse tree

    Thanx for the reply it helps alot just need to walk through it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width