/* Super-simplified calculator to compare old/new agent scripts. */ /* the old way */ init_calc_old = [ "\n", "calc_old", [] ]; calc_old = [ "read_prefix", [[], 0], "expr_old", [ "script", [ "declare", "a" ], [ "setparas", ["a"] ], [ "later", "writeln('=',%%);", "a" ] ] ]; expr_old = [ "pivot", "+", [ "expr_old", "expr_old" ], [ "ignore", ["bras"] ], [ "script", [ "declare", "a", "b" ], [ "setparas", ["a"], ["b"] ], [ "execute", "%% is %% + %%;", "v_paras[1]", "a", "b" ] ], [ "fail", "term_old" ] ]; term_old = [ "read_all", [["0","9"]], [ "script", [ "execute", "%% = $$;", "v_paras[1]", "v_string" ] ] ]; /* the new way - so much simpler! */ init_calc = [ "\n", "calc", [] ]; calc = [ "read_prefix", [[], 0], "expr", [ "action", [ "later", "writeln('=',$p1);" ] ] ]; expr = [ "pivot", "+", [ "expr", "expr" ], [ "ignore", ["bras"] ], [ "action", [ "now", "$v is $p1 + $p2;" ] ], [ "fail", "term" ] ]; term = [ "read_all", [["0","9"]], [ "action", [ "now", "$v = $i;" ] ] ]; installAOP("%calc_old","init_calc_old"); installAOP("%calc","init_calc");