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_operator extends PCFx {
public PCFx_operator() {
}
/**
* eval
*
* @param startAt Node
* @return Node
* @throws Exception
* @todo Implémenter cette méthode abstrasy.PCFx
*/
public Node eval(Node startAt) throws Exception {
/**
* vérification élémentaire de la syntaxe
*/
startAt.isGoodArgsCnt(2);
Node snode = startAt.getSubNode(1, Node.TYPE_STRING | Node.TYPE_QPCODE | Node.TYPE_PCODE);
long qt=snode.getQType();
if (qt==Node.TYPE_QSTRING) {
int pcode = PCoder.getCode(snode.getString());
if (pcode == PCoder.PC_ERR)
throw new InterpreterException(StdErrors.extend(StdErrors.Syntax_error, "invalid pcode \'" + snode.getString() + "\'"));
return Node.createPCode(pcode);
}
else if (qt==Node.TYPE_PCODE)
return Node.createClone(snode);
else if (qt==Node.TYPE_QPCODE)
return Node.createClone(snode).letQuoted(false);
else
throw new InterpreterException(StdErrors.Argument_type_mismatch);
}
}