Is there a way to have two "cases" with one method?

Maury Markowitz <[email protected]> Mon, 22 Aug 2022 12:12:33 -0400
Newsgroups gmane.comp.parsers.bison.general
Message-ID <[email protected]>
Sorry, I’m not sure what the proper lingo is, so the subject may not make sense.

In my BASIC interpreter’s bison code I have one of these:

  |
  CHANGE variable TO variable
  {
    statement_t *new = make_statement(CHANGE);
    new->parms.change.var1 = $2;
    new->parms.change.var2 = $4;
    $$ = new;
  }

CHANGE is from the original Dartmouth BASIC. It turns out that HP included an identical feature in their dialect, CONVERT. So I did:

  |
  CONVERT variable TO variable
  {
    statement_t *new = make_statement(CONVERT);
    new->parms.change.var1 = $2;
    new->parms.change.var2 = $4;
    $$ = new;
  }

Works great.

My question is whether there is a simple way to combine the two to eliminate the duplicated code? These sorts of synonyms are not uncommon across different dialects. I tried what seemed obvious:

  |
  CONVERT variable TO variable
  |
  CHANGE variable TO variable

… and simply using the CHANGE token, but this resulted in the convert statement being empty.

Is there an easy way to do this?
If so, can I “save” the correct token in the make_statement?