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);