TL;DR
Given: sequence of Token and Grammar
Where:
Token := tuple[name:string, value:string, parent:Token]
Grammar := Table[system.string, proc(x:Token):string]
Return: string of token values passed through the grammar
When implementing my translator, I came to the conclusion that I need to perform some action depending on the token, I understand that it would be more correct to implement this functionality using conditional branching, but I am interested in a different approach, in which, having received the name of the token, I do some interaction with it.
The easiest way to implement this is Table[system.string, proc(x:Token):string]
However, I am not satisfied with the fact that I cannot generate it during compilation. Or I can, but I don’t know how.
Since I have a little experience with php, from which I know that I can work with *strings as functions *
function a(int $a){
return $a + 3;
}
echo "a"(1); // 4
Based on this, is there a way in Nim that would allow declaring a set of functions in advance to access them in this way?
agatzan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.