It would be extremely hard to do, but not impossible in principle.
As Christian Lindig mentions, trees and dictionaries would be needed, and it is not possible to code those very efficiently in TeX. However, a naive implementation of dictionaries can be
\def\newdictionary#1{%
\expandafter\def\csname dict@#1\endcsname##1{%
\csname dict@#1@##1\endcsname}}
\def\putkeyvalue#1#2#3{%
\expandafter\def\csname dict@#1@#2\endcsname{#3}}
A better (more memory efficient) implementation can be found as property lists in the expl3
bundle. For trees, I guess that the easiest is to have each node represented as one control sequence containing the list of its children, and one containing the material.
It may be easier to run the programs without compiling them, though. I know that pgf
has some support for object-oriented programming.
On a side note, I should mention that I once wrote in TeX a parser for integer expressions (essentially the same syntax as \numexpr
), where the user could define new functions, and it is rather tricky to get right.