Checking balanced TeX symbols, an algorithm in different languages