c++parsinglemon

How do I fix "error: call to implicitly-deleted default constructor of 'YYMINORTYPE'" in lemon?


When I compile my lemon grammar. I get the following error.

src/grammar.c:949:21: error: call to implicitly-deleted default constructor of
      'YYMINORTYPE'
        YYMINORTYPE yylhsminor;
                    ^
src/grammar.c:111:38: note: default constructor of '' is implicitly deleted because
      variant field 'yy13' has a non-trivial default constructor
  std::tuple<bool, IdentifierNode *> yy13;
                                     ^
src/grammar.c:1178:15: error: call to implicitly-deleted default constructor of
      'YYMINORTYPE'
  YYMINORTYPE yyminorunion;
              ^
src/grammar.c:111:38: note: default constructor of '' is implicitly deleted because
      variant field 'yy13' has a non-trivial default constructor
  std::tuple<bool, IdentifierNode *> yy13;
                                     ^
2 errors generated.

Can anyone help? Thanks in advance.


Solution

  • Lemon is primarily intended to generate C code, but (like flex and lex) the parser it generates can be compiled with C++ provided your semantic types are simple enough. In particular, the various semantic types are joined together into a union and instances of this union are default-constructed (when the parser stack is created). As a consequence, every individual semantic type must have a default constructor, and std::tuple does not define one. So you can't use a std::tuple as a semantic type.

    That's not the only restriction. Stack elements may be copied by realloc, so the types should be trivially copyable. In short, they should basically look like C types, which excludes most of the C++ standard library.

    In this particular case, you could use a struct with two members instead of a tuple.

    Note that the Lemon documentation says nothing about C++ compatibility, so it is certainly possible that future changes (to C++ or to the lemon parser) will not preserve this compatibility.