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

This is a discussion on parenthesis, "(", has a matching closing parenthesis, ")" within the C# Programming forums, part of the General Programming Boards category; Hi Everyone, I am trying to write a program that does Expression evaluation, the expression is can be a conjuction ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    68

    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 09:54 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,663
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    68

    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:
    ((a+1)>1)
    (a!=0)
    (x>y)

    Please give me your suggestion on how about doing it...
    :-)

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    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...
    hth
    -nv

    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21