From 65a6265cf6d05750475289fc00e3018157244fcf Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 27 Jul 2017 16:52:16 -0700 Subject: [PATCH] Fix function argument order. --- src/org/nwapw/abacus/tree/FunctionNode.java | 12 ++++++++++-- src/org/nwapw/abacus/tree/TreeBuilder.java | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/org/nwapw/abacus/tree/FunctionNode.java b/src/org/nwapw/abacus/tree/FunctionNode.java index f8dc8c8..6fbd626 100644 --- a/src/org/nwapw/abacus/tree/FunctionNode.java +++ b/src/org/nwapw/abacus/tree/FunctionNode.java @@ -39,13 +39,21 @@ public class FunctionNode extends TreeNode { } /** - * Adds a child to this node. + * Adds a child to the end of this node's child list. * @param node the child to add. */ - public void addChild(TreeNode node){ + public void appendChild(TreeNode node){ children.add(node); } + /** + * Adds a new child to the beginning of this node's child list. + * @param node the node to add. + */ + public void prependChild(TreeNode node) { + children.add(0, node); + } + @Override public T reduce(Reducer reducer) { Object[] reducedChildren = new Object[children.size()]; diff --git a/src/org/nwapw/abacus/tree/TreeBuilder.java b/src/org/nwapw/abacus/tree/TreeBuilder.java index f5b3a07..4eb9741 100644 --- a/src/org/nwapw/abacus/tree/TreeBuilder.java +++ b/src/org/nwapw/abacus/tree/TreeBuilder.java @@ -155,7 +155,7 @@ public class TreeBuilder { while(!matches.isEmpty() && matches.get(0).getType() != TokenType.INTERNAL_FUNCTION_END){ TreeNode argument = fromStringRecursive(source, matches); if(argument == null) return null; - node.addChild(argument); + node.prependChild(argument); } if(matches.isEmpty()) return null; matches.remove(0);