Some work on Expression and Operand.

This commit is contained in:
Brad Arant 2024-07-22 14:49:15 -07:00
parent ea3d1a7ad0
commit 8475ef01d1
6 changed files with 96 additions and 18 deletions

View File

@ -1,24 +1,29 @@
#include "Expression.h"
#include "Operand.h"
#include <iostream>
namespace jet {
Expression::Expression(coreutils::ZString &expression) : MString() {
std::cout << "Expression construction:" << expression << std::endl;
Expression::Expression(coreutils::ZString &in) : MString() {
std::cout << "Expression construction:" << in << std::endl;
if(isNumber(0, expression)) {
} else if(expression.equals("true"))
write(expression);
else if(expression.equals("false"))
write(expression);
Operand op1(in);
boolean = op1.boolean;
}
Expression::~Expression() {}
bool Expression::isNumber(int reg, coreutils::ZString &expression) {
return false;
}
bool Expression::getBooleanResult() {
return boolean;
}
double Expression::getNumericResult() {
return 0;
}
coreutils::ZString Expression::getStringResult() {
return coreutils::ZString();
}
}

View File

@ -8,11 +8,13 @@ namespace jet {
class Expression : public coreutils::MString {
public:
Expression(coreutils::ZString &expression);
Expression(coreutils::ZString &in);
virtual ~Expression();
private:
bool isNumber(int reg, coreutils::ZString &expression);
bool getBooleanResult();
double getNumericResult();
coreutils::ZString getStringResult();
bool boolean;
};
}

36
Operand.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "Operand.h"
namespace jet {
Operand::Operand(coreutils::ZString &in) {
if(in.ifNext("true")) {
boolean = true;
return;
}
if(in.ifNext("false")) {
boolean = false;
return;
}
/*
if(in.ifNext("+")) {
}
if(in.ifNext("-")) {
}
if(in.getTokenInclude("0123456789")) {
}
if(in.ifNext(".")) {
}
if(in.getTokenInclude("0123456789")) {
}
if(in.ifNext("\"")) {
}
*/
}
}

35
Operand.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef __Operand_h__
#define __Operand_h__
#include "ZString.h"
namespace jet {
class Operand {
public:
Operand(coreutils::ZString &in);
bool isNumber();
bool isInteger();
bool isFloat();
bool isString();
bool isVariable();
///
/// boolean is set by internal processes to return the boolean
/// equivilent value.
///
bool boolean;
private:
// dataType enum ={};
double doubleValue;
};
}
#endif

View File

@ -1,4 +1,3 @@
#include "__if.h"
#include "Exception.h"
#include <iostream>
@ -15,11 +14,12 @@ namespace jet {
throw coreutils::Exception("Either value1 or expr can be specified but not both.");
if(variableDefined("value2")) {
if(variableDefined("type")) {
result = "true";
result = Expression(variables["expr"]);
} else
throw coreutils::Exception("type expected if value1 and value2 specified.");
} else
throw coreutils::Exception("value2 required if value1 specified.");
std::cout << variables["value1"].str() << "' and value2 '" << variables["value2"].str() << "' comparison" << std::endl;
} else if(variableDefined("expr")) {
if(variableDefined("value2"))
throw coreutils::Exception("value2 should not be specified with expr.");

View File

@ -18,7 +18,7 @@ int main(int argc, char **argv) {
" >>>$[thename]<<<\n"
" local: >>>#[name]<<<\n"
" <mysql key=\"uu\">\n"
" <if value1=\"X\" value2=\"Y\" type=\"eq\">\n"
" <if value1=\"X\" value2=\"Y\" type=\"ne\">\n"
" 789\n"
" <if expr=\"false\">\n"
" 123\n"