IIRC UserAgent is a free-form string without a strictly defined format. There are certain conventions like "program/9.89 (extensions)" which you may be able to parse but it's not guaranteed that it will work always and for each string.
That said, you could take the most common
UserAgents, try to find their commonalities and build a simple parser. It shouldn't be too difficult.
Or you could try to translate any of the gazillions JS/PHP/Python implementations out there, just a google search away