The grammar can be written as:
S =
| '(', S, ')', S
;
I add some pseudocode for the parser. First the functions to access and manipulate the tokenstream.
IsEof: Bool // checks for end of token stream
Get: Token // gets next token
Peek: Token // peeks next token without removing it
Then the parser. S is recognized as an empty tokenstream, or a paren set followed by another S.
Parse_S
// If no tokens left, there is a match.
if (IsEof) return True // OK
// Expect at least one paren set, but possibly more
else return (Peek == '(') && (Parse_ParenSet) && (Parse_S)
The paren set is an S enclosed in parenthesis.
Parse_ParenSet
// Expect a paren set.
if (IsEof) return False // Error
// Expect an S enclosed in Parenthesis.
else return (Get == '(') && (Parse_S) && (Get == ')')
Now you should be able to continue the assignment.