Closed AllenDang closed 3 years ago
gval is designd for interpreting expressions. It's not fitting for Interpreting instructions.
You can solve that in two ways: Building a Wrapper around gval or by modifiyng your language into an expression.
1:
type Wrapper struct{
assignments []struct{variable string, expression Gval.Evaluable}
expression Gval.Evaluable
}
Filling the values by parsing each line and the var name seperatly.
2:
${
a: 1 + 2
b: a * 0.1
}
a + b
Write a prefix extension $
. This extension parses two expresions enviroment and expression. On Evaluation it evaluates first the enviroment and parses the resulting value to the expression. The enviroment part is basicly a json object, so this part canbe handled by default.
@generikvault Thanks for the tips. I will check them out.
I intend to create a new language to accept following expressions:
The program will eval it line-by-line, so the ideal result will be:
I'm trying to create a calculator notebook app which allows user to create new avarialbe and new functions.
I found gval.InfixEvalOperator maybe the right spot to look, but I'm stucked by getting the text value of a.
Here is the demo code
Any hint?