A-LPG / LPG2

The LALR parser generator (LPG) is a tool for developing scanners and parsers. Supports multi-language . Input is specified by BNF rules. LPG supports backtracking (to resolve ambiguity), automatic AST generation and grammar inheritance.
Eclipse Public License 2.0
5 stars 4 forks source link

Get invalid generated code by having two conflicting function definitions when option -> glr is true: #2

Closed kuafuwang closed 2 years ago

kuafuwang commented 2 years ago

It seems that you have missed the fixes for this https://github.com/A-LPG/LPG2/issues/1#issuecomment-979954557 see here https://github.com/A-LPG/LPG2/blob/3e03744190610785342d487943f289459f5ea848/lpg2/src/CppAction2.cpp#L1507 , without that fix (on several *Action.cpp it seems that we'll get invalid generated code by having two conflicting function definitions when option -> glr is true:

if (option -> glr)
    {
        b.Put(indentation); b.Put("    Ast* nextAst = nullptr;\n");
        b.Put(indentation); b.Put("    IAst* getNextAst() { return nextAst; }\n"); ///<<<< first definition
        b.Put(indentation); b.Put("    void setNextAst(IAst* n) { nextAst = n; }\n");
        b.Put(indentation); b.Put("    void resetNextAst() { nextAst = nullptr; }\n");
    }
    else b.Put(indentation); b.Put("    IAst* getNextAst() { return nullptr; }\n"); ///<<<< second conflicting definition

Originally posted by @mingodad in https://github.com/A-LPG/LPG2/issues/1#issuecomment-980527275

kuafuwang commented 2 years ago

It's done.