PH Logo
Logo intepreter modeled after UCB Logo.
/Users/paul/Documents/phlogo/core/LogicalVerbs.cpp
00001 /*
00002  *  PredicateVerbs.cpp
00003  *
00004  *  Author: Paul Hamilton
00005  *      Date: 17 Aug 2011
00006  *
00007  */
00008 
00009 #include "Verbs.h"
00010 
00011 #include "Thing.h"
00012 #include "TokenStream.h"
00013 
00014 #include <boost/algorithm/string/predicate.hpp>
00015 #include <boost/lexical_cast.hpp>
00016 
00017 using namespace std;
00018 using namespace boost::algorithm;
00019 using namespace boost;
00020 
00021 namespace phlogo {
00022 
00023 void Verbs::And(TokenStream *ts) {
00024     
00025     string a = getWord(ts);
00026     bool result = true;
00027     if (a == "FALSE") {
00028         result = false;
00029         getThing(ts);
00030     }
00031     else {
00032         if (ts->withinSubExpression()) {
00033             while (result && ts->hasMoreSubExpression()) {
00034                 string b = getWord(ts);
00035                 if (b == "FALSE") {
00036                     result = false;
00037                 }
00038             }
00039         }
00040         else {
00041             string b = getWord(ts);
00042             if (b == "FALSE") {
00043                 result = false;
00044             }
00045         }
00046     }
00047     setBooleanResult(result);
00048 }
00049 
00050 void Verbs::Or(TokenStream *ts) {
00051     
00052     string a = getWord(ts);
00053     bool result = false;
00054     if (a == "TRUE") {
00055         result = true;
00056         getThing(ts);
00057     }
00058     else {
00059         if (ts->withinSubExpression()) {
00060             while (!result && ts->hasMoreSubExpression()) {
00061                 string b = getWord(ts);
00062                 if (b == "TRUE") {
00063                     result = true;
00064                 }
00065             }
00066         }
00067         else {
00068             string b = getWord(ts);
00069             if (b == "TRUE") {
00070                 result = true;
00071             }
00072         }
00073     }
00074     setBooleanResult(result);
00075     
00076 }
00077 
00078 void Verbs::Not(TokenStream *ts) {
00079     
00080     setBooleanResult(getWord(ts) == "FALSE");
00081     
00082 }
00083 
00084 }
 All Classes Functions