How to make a ⇒ (conditional, logical connective)?

I am trying to evaluate this string:

var proposicion = "(true&&false)⇒!true";
console.log(eval(proposicion));

But it doesn't work because the character "⇒" is an unrecognized logical connective.

I have this function that returns the truth value between two values according to the rules of the connective "⇒".

function Condicional(v1,v2){
    return (!v1)||v2;               //fórmula de la condicional
}

And I can apply it for the string in question like this:

var proposicion = "(true&&false)⇒!true";
var pars = proposicion.split("⇒")
var result = Condicional(eval(pars[0]),eval(pars[1]))
console.log(result)

And it works, but how can I make it work for any other kind of Proposition? for example:

var proposicion2 = "((true⇒false)&&false)⇒false===true||!false" 

O any other?

 1
Author: Roberto Sepúlveda Bravo, 2016-06-02

1 answers

If instead of using ⇒ you use the function Condicional() when you arm the string you evaluate

function Condicional(v1,v2){
    return (!v1)||v2;              
}


var proposicion = "Condicional((true&&false),!true)";

var result1 = eval(proposicion);

alert("Condicion1: " + result1);



var proposicion2 = "Condicional(((Condicional(true,false))&&false), false===true||!false)";

var result2 = eval(proposicion2);

alert("Condicion2: " + result2);

Otherwise I can evaluate libraries that allow parsing expressions, such as being

Nerdamer

You will see that you can define custom operations, analyze the documentation the title "EXTENDING the CORE", you could see to define uan expression with the ⇒ operator (although you have to see if it takes that character)

 1
Author: Leandro Tuttini, 2016-06-02 21:46:14