All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cdc.applic.expressions.ast.visitors.AbstractConverter Maven / Gradle / Ivy

There is a newer version: 0.13.3
Show newest version
package cdc.applic.expressions.ast.visitors;

import cdc.applic.expressions.ast.AbstractBinaryNode;
import cdc.applic.expressions.ast.AbstractLeafNode;
import cdc.applic.expressions.ast.AbstractNaryNode;
import cdc.applic.expressions.ast.AbstractUnaryNode;
import cdc.applic.expressions.ast.Node;
import cdc.applic.expressions.ast.Visitor;

/**
 * Base class of converters.
 * 

* They can transform a node into another one. * * @author Damien Carbonne * */ public class AbstractConverter implements Visitor { @Override public Node visitLeaf(AbstractLeafNode node) { // By default return the node return node; } @Override public Node visitUnary(AbstractUnaryNode node) { return node.create(node.getAlpha().accept(this)); } @Override public Node visitBinary(AbstractBinaryNode node) { return node.create(node.getAlpha().accept(this), node.getBeta().accept(this)); } @Override public Node visitNary(AbstractNaryNode node) { final Node[] subs = node.getChildren().clone(); for (int index = 0; index < subs.length; index++) { subs[index] = subs[index].accept(this); } return node.create(subs); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy