Started into the Expression and Operand obejcts.
This commit is contained in:
parent
071151d8a1
commit
bd25efc461
@ -6,10 +6,13 @@ namespace jet {
|
||||
|
||||
Expression::Expression(coreutils::ZString &in) : MString() {
|
||||
std::cout << "Expression construction:" << in << std::endl;
|
||||
|
||||
|
||||
Operand op1(in);
|
||||
|
||||
boolean = op1.boolean;
|
||||
string = op1.string;
|
||||
|
||||
std::cout << "Leaving expression string: " << string << std::endl;
|
||||
}
|
||||
|
||||
Expression::~Expression() {}
|
||||
|
@ -15,6 +15,7 @@ namespace jet {
|
||||
double getNumericResult();
|
||||
coreutils::ZString getStringResult();
|
||||
bool boolean;
|
||||
coreutils::ZString string;
|
||||
};
|
||||
|
||||
}
|
||||
|
41
Operand.cpp
41
Operand.cpp
@ -1,15 +1,56 @@
|
||||
#include "Operand.h"
|
||||
#include "Exception.h"
|
||||
|
||||
namespace jet {
|
||||
|
||||
Operand::Operand(coreutils::ZString &in) {
|
||||
|
||||
in.skipWhitespace();
|
||||
|
||||
if(in.ifNext("SUBSTRING")) {
|
||||
if(!in.ifNext("("))
|
||||
throw coreutils::Exception("Expecting ( for SUBSTRING parameters.");
|
||||
Operand parm1(in);
|
||||
if(!in.ifNext(","))
|
||||
throw coreutils::Exception("Expecting , in SUBSTRING expression.");
|
||||
Operand parm2(in);
|
||||
if(in.ifNext(")")) {
|
||||
string = parm1.string.substring(parm2.string.asInteger());
|
||||
}
|
||||
else if(!in.ifNext(","))
|
||||
throw coreutils::Exception("Expecting , in SUBSTRING expression.");
|
||||
Operand parm3(in);
|
||||
if(in.ifNext(")")) {
|
||||
string = parm1.string.substring(parm2.string.asInteger(), parm3.string.asInteger());
|
||||
}
|
||||
else
|
||||
throw coreutils::Exception("Expecting ) at end of substring expression.");
|
||||
}
|
||||
|
||||
else if(in.ifNext("LEFT")) {
|
||||
|
||||
} else if(in.ifNext("RIGHT")) {
|
||||
|
||||
} else if(in.ifNext("TRIM")) {
|
||||
|
||||
} else if(in.ifNext("TOUPPER")) {
|
||||
|
||||
} else if(in.ifNext("TOLOWER")) {
|
||||
|
||||
} else if(in.ifNext("REVERSE")) {
|
||||
|
||||
} else if(in.ifNext("CONCAT")) {
|
||||
|
||||
}
|
||||
|
||||
if(in.ifNext("true")) {
|
||||
boolean = true;
|
||||
string = "true";
|
||||
return;
|
||||
}
|
||||
if(in.ifNext("false")) {
|
||||
boolean = false;
|
||||
string = "false";
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -16,13 +16,13 @@ namespace jet {
|
||||
bool isString();
|
||||
bool isVariable();
|
||||
|
||||
|
||||
///
|
||||
/// boolean is set by internal processes to return the boolean
|
||||
/// equivilent value.
|
||||
///
|
||||
|
||||
bool boolean;
|
||||
coreutils::ZString string;
|
||||
|
||||
private:
|
||||
// dataType enum ={};
|
||||
|
10
Tag.cpp
10
Tag.cpp
@ -7,8 +7,10 @@
|
||||
#include "__for.h"
|
||||
#include "__if.h"
|
||||
#include "__read.h"
|
||||
#include "__write.h"
|
||||
#include "__set.h"
|
||||
#include "__call.h"
|
||||
#include "__system.h"
|
||||
#include "__jet.h"
|
||||
#include "__while.h"
|
||||
#include <iostream>
|
||||
@ -119,11 +121,17 @@ namespace jet {
|
||||
} else if(ifTagName(in, "read")) {
|
||||
__read _read(in, out, global);
|
||||
continue;
|
||||
} else if(ifTagName(in, "write")) {
|
||||
__write _write(in, out, global);
|
||||
continue;
|
||||
} else if(ifTagName(in, "set")) {
|
||||
__set _set(in, out, global);
|
||||
continue;
|
||||
} else if(ifTagName(in, "call")) {
|
||||
__call _set(in, out, global);
|
||||
__call _call(in, out, global);
|
||||
continue;
|
||||
} else if(ifTagName(in, "system")) {
|
||||
__system _system(in, out, global);
|
||||
continue;
|
||||
} else if(ifTagName(in, "while")) {
|
||||
__while _while(in, out, global);
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "__system.h"
|
||||
#include "__call.h"
|
||||
#include "Exception.h"
|
||||
#include "MString.h"
|
||||
#include <stdlib.h>
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__system::__system(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
||||
__call::__call(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
||||
if(hasContainer)
|
||||
throw coreutils::Exception("call cannot have a container.");
|
||||
if(!variableDefined(coreutils::ZString("pgm")))
|
||||
@ -51,7 +51,6 @@ namespace jet {
|
||||
else
|
||||
out.read(fdo[0]);
|
||||
waitpid(pid, &status, 0);
|
||||
std::cout << "status: " << status << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
8
__call.h
8
__call.h
@ -1,14 +1,14 @@
|
||||
#ifndef ____system_h__
|
||||
#define ____system_h__
|
||||
#ifndef ____call_h__
|
||||
#define ____call_h__
|
||||
|
||||
#include "Tag.h"
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __system : public Tag {
|
||||
class __call : public Tag {
|
||||
|
||||
public:
|
||||
__system(coreutils::ZString &in, coreutils::MString &out, Global &global);
|
||||
__call(coreutils::ZString &in, coreutils::MString &out, Global &global);
|
||||
|
||||
private:
|
||||
int pid;
|
||||
|
@ -22,7 +22,7 @@ namespace jet {
|
||||
if(variableDefined("expr")) {
|
||||
if(variableDefined("eval"))
|
||||
throw coreutils::Exception("Cannot use eval with expr.");
|
||||
global.variables[variables["name"]] = Expression(variables["expr"]);
|
||||
global.variables[variables["name"]] = Expression(variables["expr"]).string;
|
||||
} else if(hasContainer) {
|
||||
if(evaluate) {
|
||||
global.variables[variables["name"]] = out;
|
||||
|
@ -1,4 +1,4 @@
|
||||
#include "__call.h"
|
||||
#include "__system.h"
|
||||
#include "Exception.h"
|
||||
#include "MString.h"
|
||||
#include <stdlib.h>
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__call::__call(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
||||
__system::__system(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
||||
if(hasContainer)
|
||||
throw coreutils::Exception("call cannot have a container.");
|
||||
if(!variableDefined(coreutils::ZString("pgm")))
|
||||
|
@ -1,14 +1,14 @@
|
||||
#ifndef ____call_h__
|
||||
#define ____call_h__
|
||||
#ifndef ____system_h__
|
||||
#define ____system_h__
|
||||
|
||||
#include "Tag.h"
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __call : public Tag {
|
||||
class __system : public Tag {
|
||||
|
||||
public:
|
||||
__call(coreutils::ZString &in, coreutils::MString &out, Global &global);
|
||||
__system(coreutils::ZString &in, coreutils::MString &out, Global &global);
|
||||
|
||||
private:
|
||||
int pid;
|
||||
|
11
testjet.cpp
11
testjet.cpp
@ -10,14 +10,17 @@ int main(int argc, char **argv) {
|
||||
" <comment>This is a comment and should not show up in the output.</comment>\n"
|
||||
" <html>\n"
|
||||
" <set name=\"ix\" value=\"1\" />\n"
|
||||
" <set name=\"theexpr\" expr=\"true\" />\n"
|
||||
" <set name=\"theexpr\" expr=\"SUBSTRING(\"abcdefg\",1,3)\" />\n"
|
||||
" <set name=\"theexpr2\" expr=\"5+3\" />\n"
|
||||
" theexpr=($[theexpr])\n"
|
||||
" theexpr2($[theexpr2])\n"
|
||||
" <set name=\"varname$[ix]\" value=\"vardata\" scope=\"global\" />\n"
|
||||
" <set name=\"noeval\" eval=\"no\">this is the value store in #[name].</set>\n"
|
||||
" <set name=\"thename\" eval=\"yes\">this is the value store in #[name].</set>\n"
|
||||
" <set name=\"newname\" scope=\"global\">another container value</set>\n"
|
||||
" >>>$[noeval]<<<\n"
|
||||
" >>>$[thename]<<<\n"
|
||||
" local: >>>#[name]<<<\n"
|
||||
" local: >>>#[namex]<<<\n"
|
||||
" <mysql key=\"uu\">\n"
|
||||
" <if value1=\"X\" value2=\"Y\" type=\"ne\">\n"
|
||||
" 789\n"
|
||||
@ -32,9 +35,9 @@ int main(int argc, char **argv) {
|
||||
" -->#[ix]<--\n"
|
||||
" </for>\n"
|
||||
" <call pgm=\"/usr/bin/ls\" arg1=\"-al\" name=\"ls\" />\n"
|
||||
" $[ls]\n"
|
||||
" $[lsi]\n"
|
||||
" <read file=\"compile\" name=\"file\" />\n"
|
||||
" $[file]\n"
|
||||
" $[filex]\n"
|
||||
" </html>\n"
|
||||
"</jet>\n");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user