/*
* 2016 Maciej Wiecierzewski
*/
/**
* @constructor
* @classdesc Contains data of particular type of operator
* @param {type} symbol Operator's character in the expression's string
* @param {type} precedence
* @param {type} arity
* @param {type} placement
* @param {type} associativity
* @param {type} probability
* @returns {Operator}
*/
function Operator(symbol, precedence, arity, placement, associativity, probability)
{
this.symbol = symbol;
this.precedence = parseInt(precedence);
this.associativity = associativity;
this.arity = parseInt(arity);
this.placement = placement;
this.probability = probability;
}
/** Generates description of the operator */
Operator.prototype.describe = function()
{
var str = "It's ";
if(this.arity === 0)
{
str += "a nullary operator (operand).";
return str;
}
else if(this.arity === 1)
{
str += "a " + this.placement + " unary operator ";
}
else if(this.arity === 2)
{
if(this.placement === "infix")
str += "a " + this.associativity + "-associative ";
str += this.placement + " binary operator ";
}
str += "with precedence equal to "+this.precedence+".";
return str;
}