Skip to content

Commit

Permalink
Merge pull request #165 from nlmixr2/163-rhs-dadt
Browse files Browse the repository at this point in the history
Add fix/test for dadt(#) on lhs
  • Loading branch information
mattfidler committed Sep 26, 2023
2 parents c1b9a64 + c4a11a2 commit 9f234ec
Show file tree
Hide file tree
Showing 4 changed files with 3,226 additions and 3,102 deletions.
192 changes: 98 additions & 94 deletions inst/abbrev.g
@@ -1,50 +1,50 @@
//loop
statement_list :
(statement)+ ;
statement_list :
(statement)+ ;

// return and exit statements not supported

statement
: call_protocol_phrase singleLineComment?
| assignment singleLineComment?
| if1 singleLineComment?
| if1other singleLineComment?
| ifthen singleLineComment?
| ifcallrandom singleLineComment?
| ifcallsimeps singleLineComment?
| ifcallsimeta singleLineComment?
| elseif singleLineComment?
| else singleLineComment?
| endif singleLineComment?
| dowhile singleLineComment?
| enddo singleLineComment?
| ini singleLineComment?
| iniI singleLineComment?
| mtimeL singleLineComment?
| fbio singleLineComment?
| alag singleLineComment?
| rate singleLineComment?
| dur singleLineComment?
| scale singleLineComment?
| derivative singleLineComment?
| derivativeI singleLineComment?
| prob singleLineComment?
| da singleLineComment?
| dp singleLineComment?
| callsimeta singleLineComment?
| callgeteta singleLineComment?
| callsimeps singleLineComment?
| callpassmode singleLineComment?
| callsupp singleLineComment?
| callrandom singleLineComment?
| exit_line singleLineComment?
| comresn1 singleLineComment?
| ifexit singleLineComment?
| callfl singleLineComment?
| nspop singleLineComment?
| verbatimCode singleLineComment?
| includeCode singleLineComment?
| singleLineComment;
statement
: call_protocol_phrase singleLineComment?
| assignment singleLineComment?
| if1 singleLineComment?
| if1other singleLineComment?
| ifthen singleLineComment?
| ifcallrandom singleLineComment?
| ifcallsimeps singleLineComment?
| ifcallsimeta singleLineComment?
| elseif singleLineComment?
| else singleLineComment?
| endif singleLineComment?
| dowhile singleLineComment?
| enddo singleLineComment?
| ini singleLineComment?
| iniI singleLineComment?
| mtimeL singleLineComment?
| fbio singleLineComment?
| alag singleLineComment?
| rate singleLineComment?
| dur singleLineComment?
| scale singleLineComment?
| derivative singleLineComment?
| derivativeI singleLineComment?
| prob singleLineComment?
| da singleLineComment?
| dp singleLineComment?
| callsimeta singleLineComment?
| callgeteta singleLineComment?
| callsimeps singleLineComment?
| callpassmode singleLineComment?
| callsupp singleLineComment?
| callrandom singleLineComment?
| exit_line singleLineComment?
| comresn1 singleLineComment?
| ifexit singleLineComment?
| callfl singleLineComment?
| nspop singleLineComment?
| verbatimCode singleLineComment?
| includeCode singleLineComment?
| singleLineComment;


ini : 'A_0(' decimalintNo0 ')' '=' logical_or_expression;
Expand All @@ -70,8 +70,8 @@ callfl: 'CALLFL' '=' ('-' ('1' | '2') | '0' | '1');
call_protocol_phrase: '(' ('OBSERVATION' 'EVENT'
| 'OBS'
| 'OBSERVATION' 'ONLY'
| 'ONLY' 'OBSERVATION'
| 'ONLY' 'OBSERVATIONS'
| 'ONLY' 'OBSERVATION'
| 'ONLY' 'OBSERVATIONS'
| 'OBS' 'ONLY'
| 'ONCE' 'PER' 'INDIVIDUAL' 'RECORD'
| 'ONCE'
Expand Down Expand Up @@ -106,38 +106,38 @@ ifcallrandom: 'IF' '(' logical_or_expression ')' 'CALL' 'RANDOM' '(' "(10|[1-9])

assignment : identifier '=' logical_or_expression;

logical_or_expression : logical_and_expression
(or_expression_nm logical_and_expression)* ;
logical_or_expression : logical_and_expression
(or_expression_nm logical_and_expression)* ;

or_expression_nm: '.or.' | '.OR.';

logical_and_expression : equality_expression0
(and_expression_nm equality_expression0)* ;
logical_and_expression : equality_expression0
(and_expression_nm equality_expression0)* ;

and_expression_nm: '.and.' | '.AND.';

equality_expression0 : equality_expression |
'(' equality_expression ')';
'(' equality_expression ')';

equality_expression : relational_expression
((neq_expression_nm | eq_expression_nm ) relational_expression)* ;
equality_expression : relational_expression
((neq_expression_nm | eq_expression_nm ) relational_expression)* ;

eq_expression_nm: '.eq.' | '.EQ.' | '==';
neq_expression_nm: '.ne.' | '.NE.';

relational_expression : additive_expression
((lt_expression_nm | gt_expression_nm | le_expression_nm | ge_expression_nm) additive_expression)* ;
((lt_expression_nm | gt_expression_nm | le_expression_nm | ge_expression_nm) additive_expression)* ;

lt_expression_nm: '<' | '.lt.' | '.LT.';
gt_expression_nm: '>' | '.gt.' | '.GT.';
ge_expression_nm: '>='| '.ge.' | '.GE.';
le_expression_nm: '<='| '.le.' | '.LE.';

additive_expression : multiplicative_expression
(('+' | '-') multiplicative_expression)* ;
(('+' | '-') multiplicative_expression)* ;

multiplicative_expression : unary_expression
(mult_part)* ;
multiplicative_expression : unary_expression
(mult_part)* ;

mult_part : ('*' | '/') unary_expression ;

Expand Down Expand Up @@ -165,6 +165,9 @@ sigma : ('SIGMA(' | 'sigma(') decimalintNo0 ',' decimalintNo0 ')';
omega : ('OMEGA(' | 'omega(') decimalintNo0 ',' decimalintNo0 ')';
sigma1 : ('SIGMA(' | 'sigma(') decimalintNo0 ')';
omega1 : ('OMEGA(' | 'omega(') decimalintNo0 ')';
der : ('DADT(' | 'dadt(' ) decimalintNo0 ')';
derI : ('DADT(' | 'dadt(' ) identifier ')';


avar: "[Aa][0-9][0-9][0-9][0-9][0-9]";
cvar: "[Cc][0-9][0-9][0-9][0-9][0-9]";
Expand All @@ -185,43 +188,45 @@ duri : "[Dd][1-9][0-9]*";
scalei : "[Ss]([0-9]+|C|O)";


primary_expression
: constant
| a0
| a0i
| fbioi
| alagi
| ratei
| duri
| scalei
| identifier
| theta
| thetaI
| eta
| etaI
| eps
| epsI
| err
| errI
| dt
| amt
| amtI
| mpast
| mnext
| mtime
| mixp
| mixpc
| avar
| cvar
| com
| pcmt
| sigma
| omega
| sigma1
| omega1
| function
| '(' logical_or_expression ')'
;
primary_expression
: constant
| derI
| der
| a0
| a0i
| fbioi
| alagi
| ratei
| duri
| scalei
| identifier
| theta
| thetaI
| eta
| etaI
| eps
| epsI
| err
| errI
| dt
| amt
| amtI
| mpast
| mnext
| mtime
| mixp
| mixpc
| avar
| cvar
| com
| pcmt
| sigma
| omega
| sigma1
| omega1
| function
| '(' logical_or_expression ')'
;

function : function_name (logical_or_expression)* (',' logical_or_expression)* ')' ;

Expand Down Expand Up @@ -256,4 +261,3 @@ whitespace: ( "[ \t\r\n]+" | singleLineComment )*;
singleLineComment: "[;:]" "[^\n]*";
verbatimCode: '"' "[^\n]*";
includeCode: 'include' "[^\n]*";

53 changes: 38 additions & 15 deletions src/abbrev.c
Expand Up @@ -227,13 +227,13 @@ int abbrev_identifier_or_constant(char *name, int i, D_ParseNode *pn) {
sAppendN(&curLine, "icall", 5);
return 1;
} else if (!nmrxstrcmpi("IREP", v)) {
if (irepWarning == 0) {
nonmem2rxPushTheta("irep <- fix(0)", "irep set to 0 (not supported)",
NULL, 0);
if (irepWarning == 0) {
nonmem2rxPushTheta("irep <- fix(0)", "irep set to 0 (not supported)",
NULL, 0);
Rf_warning("irep found and added as rxode2 parameter to model (=0); 'sim.id' is added to all multi-study simulations and currently cannot be accessed in the simulation code");
irepWarning=1;
}
sAppendN(&curLine, "irep", 4);
sAppendN(&curLine, "irep", 4);
return 1;
} else if (!nmrxstrcmpi("MTDIFF", v)) {
//sClear(&sbTransErr);
Expand Down Expand Up @@ -426,6 +426,28 @@ int abbrevParamTheta(char *name, int i, D_ParseNode *pn) {
return 0;
}

int abbrevParamDaDt(char *name, int i, D_ParseNode *pn) {
int needName=0;
if (!strcmp("der", name) ||
(needName = !strcmp("derI", name))) {
if (i == 0) {
D_ParseNode *xpn = d_get_child(pn, 1);
char *v = (char*)rc_dup_str(xpn->start_loc.s, xpn->end);
if (needName) {
SEXP namePar = PROTECT(nonmem2rxGetModelNum(v));
v = (char*)rc_dup_str(CHAR(STRING_ELT(namePar, 0)), 0);
UNPROTECT(1);
}
int cur = atoi(v);
maxA = max2(maxA, cur);
nonmem2rxPushObservedDadt(cur);
sAppend(&curLine, "d/dt(rxddta%s)", v);
}
return 1;
}
return 0;
}

int abbrevParamEta(char *name, int i, D_ParseNode *pn) {
int needName=0;
if (!strcmp("eta", name) ||
Expand All @@ -449,7 +471,7 @@ int abbrevParamEta(char *name, int i, D_ParseNode *pn) {
int abbrevParamEps(char *name, int i, D_ParseNode *pn) {
int needName = 0;
if (!strcmp("eps", name) ||
(needName = !strcmp("epsI", name))) {
(needName = !strcmp("epsI", name))) {
if (i == 0) {
D_ParseNode *xpn = d_get_child(pn, 1);
char *v = (char*)rc_dup_str(xpn->start_loc.s, xpn->end);
Expand Down Expand Up @@ -488,7 +510,7 @@ int abbrevParamErr(char *name, int i, D_ParseNode *pn) {
int abbrevParamAmt (char *name, int i, D_ParseNode *pn) {
int needName = 0;
if (!strcmp("amt", name) ||
(needName = !strcmp("amtI", name))) {
(needName = !strcmp("amtI", name))) {
if (i == 0) {
D_ParseNode *xpn = d_get_child(pn, 1);
char *v = (char*)rc_dup_str(xpn->start_loc.s, xpn->end);
Expand Down Expand Up @@ -530,6 +552,7 @@ int abbrev_params(char *name, int i, D_ParseNode *pn) {
abbrevParamErr(name, i, pn) ||
abbrevParamAmt(name, i, pn) ||
abbrevParamA0(name, i, pn) ||
abbrevParamDaDt(name, i, pn) ||
abbrevParamMixp(name, i, pn);
}

Expand Down Expand Up @@ -810,7 +833,7 @@ int abbrev_unsupported_lines(char *name, int i, D_ParseNode *pn) {
//parseFree(0);
int x = atoi(v1), y = atoi(v2);
Rf_warning("SIGMA(%d, %d) does not have an equivalent rxode2/nlmixr2 code\nreplacing with a constant from the model translation\nthis will not be updated with simulations",
x, y);
x, y);
sAppend(&curLine, "sigma.%d.%d", x, y);
nonmem2rxPushSigmaEst(x, y);
return 0;
Expand All @@ -834,7 +857,7 @@ int abbrev_unsupported_lines(char *name, int i, D_ParseNode *pn) {
char *v2 = (char*)rc_dup_str(xpn->start_loc.s, xpn->end);
int x = atoi(v1), y = atoi(v2);
Rf_warning("OMEGA(%d, %d) does not have an equivalent rxode2/nlmixr2 code\nreplacing with a constant from the model translation\nthis will not be updated with simulations",
x, y);
x, y);
sAppend(&curLine, "omega.%d.%d", x, y);
nonmem2rxPushOmegaEst(x, y);
} else if (!strcmp("omega1", name)) {
Expand All @@ -843,7 +866,7 @@ int abbrev_unsupported_lines(char *name, int i, D_ParseNode *pn) {
char *v1 = (char*)rc_dup_str(xpn->start_loc.s, xpn->end);
int x = atoi(v1);
Rf_warning("OMEGA(%d) does not have an equivalent rxode2/nlmixr2 code\nreplacing with a constant from the model translation\nthis will not be updated with simulations",
x);
x);
sAppend(&curLine, "omega.%d.", x);
nonmem2rxPushOmegaEst(x, -1);
}
Expand Down Expand Up @@ -1164,12 +1187,12 @@ void wprint_parsetree_abbrev(D_ParserTables pt, D_ParseNode *pn, int depth, prin
pushModel();
return;
} else if (extendedCtrlInt &&
(!strcmp("assignment", name) ||
!strcmp("fbio", name) ||
!strcmp("alag", name) ||
!strcmp("rate", name) ||
!strcmp("dur", name) ||
!strcmp("scale", name))) {
(!strcmp("assignment", name) ||
!strcmp("fbio", name) ||
!strcmp("alag", name) ||
!strcmp("rate", name) ||
!strcmp("dur", name) ||
!strcmp("scale", name))) {
D_ParseNode *xpn = d_get_child(pn, 0);
char *v = (char*)rc_dup_str(xpn->start_loc.s, xpn->end);
nonmem2rxAddLhsVar(v);
Expand Down

0 comments on commit 9f234ec

Please sign in to comment.