Before passing a string to eval() I would like to make sure the syntax is correct and allow:
You could use token_get_all(), inspect each token, and abort at the first invalid token.