diff --git a/Expression.cpp b/Expression.cpp index ec1455c..b0d03eb 100644 --- a/Expression.cpp +++ b/Expression.cpp @@ -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() {} diff --git a/Expression.h b/Expression.h index 875b9d9..6d02c93 100644 --- a/Expression.h +++ b/Expression.h @@ -15,6 +15,7 @@ namespace jet { double getNumericResult(); coreutils::ZString getStringResult(); bool boolean; + coreutils::ZString string; }; } diff --git a/Operand.cpp b/Operand.cpp index deaf72f..6b87f10 100644 --- a/Operand.cpp +++ b/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; } diff --git a/Operand.h b/Operand.h index 0d6b523..d4ffb38 100644 --- a/Operand.h +++ b/Operand.h @@ -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 ={}; diff --git a/Tag.cpp b/Tag.cpp index 1c10823..be5e096 100644 --- a/Tag.cpp +++ b/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 @@ -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); diff --git a/__call.cpp b/__call.cpp index d2157fc..33ec9aa 100644 --- a/__call.cpp +++ b/__call.cpp @@ -1,4 +1,4 @@ -#include "__system.h" +#include "__call.h" #include "Exception.h" #include "MString.h" #include @@ -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; } } diff --git a/__call.h b/__call.h index bea3b18..09beb14 100644 --- a/__call.h +++ b/__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; diff --git a/__set.cpp b/__set.cpp index 6b5fead..102f02a 100644 --- a/__set.cpp +++ b/__set.cpp @@ -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; diff --git a/__system.cpp b/__system.cpp index 89b2650..d2157fc 100644 --- a/__system.cpp +++ b/__system.cpp @@ -1,4 +1,4 @@ -#include "__call.h" +#include "__system.h" #include "Exception.h" #include "MString.h" #include @@ -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"))) diff --git a/__system.h b/__system.h index 09beb14..bea3b18 100644 --- a/__system.h +++ b/__system.h @@ -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; diff --git a/testjet.cpp b/testjet.cpp index a14d3da..47e639c 100644 --- a/testjet.cpp +++ b/testjet.cpp @@ -10,14 +10,17 @@ int main(int argc, char **argv) { " This is a comment and should not show up in the output.\n" " \n" " \n" - " \n" + " \n" + " \n" + " theexpr=($[theexpr])\n" + " theexpr2($[theexpr2])\n" " \n" " this is the value store in #[name].\n" " this is the value store in #[name].\n" " another container value\n" " >>>$[noeval]<<<\n" " >>>$[thename]<<<\n" - " local: >>>#[name]<<<\n" + " local: >>>#[namex]<<<\n" " \n" " \n" " 789\n" @@ -32,9 +35,9 @@ int main(int argc, char **argv) { " -->#[ix]<--\n" " \n" " \n" - " $[ls]\n" + " $[lsi]\n" " \n" - " $[file]\n" + " $[filex]\n" " \n" "\n");