Created
April 21, 2010 19:17
-
-
Save natebenes/374279 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
logical function validExp(inputstring, length) | |
IMPLICIT NONE | |
character(len=500), intent(in) :: inputstring | |
integer, intent(in) :: length | |
integer:: i, counter = 0 | |
character(len=1) :: testCharacter | |
character(len=16), parameter :: allowed = "1234567890+-/$()" | |
validExp = .FALSE. | |
DO i = 1, length | |
testCharacter = inputstring(i:i) | |
if((i==1) .AND. (testCharacter /= "(")) exit | |
if(index(testCharacter, allowed) == 0) exit | |
! Hint: if at any point, there are more right parentheses | |
! than left parentheses, we have an issue. | |
if(testCharacter=="(") counter = counter + 1 | |
if(testCharacter==")") counter = counter - 1 | |
if((i == length) .AND. (counter == 0)) validExp = .TRUE. | |
END DO | |
END FUNCTION |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment