This commit is contained in:
Peter Harpending
2026-06-03 19:28:55 -07:00
parent 4e54bebeba
commit e180dc955d
2 changed files with 34 additions and 20 deletions
+29 -18
View File
@@ -68,27 +68,38 @@ parse(Signal) ->
% think)?
F0 = Signal,
F1 = f2f_parens(F0),
%F2 = f2f_op("=>", F1),
Result = F1,
F2 = f2f_op("=>", F1),
F3 = f2f_op("*", F2),
Result = F2,
Result.
%f2f_op(OpStr, Fst) ->
% case f2f_op(OpStr, [], none, Fst) of
% % never saw it, no change
% ident -> Fst;
%
%
%% never saw the op
%f2f_op(_, _, none, []) ->
% ident;
%% see op
%f2f_op(OpStr, LhsStk, none, [OpTk = #tk{str = OpStr} | Rest]) ->
% Lhf = lists:reverse(LhsStk),
% Rhf = f2f_op(OpStr, Rest),
% Lht = #ns{meta = none, kids = Lhf},
% Rht = #ns{meta = none, kids = Rhf},
% Result =
f2f_op(OpStr, Fst) ->
f2f_op(OpStr, [], Fst).
% never saw the op
f2f_op(_opstr, Stk, []) ->
lists:reverse(Stk);
% see op
f2f_op(OpStr, LhsStk, [#tk{str = OpStr} = OpTk | Rest]) ->
Lhf = lists:reverse(LhsStk),
Rhf = f2f_op(OpStr, Rest),
Lht = #ns{meta = none, kids = Lhf},
Rht = #ns{meta = none, kids = Rhf},
ResultT = #ns{meta = {op, OpTk},
kids = [Lht, Rht]},
ResultF = [ResultT],
ResultF;
% see stem, descend
f2f_op(OpStr, LhsStk, [Ns = #ns{kids = NsKids} | Rest]) ->
NewNsKids = f2f_op(OpStr, NsKids),
NewNs = Ns#ns{kids = NewNsKids},
NewStk = [NewNs | LhsStk],
f2f_op(OpStr, NewStk, Rest);
% see leaf, just add
f2f_op(OpStr, Stk, [L | Rest]) ->
f2f_op(OpStr, [L | Stk], Rest).
-spec f2f_parens(Forest) -> NewForest when