SlideShare a Scribd company logo
1 of 5
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
 <meta http-equiv="content-type" content="text/html; charset=windows-1250">
 <meta name="generator" content="PSPad editor, www.pspad.com">
 <title></title>
 </head>
 <body>
 <script>
  //****************Sugar*********************
  Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
  };

  Function.method('inherits', function (parent) {
  var d = {}, p = (this.prototype = new parent());
  this.method('uber', function uber(name) {
     if (!(name in d)) {
        d[name] = 0;
     }
     var f, r, t = d[name], v = parent.prototype;
     if (t) {
        while (t) {
            v = v.constructor.prototype;
            t -= 1;
        }
        f = v[name];
     } else {
        f = p[name];
        if (f == this[name]) {
            f = v[name];
        }
     }
     d[name] += 1;
     r = f.apply(this, Array.prototype.slice.apply(arguments, [1]));
     d[name] -= 1;
     return r;
  });
  return this;
  });


  Function.method('swiss', function (parent) {
     for (var i = 1; i < arguments.length; i += 1) {
        var name = arguments[i];
        this.prototype[name] = parent.prototype[name];
     }
     return this;
  });
  //******************************************
  //*************LogicEquation object*********
//var resolveKeys = new Array(Equation, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T,
W, X, Y, Z);

  function LogicEquation()
  {
    this.resolveKeys = new Array("Equation", "A", "B", "C", "D", "E", "F",
                      "G", "H", "I", "J", "K", "L", "M", "N",
                      "O", "P", "Q", "R", "S", "T", "W", "X",
                      "Y", "Z");
    this.equationProducts = new ListOfLogicProducts();
    this.strEquation;
  }

  LogicEquation.prototype.cons = function(value){
    this.strEquation = value;
  }

  LogicEquation.prototype.getEquation = function(){
    return this.strEquation;
  }

  LogicEquation.method("setEquation", function(value){
   this.strEquation = value;
  });

  LogicEquation.method("getEquationProducts", function(){
   return this.equationProducts.strLogicProducts;
  });

  LogicEquation.method("tokenizeEquation", function(){
   this.equationProducts.cons(this.strEquation.split("+"));
  });

  LogicEquation.method("resolveEquationKeys", function(args){
   for(var ctr=1;ctr<args.length;ctr++)
   {
     var eqKey = args[ctr];
     var tmpRegEx = new RegExp(this.resolveKeys[ctr], "g");
     this.strEquation = this.strEquation.replace(tmpRegEx, eqKey);
   }
  });

  LogicEquation.method("resolveEquation", function(){
    return this.equationProducts.resolve();
  });
  //***************************************************
  //***************ListOfEquationProduct***************
  function ListOfLogicProducts()
  {
    this.logicProducts = [];
    this.strLogicProducts;
  }
ListOfLogicProducts.prototype.cons = function(value){
  for(var ctr=0;ctr<value.length;ctr++)
  {
    this.logicProducts[ctr] = new LogicProduct();
    this.logicProducts[ctr].cons(value[ctr]);
  }
  this.strLogicProducts = value;
}

ListOfLogicProducts.method("resolve", function(){
 var result = false;

 for(var ctr=0;ctr<this.logicProducts.length;ctr++)
 {
   var tmpResult = this.logicProducts[ctr].resolve();

     if(result||tmpResult == true) result = true;
     else result = false;
 }

  return result;
});
//**************************************************
//****************LogicProduct**********************
function LogicProduct()
{
  this.productElements = new ListOfProductElements()//[];
  this.strProductElements;
}

LogicProduct.method("cons", function(value){
 this.productElements.cons(value.replace(/^[|]$/g,""));
 this.strProductElements = value;
});

LogicProduct.prototype.resolve = function(){
  return this.productElements.resolve();
}
//**************************************************
//***************ListOfProductElements**************
function ListOfProductElements()
{
  this.listOfElements;
  this.strListOfElements;
}

ListOfProductElements.prototype.cons = function(value){
  this.listOfElements = value.split("*");
  this.strListOfElements = value;
}
ListOfProductElements.method("resolve", function(){
  var result = true;

    for(var ctr=0;ctr<this.listOfElements.length;ctr++)
    {
      var tmpResult = this.listOfElements[ctr];

      if(/^!/.test(tmpResult))
      {
        var temp = tmpResult.replace(/^!/g, "");
        if(temp == "true") tmpResult = "false";
        else tmpResult = "true";
      }

      if(tmpResult == "true")
      {
        if(result == true) {result = true;}
        else {result = false;}
      }
      else {result = false;}

  }
  return result;
});
//**************************************************
//***************the program************************

function equationAnalyzer(args)
{
  try
  {
    var logEq = new LogicEquation();

     logEq.cons(args[0]);
     //logEq.setEquation("[!true*!false*true]+[true*true*!false]"); //"[A*B*!C]+[A*B*C]"

     //alert(logEq.getEquation());
     //alert(logEq.getEquationProducts());

     logEq.resolveEquationKeys(args);
     logEq.tokenizeEquation();

     alert(logEq.resolveEquation());
    }
    catch(e)
    {
      alert(e.description);
    }
}

function main()
{
var args=new Array()

   args[0]='[!A*!B*C*D*E*F*G*H]+[A*B*!C*D*E*F*G*H]+[A*B*!C*D*E*F*G*H]';
   args[1]=true; //A = true
   args[2]=true; //B = false
   args[3]=false; //C = false
   args[4]=true; //D = true
   args[5]=true; //E = true
   args[6]=true; //F = true
   args[7]=true; //G = true
   args[8]=false; //H = true

    equationAnalyzer(args);
  }
 </script>
 <button TYPE=BUTTON onclick="main()">EvalueLogicEquation
 </button>
 </body>
</html>

More Related Content

What's hot

とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語
Kiyotaka Oku
 

What's hot (20)

Base de-datos
Base de-datosBase de-datos
Base de-datos
 
[Droid knights 2019] Tensorflow Lite 부터 ML Kit, Mobile GPU 활용 까지
[Droid knights 2019] Tensorflow Lite 부터 ML Kit, Mobile GPU 활용 까지[Droid knights 2019] Tensorflow Lite 부터 ML Kit, Mobile GPU 활용 까지
[Droid knights 2019] Tensorflow Lite 부터 ML Kit, Mobile GPU 활용 까지
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 
How to practice functional programming in react
How to practice functional programming in reactHow to practice functional programming in react
How to practice functional programming in react
 
Groovy collection api
Groovy collection apiGroovy collection api
Groovy collection api
 
The Ring programming language version 1.6 book - Part 82 of 189
The Ring programming language version 1.6 book - Part 82 of 189The Ring programming language version 1.6 book - Part 82 of 189
The Ring programming language version 1.6 book - Part 82 of 189
 
The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181The Ring programming language version 1.5.2 book - Part 76 of 181
The Ring programming language version 1.5.2 book - Part 76 of 181
 
TDC2016SP - Código funcional em Java: superando o hype
TDC2016SP - Código funcional em Java: superando o hypeTDC2016SP - Código funcional em Java: superando o hype
TDC2016SP - Código funcional em Java: superando o hype
 
Clojure functions midje
Clojure functions midjeClojure functions midje
Clojure functions midje
 
とある断片の超動的言語
とある断片の超動的言語とある断片の超動的言語
とある断片の超動的言語
 
Retrieving data from database using result set (1)
Retrieving data from database using result set (1)Retrieving data from database using result set (1)
Retrieving data from database using result set (1)
 
SparkSQLの構文解析
SparkSQLの構文解析SparkSQLの構文解析
SparkSQLの構文解析
 
Is java8 a true functional programming language
Is java8 a true functional programming languageIs java8 a true functional programming language
Is java8 a true functional programming language
 
Is java8a truefunctionallanguage
Is java8a truefunctionallanguageIs java8a truefunctionallanguage
Is java8a truefunctionallanguage
 
Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)Currying and Partial Function Application (PFA)
Currying and Partial Function Application (PFA)
 
Shipping Pseudocode to Production VarnaLab
Shipping Pseudocode to Production VarnaLabShipping Pseudocode to Production VarnaLab
Shipping Pseudocode to Production VarnaLab
 
Ramda, a functional JavaScript library
Ramda, a functional JavaScript libraryRamda, a functional JavaScript library
Ramda, a functional JavaScript library
 
Ramda lets write declarative js
Ramda   lets write declarative jsRamda   lets write declarative js
Ramda lets write declarative js
 
PathOfMostResistance
PathOfMostResistancePathOfMostResistance
PathOfMostResistance
 
The Ring programming language version 1.9 book - Part 92 of 210
The Ring programming language version 1.9 book - Part 92 of 210The Ring programming language version 1.9 book - Part 92 of 210
The Ring programming language version 1.9 book - Part 92 of 210
 

Viewers also liked (9)

Object Oriented Approach Within Siebel Boundaries
Object Oriented Approach Within Siebel BoundariesObject Oriented Approach Within Siebel Boundaries
Object Oriented Approach Within Siebel Boundaries
 
Common Redirection Mechanism
Common Redirection MechanismCommon Redirection Mechanism
Common Redirection Mechanism
 
It Project And Agile
It Project And AgileIt Project And Agile
It Project And Agile
 
Guidance 4 Days Configuration
Guidance   4 Days   ConfigurationGuidance   4 Days   Configuration
Guidance 4 Days Configuration
 
Design Results
Design ResultsDesign Results
Design Results
 
Siebel client side integrator (SCSI)
Siebel client side integrator (SCSI)Siebel client side integrator (SCSI)
Siebel client side integrator (SCSI)
 
Integration Within Several Projects
Integration Within Several ProjectsIntegration Within Several Projects
Integration Within Several Projects
 
Potential Solutions Co Existence
Potential Solutions   Co ExistencePotential Solutions   Co Existence
Potential Solutions Co Existence
 
Siebel deployment
Siebel deploymentSiebel deployment
Siebel deployment
 

Similar to Logic Equations Resolver J Script

java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
priestmanmable
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
偉格 高
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
whitneyleman54422
 
Js 单元测试框架介绍
Js 单元测试框架介绍Js 单元测试框架介绍
Js 单元测试框架介绍
louieuser
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
Darwin Durand
 

Similar to Logic Equations Resolver J Script (20)

Say It With Javascript
Say It With JavascriptSay It With Javascript
Say It With Javascript
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docxjava compilerCompiler1.javajava compilerCompiler1.javaimport.docx
java compilerCompiler1.javajava compilerCompiler1.javaimport.docx
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docxsrcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
srcArtifact.javasrcArtifact.javaclassArtifactextendsCave{pub.docx
 
JSConf: All You Can Leet
JSConf: All You Can LeetJSConf: All You Can Leet
JSConf: All You Can Leet
 
JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)JavaScript - i och utanför webbläsaren (2010-03-03)
JavaScript - i och utanför webbläsaren (2010-03-03)
 
Ian 20150116 java script oop
Ian 20150116 java script oopIan 20150116 java script oop
Ian 20150116 java script oop
 
Js 单元测试框架介绍
Js 单元测试框架介绍Js 单元测试框架介绍
Js 单元测试框架介绍
 
Web Optimization Summit: Coding for Performance
Web Optimization Summit: Coding for PerformanceWeb Optimization Summit: Coding for Performance
Web Optimization Summit: Coding for Performance
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Week 12 code
Week 12 codeWeek 12 code
Week 12 code
 
Google guava
Google guavaGoogle guava
Google guava
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
FrontDays #3. Иван Федяев, Эволюция JavaScript. Обзор нововведений ECMAScript 6
 
JavaScript Classes and Inheritance
JavaScript Classes and InheritanceJavaScript Classes and Inheritance
JavaScript Classes and Inheritance
 
Productaccess m
Productaccess mProductaccess m
Productaccess m
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 

More from Roman Agaev (15)

Client/Server Paradigm And Its Implementation
Client/Server Paradigm And Its ImplementationClient/Server Paradigm And Its Implementation
Client/Server Paradigm And Its Implementation
 
Order Management Plus Integration Topics
Order Management Plus Integration TopicsOrder Management Plus Integration Topics
Order Management Plus Integration Topics
 
Workflow Usage Best Practices
Workflow Usage Best PracticesWorkflow Usage Best Practices
Workflow Usage Best Practices
 
Workflow On The Fly Monitoring Solution
Workflow On The Fly Monitoring SolutionWorkflow On The Fly Monitoring Solution
Workflow On The Fly Monitoring Solution
 
Potential Vpn Solution
Potential Vpn SolutionPotential Vpn Solution
Potential Vpn Solution
 
Potential Customer Data Model Solution Telco
Potential Customer Data Model Solution   TelcoPotential Customer Data Model Solution   Telco
Potential Customer Data Model Solution Telco
 
General Logging Approach
General Logging ApproachGeneral Logging Approach
General Logging Approach
 
General Error Handling Approach
General Error Handling ApproachGeneral Error Handling Approach
General Error Handling Approach
 
Common System Parameters
Common System ParametersCommon System Parameters
Common System Parameters
 
Common Global Parameters
Common Global ParametersCommon Global Parameters
Common Global Parameters
 
Common Msisdn Resource Number Management
Common Msisdn Resource   Number ManagementCommon Msisdn Resource   Number Management
Common Msisdn Resource Number Management
 
Guidance 4 Days Configuration Presentation
Guidance   4 Days   Configuration   PresentationGuidance   4 Days   Configuration   Presentation
Guidance 4 Days Configuration Presentation
 
Analysis
AnalysisAnalysis
Analysis
 
Siebel Web Architecture
Siebel Web ArchitectureSiebel Web Architecture
Siebel Web Architecture
 
Enterprise Integration Application
Enterprise Integration ApplicationEnterprise Integration Application
Enterprise Integration Application
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Logic Equations Resolver J Script

  • 1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=windows-1250"> <meta name="generator" content="PSPad editor, www.pspad.com"> <title></title> </head> <body> <script> //****************Sugar********************* Function.prototype.method = function (name, func) { this.prototype[name] = func; return this; }; Function.method('inherits', function (parent) { var d = {}, p = (this.prototype = new parent()); this.method('uber', function uber(name) { if (!(name in d)) { d[name] = 0; } var f, r, t = d[name], v = parent.prototype; if (t) { while (t) { v = v.constructor.prototype; t -= 1; } f = v[name]; } else { f = p[name]; if (f == this[name]) { f = v[name]; } } d[name] += 1; r = f.apply(this, Array.prototype.slice.apply(arguments, [1])); d[name] -= 1; return r; }); return this; }); Function.method('swiss', function (parent) { for (var i = 1; i < arguments.length; i += 1) { var name = arguments[i]; this.prototype[name] = parent.prototype[name]; } return this; }); //****************************************** //*************LogicEquation object*********
  • 2. //var resolveKeys = new Array(Equation, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, W, X, Y, Z); function LogicEquation() { this.resolveKeys = new Array("Equation", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "W", "X", "Y", "Z"); this.equationProducts = new ListOfLogicProducts(); this.strEquation; } LogicEquation.prototype.cons = function(value){ this.strEquation = value; } LogicEquation.prototype.getEquation = function(){ return this.strEquation; } LogicEquation.method("setEquation", function(value){ this.strEquation = value; }); LogicEquation.method("getEquationProducts", function(){ return this.equationProducts.strLogicProducts; }); LogicEquation.method("tokenizeEquation", function(){ this.equationProducts.cons(this.strEquation.split("+")); }); LogicEquation.method("resolveEquationKeys", function(args){ for(var ctr=1;ctr<args.length;ctr++) { var eqKey = args[ctr]; var tmpRegEx = new RegExp(this.resolveKeys[ctr], "g"); this.strEquation = this.strEquation.replace(tmpRegEx, eqKey); } }); LogicEquation.method("resolveEquation", function(){ return this.equationProducts.resolve(); }); //*************************************************** //***************ListOfEquationProduct*************** function ListOfLogicProducts() { this.logicProducts = []; this.strLogicProducts; }
  • 3. ListOfLogicProducts.prototype.cons = function(value){ for(var ctr=0;ctr<value.length;ctr++) { this.logicProducts[ctr] = new LogicProduct(); this.logicProducts[ctr].cons(value[ctr]); } this.strLogicProducts = value; } ListOfLogicProducts.method("resolve", function(){ var result = false; for(var ctr=0;ctr<this.logicProducts.length;ctr++) { var tmpResult = this.logicProducts[ctr].resolve(); if(result||tmpResult == true) result = true; else result = false; } return result; }); //************************************************** //****************LogicProduct********************** function LogicProduct() { this.productElements = new ListOfProductElements()//[]; this.strProductElements; } LogicProduct.method("cons", function(value){ this.productElements.cons(value.replace(/^[|]$/g,"")); this.strProductElements = value; }); LogicProduct.prototype.resolve = function(){ return this.productElements.resolve(); } //************************************************** //***************ListOfProductElements************** function ListOfProductElements() { this.listOfElements; this.strListOfElements; } ListOfProductElements.prototype.cons = function(value){ this.listOfElements = value.split("*"); this.strListOfElements = value; }
  • 4. ListOfProductElements.method("resolve", function(){ var result = true; for(var ctr=0;ctr<this.listOfElements.length;ctr++) { var tmpResult = this.listOfElements[ctr]; if(/^!/.test(tmpResult)) { var temp = tmpResult.replace(/^!/g, ""); if(temp == "true") tmpResult = "false"; else tmpResult = "true"; } if(tmpResult == "true") { if(result == true) {result = true;} else {result = false;} } else {result = false;} } return result; }); //************************************************** //***************the program************************ function equationAnalyzer(args) { try { var logEq = new LogicEquation(); logEq.cons(args[0]); //logEq.setEquation("[!true*!false*true]+[true*true*!false]"); //"[A*B*!C]+[A*B*C]" //alert(logEq.getEquation()); //alert(logEq.getEquationProducts()); logEq.resolveEquationKeys(args); logEq.tokenizeEquation(); alert(logEq.resolveEquation()); } catch(e) { alert(e.description); } } function main() {
  • 5. var args=new Array() args[0]='[!A*!B*C*D*E*F*G*H]+[A*B*!C*D*E*F*G*H]+[A*B*!C*D*E*F*G*H]'; args[1]=true; //A = true args[2]=true; //B = false args[3]=false; //C = false args[4]=true; //D = true args[5]=true; //E = true args[6]=true; //F = true args[7]=true; //G = true args[8]=false; //H = true equationAnalyzer(args); } </script> <button TYPE=BUTTON onclick="main()">EvalueLogicEquation </button> </body> </html>