last ! = SPECIALCHAR means left parentheses remain unmatched

if(last != SPECIALCHAR)

*pvalid = FALSE;