I am writing a java program which would act upon the input which would be in scheme kind
of language.
Something like
(+ (+ a b))
Say I now want to check the syntax like if there are 2 brackets which have been opened, there have to be 2 other closing brackets. I am not sure how to achieve this with a regex. Can you help me out
Regular expressions can’t pair parentheses to an arbitrary depth. Scheme syntax is not regular.
http://en.wikipedia.org/wiki/Regular_language#The_number_of_words_in_a_regular_language
You’re going to have to tokenize it and then walk over tokens counting paren depth and make sure the depth is zero at the end and never goes negative.
For a simple language that has parentheses spaces and identifiers made from repetitions of the letter ‘a’, you might do