Execute semantic actions for optionals only if the optional exists

This commit is contained in:
Dane Johnson 2022-01-02 11:34:47 -06:00
parent c3b7cc58f0
commit bf55252b9a
2 changed files with 13 additions and 15 deletions

View File

@ -25,7 +25,7 @@ struct Choice {
char *id;
statchange_t *statchange;
Choice(char*, statcheck_t *statcheck, statchange_t *statchange);
Choice(int);
};
typedef std::map<int, Choice*> ChoiceList;

View File

@ -60,20 +60,18 @@ Ending = 'THE END' Newline
ChoiceList = c:Choice l:ChoiceList { $$ = l; (*$$.choices)[c.choice->option] = c.choice; }
| c:Choice { $$.choices = new ChoiceList(); (*$$.choices)[c.choice->option] = c.choice; }
Choice = b:Bullet f:Freetext r:Redirect
{
$$ = r;
$$.choice->option = b.num;
$$.choice->flavor = f.string;
}
Choice = b:Bullet
f:Freetext { b.choice->flavor = f.string; }
(ck:StatCheck { b.choice->statcheck = ck.statcheck; })?
'[' i:Identifier ']' { b.choice->id = i.string; } -
(cg:StatChange { b.choice->statchange = cg.statchange; })?
Newline { $$ = b; }
;
Bullet = < [0-9]+ > ')' - { $$.num = atoi(yytext); }
Bullet = < [0-9]+ > ')' - { $$.choice = new Choice(atoi(yytext)); }
Freetext = < ([^[<])+ > { $$.string = strndup(yytext, yyleng); }
Redirect = ck:StatCheck? '[' i:Identifier ']' - cg:StatChange? Newline
{ $$.choice = new Choice(i.string, ck.statcheck, cg.statchange); }
StatCheck = '<' n:StatName v:StatVal r:StatRel '>' -
{ $$.statcheck = new statcheck_t{n.string, v.num, r.num}; }
@ -96,10 +94,10 @@ Newline = '\r\n' | '\r' | '\n'
%%
Choice::Choice(char *id, statcheck_t *statcheck, statchange_t *statchange) {
this->id = id;
this->statcheck = statcheck;
this->statchange = statchange;
Choice::Choice(int option) {
this->option = option;
this->statcheck = NULL;
this->statchange = NULL;
}
Footer::Footer() {