For taking X language and translating it to Y language you could use a compiler. The book Compilers: Principles, Techniques, and Tools by Alfred Aho and Jeffrey Ullman is where you'd want to start on this.
Using the lexical analysis part of the compiler, you could create a system where by as the tokens are made, you analyse them against a database. If the full length of the tokens match, call for that function. Otherwise continue with the other compiler steps.