Package abstrasy.pcfx

Source Code of abstrasy.pcfx.PCFx_range

package abstrasy.pcfx;

import abstrasy.Node;
import abstrasy.PCoder;

import abstrasy.interpreter.InterpreterException;
import abstrasy.interpreter.StdErrors;

/**
* Abstrasy Interpreter
*
* Copyright : Copyright (c) 2006-2012, Luc Bruninx.
*
* Concédée sous licence EUPL, version 1.1 uniquement (la «Licence»).
*
* Vous ne pouvez utiliser la présente oeuvre que conformément à la Licence.
* Vous pouvez obtenir une copie de la Licence à l’adresse suivante:
*
*   http://www.osor.eu/eupl
*
* Sauf obligation légale ou contractuelle écrite, le logiciel distribué sous
* la Licence est distribué "en l’état", SANS GARANTIES OU CONDITIONS QUELLES
* QU’ELLES SOIENT, expresses ou implicites.
*
* Consultez la Licence pour les autorisations et les restrictions
* linguistiques spécifiques relevant de la Licence.
*
*
* @author Luc Bruninx
* @version 1.0
*/

public class PCFx_range extends PCFx {

    public PCFx_range() {
    }

    /**
     * eval
     *
     * @param startAt Node
     * @return Node
     * @throws Exception
     * @todo Implémenter cette méthode abstrasy.PCFx
     */
    public Node eval(Node startAt) throws Exception {
        /**
         * forme: (range n0 to nN)         -> [n0 n1 n2 ... nN]
         *        (range n0 to nN by stp)  -> [n0 (n0+stp) (n0+2stp) ... nN]
         */
        startAt.requirePCode(2, PCoder.PC_TO);
        double n0 = startAt.getSubNode(1,Node.TYPE_NUMBER).getNumber();
        double nN = startAt.getSubNode(3,Node.TYPE_NUMBER).getNumber();
        double ic=1;
        if(startAt.size()>4){
            startAt.requirePCode(4,PCoder.PC_BY);
            ic = startAt.getSubNode(5,Node.TYPE_NUMBER).getNumber();
            if(ic<0){
                throw new InterpreterException(StdErrors.Invalid_parameter);
            }
        }
        startAt.isGoodArgsCnt(4,6);
        Node liste=Node.createCList();
        /**
         * de cette manière, l'arrondi ne perturbe pas la progression...
         */
        if(n0<nN){
            int nx=(int)Math.abs((nN-n0)/ic);
            for(int i=0;i<=nx;i++){
                liste.addElement(new Node(n0+(ic*i)));
            }
        }
        else{
            int nx=(int)Math.abs((n0-nN)/ic);
            for(int i=0;i<=nx;i++){
                liste.addElement(new Node(n0-(ic*i)));
            }
        }
        return liste;
    }

}
TOP

Related Classes of abstrasy.pcfx.PCFx_range

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.