|
From: Dipl. I. S. G. B. <se...@us...> - 2017-02-14 16:38:45
|
>> The idea I try to follow (and explain the whole time), is to recognize the assignment and use the lvalue as variable name in assignment case.
>
> When compiling an expression like {sin(0)=42}, then at the time the "=" is
> seen, the bytecode for calling [tcl::mathfunc::sin 0] is already produced.
Yep, because currently it does not do look ahead, before it compiles the
sub-expression "sin(0)".
Because currently if it find '(', in ParseExpr lexer try to parse
function (lexeme = FUNCTION).
Because currently after token MARK_RIGTH it will be to function
"::tcl::mathfunc::sin".
And pair other "because". But exactly that I suggest to change.
I'll try to explain it on `expr {a($i + $k) = 42}`
The algorithm would be:
- tokenize expression (will take place already, but possibly to be
modified in ParseExpr by ParseLexeme to FUNCTION):
- anyway, you will get tokens similar to "a" "(" "sub-expr1" ")" "="
"42"
- in TclCompileExpr (or CompileExprTree, or even directly in
ParseLexeme) look ahead for assignment token (currently "=").
- if we don't have it - do the current compilation (unchanged as so
far);
- if we have it - a(expr1) is an array variable (and not
"tcl::mathfunc::a"), so compile assignment with twin varname;
You can do it relative easy somewhere in scope of `if (nodePtr->mark ==
MARK_RIGHT) ...`, but of course the lexer can do it much better.
I've currently no time to try it, but possibly soon...
The problem may occur by the direct execution (without compiling). I
mean not that it'll be impossible, but probably slower. Just how often
it'll be executed directly?
JFYI.
Regards,
sebres. |