Arithmetic evaluation: Difference between revisions

Added zkl
(Updated D entry)
(Added zkl)
Line 4,174:
1.000000e+01,
-5.263158e-02></pre>
 
=={{header|zkl}}==
In zkl, the compiler stack is part of the language and is written in zkl so ...
<lang zkl>Compiler.Parser.parseText("(1+3)*7").dump();
Compiler.Parser.parseText("1+3*7").dump();</lang>
The ASTs look like
{{out}}
<pre>
class RootClass# Input source: "<text>"
Attributes: static createReturnsSelf
...
{ Block(Class) <Line 1>
Exp(
(,1,+,3,),*,7
)
}
 
class RootClass# Input source: "<text>"
...
{ Block(Class) <Line 1>
Exp(
1,+,3,*,7
)
}
</pre>
Evaluating them is just moving up the stack:
<lang zkl>Compiler.Compiler.compileText("(1+3)*7").__constructor(); vm.regX;
Compiler.Compiler.compileText("1+3*7").__constructor(); vm.regX;</lang>
{{out}}
<pre>
28
22
</pre>
Anonymous user