Thread: parenthesis, "(", has a matching closing parenthesis, ")"

  1. #1
    Registered User
    Join Date
    Oct 2001

    parenthesis, "(", has a matching closing parenthesis, ")"

    Hi Everyone,

    I am trying to write a program that does Expression evaluation, the expression is can be a conjuction of expression or conjuction of expression and condition.

    for example:
    (((a+1) > 1) AND(a != 0))

    I want to make sure that i have a vaild statement so i want to make sure their are appropriate "(" and close ")" parenthesis. Please let me knwo if you know of a C# or C++ or C code that already does what i need to do.

    I also want a suggestion of how about doing this...:-)

    Thank You,
    Last edited by simly01; 11-07-2003 at 10:54 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    int num_paren = 0;

    You increment it everytime you see a '('
    You decrement it everytime you see a ')'

    If it's ever negative, you've got a problem
    If it's non-zero at the end, you've got a mis-match
    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.

  3. #3
    Registered User
    Join Date
    Oct 2001

    What would be the easy way to delimite by AND/OR

    Hi Everyone,

    The input got me going, now my question is how to i make it so it delimits by AND/OR. So before the delimiting the string will be like:
    ((((a+1) > 1) AND(a != 0))OR(x > y))

    after the delimiting it will be:

    Please give me your suggestion on how about doing it...

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Hannover, Germany
    In C# you can use the Split Method on strings. It will return an array of strings containing what you need. Such a simple logic might not be enough for your needs though, as your split method has to be sensitive to brackets...

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM