Skip to content

Commit

Permalink
fix unary +/- equation output - add in PULSE_TRAIN and RANDOM_NORMAL,…
Browse files Browse the repository at this point in the history
… DELAY1
  • Loading branch information
bobeberlein committed Jul 10, 2018
1 parent 0c52b43 commit 6a4f13d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 5 deletions.
41 changes: 41 additions & 0 deletions src/Function/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,47 @@ void FunctionSampleIfTrue::OutputComputable(ContextInfo *info, ExpressionList *a
Function::OutputComputable(info, arg);
}

void FunctionPulseTrain::OutputComputable(ContextInfo *info, ExpressionList *arg)
{
if (arg->Length() == 4)
{
*info << "( IF TIME >= (";
const_cast<Expression*>((*arg)[0])->OutputComputable(info); // OutputComputable should really be const
*info << ") AND TIME <= (";
const_cast<Expression*>((*arg)[3])->OutputComputable(info); // OutputComputable should really be const
*info << ") AND (TIME - (";
const_cast<Expression*>((*arg)[0])->OutputComputable(info); // OutputComputable should really be const
*info << ")) MOD (";
const_cast<Expression*>((*arg)[2])->OutputComputable(info); // OutputComputable should really be const
*info << ") < (";
const_cast<Expression*>((*arg)[1])->OutputComputable(info); // OutputComputable should really be const
*info << ") THEN 1 ELSE 0 )";
return;
}
Function::OutputComputable(info, arg);
}

void FunctionRandomNormal::OutputComputable(ContextInfo *info, ExpressionList *arg)
{
if (arg->Length() == 5)
{
*info << "NORMAL(";
const_cast<Expression*>((*arg)[2])->OutputComputable(info); // OutputComputable should really be const
*info << ", ";
const_cast<Expression*>((*arg)[3])->OutputComputable(info); // OutputComputable should really be const
*info << ", ";
const_cast<Expression*>((*arg)[4])->OutputComputable(info); // OutputComputable should really be const
*info << ", ";
const_cast<Expression*>((*arg)[0])->OutputComputable(info); // OutputComputable should really be const
*info << ", ";
const_cast<Expression*>((*arg)[1])->OutputComputable(info); // OutputComputable should really be const
*info << ")";
return;
}
Function::OutputComputable(info, arg);
}


void FunctionIfThenElse::OutputComputable(ContextInfo *info, ExpressionList *arg)
{
if (arg->Length() == 3)
Expand Down
22 changes: 21 additions & 1 deletion src/Function/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ FSubclass(FunctionVectorElmMap, "VECTOR ELM MAP", 2, "VECTOR ELM MAP");
FSubclass(FunctionVectorSortOrder, "VECTOR SORT ORDER", 2, "VECTOR SORT ORDER");
FSubclass(FunctionGame, "GAME", 1, ""); // don't need this
FSubclass(FunctionRandom01, "RANDOM 0 1", 0, "UNIFORM(0,1)");
FSubclass(FunctionRandomUniform, "RANDOM UNIFORM", 3, "UNIFORM");

// actually memory but no init - or init - does not matter for translation
FSubclass(FunctionSmooth, "SMOOTH", 2, "SMTH1")
FSubclass(FunctionSmoothI, "SMOOTHI", 3, "SMTH1")
FSubclass(FunctionSmooth3, "SMOOTH3", 2, "SMTH3")
FSubclass(FunctionTrend,"TREND", 3, "TREND")
FSubclass(FunctionDelay1, "DELAY1", 2, "DELAY1")
FSubclass(FunctionDelay3, "DELAY3", 2, "DELAY3")
FSubclass(FunctionDelay, "DELAY FIXED", 3, "DELAY")
FSubclass(FunctionNPV,"NPV",4,"NPV")
Expand All @@ -154,7 +156,6 @@ FSubclass(FunctionModulo,"MODULO",2,"MODULO")
FSubclass(FunctionGetDataAtTime, "GET DATA AT TIME", 2, "GET_DATA_AT_TIME")
FSubclass(FunctionGetDataLastTime, "GET DATA LAST TIME", 1, "GET_DATA_LAST_TIME")
FSubclass(FunctionLookupArea, "LOOKUP AREA", 3, "LOOKUP_AREA")
FSubclass(FunctionRandomNormal, "RANDOM NORMAL", 5, "RANDOM_NORMAL")

FSubclassStart(FunctionDelayN, "DELAY N", 4, "DELAYN")
public:
Expand Down Expand Up @@ -203,6 +204,25 @@ class FunctionSampleIfTrue : public Function
private:
};

class FunctionPulseTrain : public Function
{
public:
FunctionPulseTrain(SymbolNameSpace *sns) : Function(sns, "PULSE TRAIN", 4) {}
~FunctionPulseTrain(void) {}
std::string ComputableName(void) { return "PulseTrain"; }
virtual void OutputComputable(ContextInfo *info, ExpressionList *arg);
private:
};
class FunctionRandomNormal : public Function
{
public:
FunctionRandomNormal(SymbolNameSpace *sns) : Function(sns, "RANDOM NORMAL", 5) {}
~FunctionRandomNormal(void) {}
std::string ComputableName(void) { return "RandomNormal"; }
virtual void OutputComputable(ContextInfo *info, ExpressionList *arg);
private:
};


class FunctionIfThenElse : public Function
{
Expand Down
4 changes: 2 additions & 2 deletions src/Vensim/VYacc.tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2045,13 +2045,13 @@ yyparse ()
case 81:
/* Line 1792 of yacc.c */
#line 220 "C:\\sdev\\xmutil\\src\\Vensim\\VYacc.y"
{ (yyval.exn) = vpyy_operator_expression('-',(yyvsp[(2) - (2)].exn),NULL) ; }
{ (yyval.exn) = vpyy_operator_expression('-',NULL, (yyvsp[(2) - (2)].exn)) ; }
break;

case 82:
/* Line 1792 of yacc.c */
#line 221 "C:\\sdev\\xmutil\\src\\Vensim\\VYacc.y"
{ (yyval.exn) = vpyy_operator_expression('+',(yyvsp[(2) - (2)].exn),NULL) ; }
{ (yyval.exn) = vpyy_operator_expression('+',NULL, (yyvsp[(2) - (2)].exn)) ; }
break;

case 83:
Expand Down
4 changes: 2 additions & 2 deletions src/Vensim/VYacc.y
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ exp:
| exp VPTT_and exp { $$ = vpyy_operator_expression(VPTT_and,$1,$3) ; }
| VPTT_not exp { $$ = vpyy_operator_expression(VPTT_not,$2,NULL) ; }
| exp '=' exp { $$ = vpyy_operator_expression('=',$1,$3) ; }
| '-' exp { $$ = vpyy_operator_expression('-',$2,NULL) ; } /* unary plus - might be used by numbers */
| '+' exp { $$ = vpyy_operator_expression('+',$2,NULL) ; } /* unary plus - might be used by numbers */
| '-' exp { $$ = vpyy_operator_expression('-',NULL, $2) ; } /* unary plus - might be used by numbers */
| '+' exp { $$ = vpyy_operator_expression('+',NULL, $2) ; } /* unary plus - might be used by numbers */
| exp '^' exp { $$ = vpyy_operator_expression('^',$1,$3) ; }
;

Expand Down
3 changes: 3 additions & 0 deletions src/Vensim/VensimParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void VensimParse::ReadyFunctions()
new FunctionInitial(pSymbolNameSpace);
new FunctionSampleIfTrue(pSymbolNameSpace);
new FunctionPulse(pSymbolNameSpace);
new FunctionPulseTrain(pSymbolNameSpace);
new FunctionIfThenElse(pSymbolNameSpace);
new FunctionLog(pSymbolNameSpace);
new FunctionZidz(pSymbolNameSpace);
Expand All @@ -60,6 +61,7 @@ void VensimParse::ReadyFunctions()
new FunctionSmoothI(pSymbolNameSpace);
new FunctionSmooth3(pSymbolNameSpace);
new FunctionTrend(pSymbolNameSpace);
new FunctionDelay1(pSymbolNameSpace);
new FunctionDelay3(pSymbolNameSpace);
new FunctionDelay(pSymbolNameSpace);
new FunctionDelayN(pSymbolNameSpace);
Expand All @@ -78,6 +80,7 @@ void VensimParse::ReadyFunctions()
new FunctionVectorSortOrder(pSymbolNameSpace);
new FunctionGame(pSymbolNameSpace);
new FunctionRandom01(pSymbolNameSpace);
new FunctionRandomUniform(pSymbolNameSpace);
new FunctionAbs(pSymbolNameSpace);
new FunctionExp(pSymbolNameSpace);
new FunctionSqrt(pSymbolNameSpace);
Expand Down

0 comments on commit 6a4f13d

Please sign in to comment.